Skip to content

Commit cf2a02c

Browse files
committed
🚩(frontend) feature flag on blocking edition
If users were not connected to the collaboration server, they were not be able to edit documents. We decided to add a feature flag on this feature as it can be quite restrictive. We can now enable or disable this feature at runtime thanks to the env variable "COLLABORATION_WS_NOT_CONNECTED_READY_ONLY".
1 parent d87a2ed commit cf2a02c

File tree

10 files changed

+23
-1
lines changed

10 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to
2121
- ✨(frontend) create generic theme #792
2222
- 🛂(frontend) block edition to not connected users #945
2323
- 🚸 Let loader during upload analyze #984
24+
- 🚩(frontend) feature flag on blocking edition #997
2425

2526
### Changed
2627

docs/env.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ These are the environment variables you can set for the `impress-backend` contai
4747
| COLLABORATION_API_URL | collaboration api host | |
4848
| COLLABORATION_SERVER_SECRET | collaboration api secret | |
4949
| COLLABORATION_WS_URL | collaboration websocket url | |
50+
| COLLABORATION_WS_NOT_CONNECTED_READY_ONLY | Users not connected to the collaboration server cannot edit | false |
5051
| FRONTEND_CSS_URL | To add a external css file to the app | |
5152
| FRONTEND_HOMEPAGE_FEATURE_ENABLED | frontend feature flag to display the homepage | false |
5253
| FRONTEND_THEME | frontend theme to use | |

src/backend/core/api/viewsets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,7 @@ def get(self, request):
17851785
array_settings = [
17861786
"AI_FEATURE_ENABLED",
17871787
"COLLABORATION_WS_URL",
1788+
"COLLABORATION_WS_NOT_CONNECTED_READY_ONLY",
17881789
"CRISP_WEBSITE_ID",
17891790
"ENVIRONMENT",
17901791
"FRONTEND_CSS_URL",

src/backend/core/tests/test_api_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
@override_settings(
2121
AI_FEATURE_ENABLED=False,
2222
COLLABORATION_WS_URL="http://testcollab/",
23+
COLLABORATION_WS_NOT_CONNECTED_READY_ONLY=True,
2324
CRISP_WEBSITE_ID="123",
2425
FRONTEND_CSS_URL="http://testcss/",
2526
FRONTEND_THEME="test-theme",
@@ -41,6 +42,7 @@ def test_api_config(is_authenticated):
4142
assert response.status_code == HTTP_200_OK
4243
assert response.json() == {
4344
"COLLABORATION_WS_URL": "http://testcollab/",
45+
"COLLABORATION_WS_NOT_CONNECTED_READY_ONLY": True,
4446
"CRISP_WEBSITE_ID": "123",
4547
"ENVIRONMENT": "test",
4648
"FRONTEND_CSS_URL": "http://testcss/",

src/backend/impress/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,11 @@ class Base(Configuration):
413413
COLLABORATION_WS_URL = values.Value(
414414
None, environ_name="COLLABORATION_WS_URL", environ_prefix=None
415415
)
416+
COLLABORATION_WS_NOT_CONNECTED_READY_ONLY = values.BooleanValue(
417+
False,
418+
environ_name="COLLABORATION_WS_NOT_CONNECTED_READY_ONLY",
419+
environ_prefix=None,
420+
)
416421

417422
# Frontend
418423
FRONTEND_THEME = values.Value(

src/frontend/apps/e2e/__tests__/app-impress/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const CONFIG = {
44
AI_FEATURE_ENABLED: true,
55
CRISP_WEBSITE_ID: null,
66
COLLABORATION_WS_URL: 'ws://localhost:4444/collaboration/ws/',
7+
COLLABORATION_WS_NOT_CONNECTED_READY_ONLY: false,
78
ENVIRONMENT: 'development',
89
FRONTEND_CSS_URL: null,
910
FRONTEND_HOMEPAGE_FEATURE_ENABLED: true,

src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ test.describe('Doc Editor', () => {
516516
json: {
517517
...CONFIG,
518518
COLLABORATION_WS_URL: 'ws://localhost:5555/collaboration/ws/',
519+
COLLABORATION_WS_NOT_CONNECTED_READY_ONLY: true,
519520
},
520521
});
521522
} else {

src/frontend/apps/impress/src/core/config/api/useConfig.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface ThemeCustomization {
1212
interface ConfigResponse {
1313
AI_FEATURE_ENABLED?: boolean;
1414
COLLABORATION_WS_URL?: string;
15+
COLLABORATION_WS_NOT_CONNECTED_READY_ONLY?: boolean;
1516
CRISP_WEBSITE_ID?: string;
1617
ENVIRONMENT: string;
1718
FRONTEND_CSS_URL?: string;

src/frontend/apps/impress/src/features/docs/doc-header/components/AlertNetwork.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const AlertNetwork = () => {
2929
border: 1px solid var(--c--theme--colors--warning-300);
3030
`}
3131
>
32-
<Box $direction="row" $gap={spacingsTokens['2xs']}>
32+
<Box $direction="row" $gap={spacingsTokens['2xs']} $align="center">
3333
<Icon iconName="mobiledata_off" $theme="warning" $variation="600" />
3434
<Text $theme="warning" $variation="600" $weight={500}>
3535
{t('Your network do not allow you to edit')}

src/frontend/apps/impress/src/features/docs/doc-management/hooks/useIsCollaborativeEditable.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { useEffect, useState } from 'react';
22

3+
import { useConfig } from '@/core';
34
import { useIsOffline } from '@/features/service-worker';
45

56
import { useProviderStore } from '../stores';
67
import { Doc, LinkReach } from '../types';
78

89
export const useIsCollaborativeEditable = (doc: Doc) => {
910
const { isConnected } = useProviderStore();
11+
const { data: conf } = useConfig();
1012

1113
const docIsPublic = doc.link_reach === LinkReach.PUBLIC;
1214
const docIsAuth = doc.link_reach === LinkReach.AUTHENTICATED;
@@ -37,6 +39,13 @@ export const useIsCollaborativeEditable = (doc: Doc) => {
3739
return () => clearTimeout(timer);
3840
}, [isConnected, isOffline, isShared]);
3941

42+
if (!conf?.COLLABORATION_WS_NOT_CONNECTED_READY_ONLY) {
43+
return {
44+
isEditable: true,
45+
isLoading: false,
46+
};
47+
}
48+
4049
return {
4150
isEditable,
4251
isLoading,

0 commit comments

Comments
 (0)