✨(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:
committed by
Laurent Bossavit
parent
bbe8f32b96
commit
43c18cb4e6
@@ -504,7 +504,7 @@ class ConfigView(views.APIView):
|
|||||||
GET /api/v1.0/config/
|
GET /api/v1.0/config/
|
||||||
Return a dictionary of public settings.
|
Return a dictionary of public settings.
|
||||||
"""
|
"""
|
||||||
array_settings = ["LANGUAGES", "FEATURES", "RELEASE"]
|
array_settings = ["LANGUAGES", "FEATURES", "RELEASE", "COMMIT"]
|
||||||
dict_settings = {}
|
dict_settings = {}
|
||||||
for setting in array_settings:
|
for setting in array_settings:
|
||||||
dict_settings[setting] = getattr(settings, setting)
|
dict_settings[setting] = getattr(settings, setting)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ def test_api_config_anonymous():
|
|||||||
assert response.status_code == HTTP_200_OK
|
assert response.status_code == HTTP_200_OK
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"]],
|
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"]],
|
||||||
|
"COMMIT": "NA",
|
||||||
"FEATURES": {
|
"FEATURES": {
|
||||||
"CONTACTS_DISPLAY": True,
|
"CONTACTS_DISPLAY": True,
|
||||||
"CONTACTS_CREATE": True,
|
"CONTACTS_CREATE": True,
|
||||||
@@ -42,6 +43,7 @@ def test_api_config_authenticated():
|
|||||||
assert response.status_code == HTTP_200_OK
|
assert response.status_code == HTTP_200_OK
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"]],
|
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"]],
|
||||||
|
"COMMIT": "NA",
|
||||||
"FEATURES": {
|
"FEATURES": {
|
||||||
"CONTACTS_DISPLAY": True,
|
"CONTACTS_DISPLAY": True,
|
||||||
"CONTACTS_CREATE": True,
|
"CONTACTS_CREATE": True,
|
||||||
|
|||||||
@@ -44,6 +44,17 @@ def get_release():
|
|||||||
return "NA" # Default: not available
|
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):
|
class Base(Configuration):
|
||||||
"""
|
"""
|
||||||
This is the base configuration every configuration (aka environment) should inherit from. It
|
This is the base configuration every configuration (aka environment) should inherit from. It
|
||||||
@@ -488,6 +499,14 @@ class Base(Configuration):
|
|||||||
"""
|
"""
|
||||||
return get_release()
|
return get_release()
|
||||||
|
|
||||||
|
# pylint: disable=invalid-name
|
||||||
|
@property
|
||||||
|
def COMMIT(self):
|
||||||
|
"""
|
||||||
|
Return the commit information.
|
||||||
|
"""
|
||||||
|
return get_commit()
|
||||||
|
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
@property
|
@property
|
||||||
def PARLER_LANGUAGES(self):
|
def PARLER_LANGUAGES(self):
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ describe('Page', () => {
|
|||||||
useConfigStore.setState({
|
useConfigStore.setState({
|
||||||
config: {
|
config: {
|
||||||
RELEASE: '1.0.0',
|
RELEASE: '1.0.0',
|
||||||
|
COMMIT: 'NA',
|
||||||
FEATURES: { TEAMS_DISPLAY: true },
|
FEATURES: { TEAMS_DISPLAY: true },
|
||||||
LANGUAGES: [],
|
LANGUAGES: [],
|
||||||
},
|
},
|
||||||
@@ -37,6 +38,7 @@ describe('Page', () => {
|
|||||||
useConfigStore.setState({
|
useConfigStore.setState({
|
||||||
config: {
|
config: {
|
||||||
RELEASE: '1.0.0',
|
RELEASE: '1.0.0',
|
||||||
|
COMMIT: 'NA',
|
||||||
FEATURES: { TEAMS_DISPLAY: false },
|
FEATURES: { TEAMS_DISPLAY: false },
|
||||||
LANGUAGES: [],
|
LANGUAGES: [],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ describe('MainLayout', () => {
|
|||||||
useConfigStore.setState({
|
useConfigStore.setState({
|
||||||
config: {
|
config: {
|
||||||
RELEASE: '1.0.0',
|
RELEASE: '1.0.0',
|
||||||
|
COMMIT: 'NA',
|
||||||
FEATURES: { TEAMS_DISPLAY: true },
|
FEATURES: { TEAMS_DISPLAY: true },
|
||||||
LANGUAGES: [],
|
LANGUAGES: [],
|
||||||
},
|
},
|
||||||
@@ -57,6 +58,7 @@ describe('MainLayout', () => {
|
|||||||
useConfigStore.setState({
|
useConfigStore.setState({
|
||||||
config: {
|
config: {
|
||||||
RELEASE: '1.0.0',
|
RELEASE: '1.0.0',
|
||||||
|
COMMIT: 'NA',
|
||||||
FEATURES: { TEAMS_DISPLAY: true },
|
FEATURES: { TEAMS_DISPLAY: true },
|
||||||
LANGUAGES: [],
|
LANGUAGES: [],
|
||||||
},
|
},
|
||||||
@@ -95,6 +97,7 @@ describe('MainLayout', () => {
|
|||||||
useConfigStore.setState({
|
useConfigStore.setState({
|
||||||
config: {
|
config: {
|
||||||
RELEASE: '1.0.0',
|
RELEASE: '1.0.0',
|
||||||
|
COMMIT: 'NA',
|
||||||
FEATURES: { TEAMS_DISPLAY: false },
|
FEATURES: { TEAMS_DISPLAY: false },
|
||||||
LANGUAGES: [],
|
LANGUAGES: [],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export interface Config {
|
export interface Config {
|
||||||
LANGUAGES: [string, string][];
|
LANGUAGES: [string, string][];
|
||||||
RELEASE: string;
|
RELEASE: string;
|
||||||
|
COMMIT: string;
|
||||||
FEATURES: {
|
FEATURES: {
|
||||||
TEAMS_DISPLAY: boolean;
|
TEAMS_DISPLAY: boolean;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import styled from 'styled-components';
|
|||||||
import { Box, LogoGouv, StyledLink, Text } from '@/components';
|
import { Box, LogoGouv, StyledLink, Text } from '@/components';
|
||||||
import { useConfigStore } from '@/core';
|
import { useConfigStore } from '@/core';
|
||||||
|
|
||||||
|
import frontVersion from '../../../version.json';
|
||||||
|
|
||||||
import IconLink from './assets/external-link.svg';
|
import IconLink from './assets/external-link.svg';
|
||||||
|
|
||||||
const BlueStripe = styled.div`
|
const BlueStripe = styled.div`
|
||||||
@@ -141,6 +143,11 @@ export const Footer = () => {
|
|||||||
))}
|
))}
|
||||||
</Box>
|
</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
|
<Text
|
||||||
as="p"
|
as="p"
|
||||||
$size="m"
|
$size="m"
|
||||||
|
|||||||
6
src/frontend/apps/desk/version.json
Normal file
6
src/frontend/apps/desk/version.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"source":"people",
|
||||||
|
"version":"version",
|
||||||
|
"commit":"commit",
|
||||||
|
"build": "NA"
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ test.describe('Config', () => {
|
|||||||
['en-us', 'English'],
|
['en-us', 'English'],
|
||||||
['fr-fr', 'French'],
|
['fr-fr', 'French'],
|
||||||
],
|
],
|
||||||
|
COMMIT: 'NA',
|
||||||
FEATURES: {
|
FEATURES: {
|
||||||
CONTACTS_CREATE: true,
|
CONTACTS_CREATE: true,
|
||||||
CONTACTS_DISPLAY: true,
|
CONTACTS_DISPLAY: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user