Skip to content

Commit 8d7d49f

Browse files
✨ feat(demo): restrict some demo features
1 parent 87b4781 commit 8d7d49f

File tree

6 files changed

+117
-29
lines changed

6 files changed

+117
-29
lines changed

.env.test

-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@ AUTH_TOKEN_KEY=TEST123*!@#testtesttesttesttesttesttesttesttesttesttesttesttestte
1010
NEXT_PUBLIC_BASE_URL=http://api.test.com
1111

1212
DEBUG_PRINT_LIMIT=1000
13-
14-
NEXT_PUBLIC_SHOW_UNFINISHED_FEATURES=true

.github/labels.yml

+21
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,98 @@
22
- name: "breaking-change"
33
color: ee0701
44
description: "A change that changes the API or breaks backward compatibility for users."
5+
56
- name: "bugfix"
67
color: ee0701
78
description: "Inconsistencies or issues which will cause a problem for users or implementors."
9+
810
- name: "documentation"
911
color: 0052cc
1012
description: "Solely about the documentation of the project."
13+
1114
- name: "enhancement"
1215
color: 1d76db
1316
description: "Enhancement of the code, not introducing new features."
17+
1418
- name: "refactor"
1519
color: 1d76db
1620
description: "Updating the code with simpler, easier to understand or more efficient syntax or methods, but not introducing new features."
21+
1722
- name: "performance"
1823
color: 1d76db
1924
description: "Improving performance of the project, not introducing new features."
25+
2026
- name: "new-feature"
2127
color: 0e8a16
2228
description: "New features or options."
29+
2330
- name: "maintenance"
2431
color: 2af79e
2532
description: "Generic maintenance tasks."
33+
2634
- name: "ci"
2735
color: 1d76db
2836
description: "Work that improves the continuous integration."
37+
2938
- name: "dependencies"
3039
color: 1d76db
3140
description: "Change in project dependencies."
3241

3342
- name: "in-progress"
3443
color: fbca04
3544
description: "Issue is currently being worked on by a developer."
45+
3646
- name: "stale"
3747
color: fef2c0
3848
description: "No activity for quite some time."
49+
3950
- name: "no-stale"
4051
color: fef2c0
4152
description: "This is exempt from the stale bot."
4253

4354
- name: "security"
4455
color: ee0701
4556
description: "Addressing a vulnerability or security risk in this project."
57+
4658
- name: "incomplete"
4759
color: fef2c0
4860
description: "Missing information."
61+
4962
- name: "invalid"
5063
color: fef2c0
5164
description: "This is off-topic, spam, or otherwise doesn't apply to this project."
5265

5366
- name: "beginner-friendly"
5467
color: 0e8a16
5568
description: "Good first issue for people wanting to contribute to this project."
69+
5670
- name: "help-wanted"
5771
color: 0e8a16
5872
description: "We need some extra helping hands or expertise in order to resolve this!"
5973

6074
- name: "priority-critical"
6175
color: ee0701
6276
description: "Must be addressed as soon as possible."
77+
6378
- name: "priority-high"
6479
color: b60205
6580
description: "After critical issues are fixed, these should be dealt with before any further issues."
81+
6682
- name: "priority-medium"
6783
color: 0e8a16
6884
description: "This issue may be useful, and needs some attention."
85+
6986
- name: "priority-low"
7087
color: e4ea8a
7188
description: "Nice addition, maybe... someday..."
7289

7390
- name: "major"
7491
color: b60205
7592
description: "This PR causes a major bump in the version number."
93+
7694
- name: "minor"
7795
color: 0e8a16
7896
description: "This PR causes a minor bump in the version number."
97+
98+
99+
# green chore #0e8a16

src/__tests__/api/config/[key]/index.spec.ts

+74-24
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ describe("/api/config/[key]/index", () => {
119119
});
120120

121121
describe("App config key validation", () => {
122+
const OLD_ENV = process.env;
123+
124+
beforeEach(() => {
125+
jest.resetModules();
126+
process.env = { ...OLD_ENV };
127+
});
128+
129+
afterEach(() => {
130+
process.env = OLD_ENV;
131+
});
132+
122133
it("should return error for invalid config key", async () => {
123134
const { req, res } = createAuthenticatedMocks({
124135
method: "GET",
@@ -131,14 +142,14 @@ describe("/api/config/[key]/index", () => {
131142

132143
expect(res._getStatusCode()).toBe(400);
133144
expect(res._getJSONData()).toMatchInlineSnapshot(`
134-
{
135-
"message": "Configuration key 'some-invalid-key' doesn't exist",
136-
"method": "GET",
137-
"name": "BadRequestError",
138-
"path": "",
139-
"statusCode": 400,
140-
}
141-
`);
145+
{
146+
"message": "Configuration key 'some-invalid-key' doesn't exist",
147+
"method": "GET",
148+
"name": "BadRequestError",
149+
"path": "",
150+
"statusCode": 400,
151+
}
152+
`);
142153
});
143154

144155
it("should return error for no config key", async () => {
@@ -151,14 +162,14 @@ describe("/api/config/[key]/index", () => {
151162

152163
expect(res._getStatusCode()).toBe(400);
153164
expect(res._getJSONData()).toMatchInlineSnapshot(`
154-
{
155-
"message": "Configuration key 'undefined' doesn't exist",
156-
"method": "GET",
157-
"name": "BadRequestError",
158-
"path": "",
159-
"statusCode": 400,
160-
}
161-
`);
165+
{
166+
"message": "Configuration key 'undefined' doesn't exist",
167+
"method": "GET",
168+
"name": "BadRequestError",
169+
"path": "",
170+
"statusCode": 400,
171+
}
172+
`);
162173
});
163174

164175
it("should return error for entity config keys when the entity is not passed", async () => {
@@ -173,14 +184,53 @@ describe("/api/config/[key]/index", () => {
173184

174185
expect(res._getStatusCode()).toBe(400);
175186
expect(res._getJSONData()).toMatchInlineSnapshot(`
176-
{
177-
"message": "Configuration of key 'table_views' requires entity",
178-
"method": "GET",
179-
"name": "BadRequestError",
180-
"path": "",
181-
"statusCode": 400,
182-
}
183-
`);
187+
{
188+
"message": "Configuration of key 'table_views' requires entity",
189+
"method": "GET",
190+
"name": "BadRequestError",
191+
"path": "",
192+
"statusCode": 400,
193+
}
194+
`);
195+
});
196+
197+
it("should throw error when updating a restricted config on demo", async () => {
198+
process.env.NEXT_PUBLIC_IS_DEMO = "true";
199+
200+
const putReq = createAuthenticatedMocks({
201+
method: "PUT",
202+
query: {
203+
key: "disabled_entities",
204+
},
205+
body: {
206+
data: ["updated-1", "updated-3"],
207+
},
208+
});
209+
210+
await handler(putReq.req, putReq.res);
211+
212+
expect(putReq.res._getStatusCode()).toBe(400);
213+
expect(putReq.res._getJSONData()).toMatchInlineSnapshot(`
214+
{
215+
"message": "This action is not available on the demo site",
216+
"method": "PUT",
217+
"name": "BadRequestError",
218+
"path": "",
219+
"statusCode": 400,
220+
}
221+
`);
222+
223+
const getReq = createAuthenticatedMocks({
224+
method: "GET",
225+
query: {
226+
key: "disabled_entities",
227+
},
228+
});
229+
230+
await handler(getReq.req, getReq.res);
231+
232+
expect(getReq.res._getStatusCode()).toBe(200);
233+
expect(getReq.res._getJSONData()).toEqual(["updated-1", "updated-2"]);
184234
});
185235
});
186236
});

src/backend/configuration/configuration.service.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { progammingError } from "backend/lib/errors";
22
import { AppConfigurationValueType } from "shared/configurations/constants";
3+
import { notAllowedOnDemoValidation } from "backend/lib/request/validations/implementations/not-allowed-on-demo";
34
import {
45
createConfigDomainPersistenceService,
56
AbstractConfigDataPersistenceService,
@@ -42,6 +43,14 @@ export class ConfigurationApiService {
4243
): Promise<void> {
4344
this.checkConfigKeyEntityRequirement(key, entity);
4445

46+
const disabledConfigKeysOnDemo: AppConfigurationKeys[] = [
47+
"disabled_entities",
48+
];
49+
50+
if (disabledConfigKeysOnDemo.includes(key)) {
51+
notAllowedOnDemoValidation();
52+
}
53+
4554
return await this._appConfigPersistenceService.upsertItem(
4655
this._appConfigPersistenceService.mergeKeyWithSecondaryKey(key, entity),
4756
value
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { BadRequestError } from "backend/lib/errors";
22
import { ValidationImplType } from "./types";
33

4-
export const notAllowedOnDemoValidationImpl: ValidationImplType<
5-
void
6-
> = async () => {
4+
export const notAllowedOnDemoValidation = () => {
75
if (process.env.NEXT_PUBLIC_IS_DEMO) {
86
throw new BadRequestError("This action is not available on the demo site");
97
}
108
};
9+
10+
export const notAllowedOnDemoValidationImpl: ValidationImplType<
11+
void
12+
> = async () => {
13+
notAllowedOnDemoValidation();
14+
};

src/frontend/views/settings/System/index.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ export function SystemSettings() {
5858
{
5959
validationType: "required",
6060
},
61+
{
62+
validationType: "min",
63+
constraint: {
64+
value: 1,
65+
},
66+
},
6167
],
6268
},
6369
}}

0 commit comments

Comments
 (0)