(version) convey version information to the /config endpoint and footer

We add the machinery to get version information and display it discreetly.
This commit is contained in:
Laurent Bossavit
2024-11-15 15:54:30 +01:00
committed by Laurent Bossavit
parent bbe8f32b96
commit 43c18cb4e6
9 changed files with 42 additions and 1 deletions

View File

@@ -504,7 +504,7 @@ class ConfigView(views.APIView):
GET /api/v1.0/config/
Return a dictionary of public settings.
"""
array_settings = ["LANGUAGES", "FEATURES", "RELEASE"]
array_settings = ["LANGUAGES", "FEATURES", "RELEASE", "COMMIT"]
dict_settings = {}
for setting in array_settings:
dict_settings[setting] = getattr(settings, setting)

View File

@@ -20,6 +20,7 @@ def test_api_config_anonymous():
assert response.status_code == HTTP_200_OK
assert response.json() == {
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"]],
"COMMIT": "NA",
"FEATURES": {
"CONTACTS_DISPLAY": True,
"CONTACTS_CREATE": True,
@@ -42,6 +43,7 @@ def test_api_config_authenticated():
assert response.status_code == HTTP_200_OK
assert response.json() == {
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"]],
"COMMIT": "NA",
"FEATURES": {
"CONTACTS_DISPLAY": True,
"CONTACTS_CREATE": True,

View File

@@ -44,6 +44,17 @@ def get_release():
return "NA" # Default: not available
def get_commit():
"""
Get the current commit of the application
"""
try:
with open(os.path.join(BASE_DIR, "version.json"), encoding="utf8") as version:
return json.load(version)["commit"]
except FileNotFoundError:
return "NA" # Default: not available
class Base(Configuration):
"""
This is the base configuration every configuration (aka environment) should inherit from. It
@@ -488,6 +499,14 @@ class Base(Configuration):
"""
return get_release()
# pylint: disable=invalid-name
@property
def COMMIT(self):
"""
Return the commit information.
"""
return get_commit()
# pylint: disable=invalid-name
@property
def PARLER_LANGUAGES(self):

View File

@@ -23,6 +23,7 @@ describe('Page', () => {
useConfigStore.setState({
config: {
RELEASE: '1.0.0',
COMMIT: 'NA',
FEATURES: { TEAMS_DISPLAY: true },
LANGUAGES: [],
},
@@ -37,6 +38,7 @@ describe('Page', () => {
useConfigStore.setState({
config: {
RELEASE: '1.0.0',
COMMIT: 'NA',
FEATURES: { TEAMS_DISPLAY: false },
LANGUAGES: [],
},

View File

@@ -20,6 +20,7 @@ describe('MainLayout', () => {
useConfigStore.setState({
config: {
RELEASE: '1.0.0',
COMMIT: 'NA',
FEATURES: { TEAMS_DISPLAY: true },
LANGUAGES: [],
},
@@ -57,6 +58,7 @@ describe('MainLayout', () => {
useConfigStore.setState({
config: {
RELEASE: '1.0.0',
COMMIT: 'NA',
FEATURES: { TEAMS_DISPLAY: true },
LANGUAGES: [],
},
@@ -95,6 +97,7 @@ describe('MainLayout', () => {
useConfigStore.setState({
config: {
RELEASE: '1.0.0',
COMMIT: 'NA',
FEATURES: { TEAMS_DISPLAY: false },
LANGUAGES: [],
},

View File

@@ -1,6 +1,7 @@
export interface Config {
LANGUAGES: [string, string][];
RELEASE: string;
COMMIT: string;
FEATURES: {
TEAMS_DISPLAY: boolean;
};

View File

@@ -5,6 +5,8 @@ import styled from 'styled-components';
import { Box, LogoGouv, StyledLink, Text } from '@/components';
import { useConfigStore } from '@/core';
import frontVersion from '../../../version.json';
import IconLink from './assets/external-link.svg';
const BlueStripe = styled.div`
@@ -141,6 +143,11 @@ export const Footer = () => {
))}
</Box>
<Text as="p" aria-hidden="true" $css="display: none">
You have found the hidden app version information ! Well done ! back
commit is: {config?.COMMIT}; front commit is: {frontVersion?.commit}
</Text>
<Text
as="p"
$size="m"

View File

@@ -0,0 +1,6 @@
{
"source":"people",
"version":"version",
"commit":"commit",
"build": "NA"
}

View File

@@ -20,6 +20,7 @@ test.describe('Config', () => {
['en-us', 'English'],
['fr-fr', 'French'],
],
COMMIT: 'NA',
FEATURES: {
CONTACTS_CREATE: true,
CONTACTS_DISPLAY: true,