strapi-plugin-comments 2.0.0 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.husky/pre-commit +4 -0
  2. package/README.md +33 -5
  3. package/__mocks__/initSetup.js +31 -2
  4. package/admin/src/hooks/useConfig.js +49 -0
  5. package/admin/src/index.js +31 -2
  6. package/admin/src/pages/Details/components/DetailsEntity/index.js +3 -1
  7. package/admin/src/pages/Details/index.js +7 -7
  8. package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +2 -2
  9. package/admin/src/pages/Settings/components/RestartAlert/styles.js +8 -0
  10. package/admin/src/pages/Settings/index.js +376 -0
  11. package/admin/src/pages/Settings/utils/api.js +60 -0
  12. package/admin/src/permissions.js +3 -0
  13. package/admin/src/translations/en.json +44 -1
  14. package/admin/src/utils/handleAPIError.js +3 -2
  15. package/admin/src/utils/index.js +2 -1
  16. package/admin/src/utils/parseRegExp.js +10 -0
  17. package/package.json +8 -5
  18. package/server/bootstrap.js +24 -0
  19. package/server/config/index.js +1 -0
  20. package/server/controllers/admin.js +42 -8
  21. package/server/controllers/client.js +4 -4
  22. package/server/controllers/utils/parsers.js +3 -1
  23. package/server/graphql/index.js +7 -8
  24. package/server/graphql/queries/findAllFlat.js +4 -2
  25. package/server/graphql/queries/findAllInHierarchy.js +3 -3
  26. package/server/graphql/resolvers-config.js +2 -4
  27. package/server/graphql/types/report-reason.js +10 -10
  28. package/server/register.js +1 -3
  29. package/server/routes/admin.js +32 -0
  30. package/server/services/__tests__/common.test.js +95 -14
  31. package/server/services/admin.js +57 -6
  32. package/server/services/client.js +14 -8
  33. package/server/services/common.js +69 -11
  34. package/server/services/utils/__tests__/functions.test.js +12 -1
  35. package/server/services/utils/functions.js +9 -1
  36. package/server/utils/constants.js +10 -0
  37. package/strapi-server.js +12 -5
  38. package/.circleci/config.yml +0 -48
  39. package/.eslintrc +0 -35
  40. package/.github/pull_request_template.md +0 -13
  41. package/.nvmrc +0 -1
  42. package/codecov.yml +0 -4
  43. package/public/assets/logo.png +0 -0
  44. package/public/assets/preview.png +0 -0
@@ -0,0 +1,376 @@
1
+ import React, { useRef, useMemo, useState } from 'react';
2
+ import { useQuery } from 'react-query';
3
+ import { Formik } from 'formik';
4
+ import { capitalize, first, orderBy, isEmpty, isEqual } from 'lodash';
5
+ import {
6
+ CheckPermissions,
7
+ LoadingIndicatorPage,
8
+ Form,
9
+ useTracking,
10
+ useNotification,
11
+ useRBAC,
12
+ useFocusWhenNavigate,
13
+ useOverlayBlocker,
14
+ } from '@strapi/helper-plugin';
15
+ import { Main } from '@strapi/design-system/Main';
16
+ import { ContentLayout, HeaderLayout } from '@strapi/design-system/Layout';
17
+ import { Button } from '@strapi/design-system/Button';
18
+ import { Box } from '@strapi/design-system/Box';
19
+ import { Stack } from '@strapi/design-system/Stack';
20
+ import { Typography } from '@strapi/design-system/Typography';
21
+ import { Grid, GridItem } from '@strapi/design-system/Grid';
22
+ import { ToggleInput } from '@strapi/design-system/ToggleInput';
23
+ import { Select, Option } from '@strapi/design-system/Select';
24
+ import { useNotifyAT } from '@strapi/design-system/LiveRegions';
25
+ import {
26
+ Card,
27
+ CardBody,
28
+ CardContent,
29
+ } from '@strapi/design-system/Card';
30
+ import { Check, Refresh, Play } from '@strapi/icons';
31
+
32
+ import pluginPermissions from '../../permissions';
33
+ import useConfig from '../../hooks/useConfig';
34
+ import { fetchAllContentTypes, fetchRoles } from './utils/api';
35
+ import { getMessage, parseRegExp } from '../../utils';
36
+ import ConfirmationDialog from '../../components/ConfirmationDialog';
37
+ import { RestartAlert } from './components/RestartAlert/styles';
38
+
39
+
40
+ const Settings = () => {
41
+ useFocusWhenNavigate();
42
+
43
+ const { notifyStatus } = useNotifyAT();
44
+ const { trackUsage } = useTracking();
45
+ const trackUsageRef = useRef(trackUsage);
46
+ const toggleNotification = useNotification();
47
+ const { lockApp, unlockApp } = useOverlayBlocker();
48
+
49
+ const viewPermissions = useMemo(() => ({
50
+ access: pluginPermissions.settings.read,
51
+ change: pluginPermissions.settings.change,
52
+ }), []);
53
+
54
+ const {
55
+ isLoading: isLoadingForPermissions,
56
+ allowedActions: { canAccess, canChange },
57
+ } = useRBAC(viewPermissions);
58
+
59
+ const [restoreConfigmationVisible, setRestoreConfigmationVisible] = useState(false);
60
+ const [restartRequired, setRestartRequired] = useState(false);
61
+
62
+ const { fetch, restartMutation, submitMutation, restoreMutation } = useConfig(toggleNotification);
63
+ const { data: configData, isLoading: isConfigLoading, err: configErr } = fetch;
64
+
65
+ const { data: allCollectionsData, isLoading: areCollectionsLoading, err: collectionsErr } = useQuery(
66
+ ['get-all-content-types', canAccess],
67
+ () => fetchAllContentTypes(toggleNotification)
68
+ );
69
+
70
+ const { data: allRolesData, isLoading: areRolesLoading, err: rolesErr } = useQuery(
71
+ ['get-all-roles', canAccess],
72
+ () => fetchRoles(toggleNotification)
73
+ );
74
+
75
+ const isLoading = isLoadingForPermissions || isConfigLoading || areCollectionsLoading || areRolesLoading;
76
+ const isError = configErr || collectionsErr || rolesErr;
77
+
78
+ const preparePayload = ({ enabledCollections, gqlAuthEnabled, approvalFlow, entryLabel, ...rest }) => ({
79
+ ...rest,
80
+ enabledCollections,
81
+ approvalFlow: approvalFlow.filter(_ => enabledCollections.includes(_)),
82
+ entryLabel: {
83
+ ...Object.keys(entryLabel).reduce((prev, curr) => ({
84
+ ...prev,
85
+ [curr]: enabledCollections.includes(curr) ? entryLabel[curr] : undefined,
86
+ }), {}),
87
+ '*': entryLabel['*'],
88
+ },
89
+ reportReasons: configData?.reportReasons,
90
+ gql: gqlAuthEnabled ? { auth: true } : undefined,
91
+ });
92
+
93
+ if (isLoading || isError) {
94
+ return (<LoadingIndicatorPage>
95
+ { getMessage('page.settings.loading')}
96
+ </LoadingIndicatorPage>);
97
+ }
98
+
99
+ const regexUID = !isLoading ? new RegExp(
100
+ parseRegExp(fetch.data.regex?.uid).value,
101
+ parseRegExp(fetch.data.regex?.uid).flags
102
+ ) : null;
103
+
104
+ const allRoles = allRolesData?.data || [];
105
+ const allCollections = !isLoading && allCollectionsData
106
+ .filter(({ uid }) => first(uid.split(regexUID).filter(s => s && s.length > 0)) === 'api');
107
+ const enabledCollections = configData?.enabledCollections
108
+ ?.map(uid => allCollections.find(_ => _.uid === uid) ? uid : undefined)
109
+ .filter(_ => _) || [];
110
+ const entryLabel = configData?.entryLabel || {};
111
+ const approvalFlow = configData?.approvalFlow || [];
112
+ const badWords = configData?.badWords || undefined;
113
+ const isGQLPluginEnabled = configData?.isGQLPluginEnabled;
114
+ const gqlAuthEnabled = configData?.gql?.auth || undefined;
115
+ const moderatorRoles = configData?.moderatorRoles
116
+ ?.filter(code => allRoles.find(_ => _.code === code)) || [];
117
+
118
+ const changeApprovalFlowFor = (uid, current, value) => {
119
+ const currentSet = new Set(current);
120
+ if (value) {
121
+ currentSet.add(uid);
122
+ } else {
123
+ currentSet.delete(uid);
124
+ }
125
+ return Array.from(currentSet);
126
+ };
127
+
128
+ const changeEntryLabelFor = (uid, current, value) => ({
129
+ ...current,
130
+ [uid]: value && !isEmpty(value) ? [...value] : undefined,
131
+ });
132
+
133
+ const handleUpdateConfiguration = async (form) => {
134
+ if (canChange) {
135
+ lockApp();
136
+ const payload = preparePayload(form);
137
+ await submitMutation.mutateAsync(payload);
138
+ const enabledCollectionsChanged = !isEqual(payload.enabledCollections, configData?.enabledCollections);
139
+ const gqlAuthChanged = !isEqual(payload.gql?.auth, configData?.gql?.auth);
140
+ if (enabledCollectionsChanged || gqlAuthChanged) {
141
+ setRestartRequired(true);
142
+ }
143
+ unlockApp();
144
+ }
145
+ };
146
+
147
+ const handleRestoreConfirmation = () => setRestoreConfigmationVisible(true);
148
+ const handleRestoreConfiguration = async () => {
149
+ if (canChange) {
150
+ lockApp();
151
+ await restoreMutation.mutateAsync();
152
+ unlockApp();
153
+ setRestartRequired(true);
154
+ setRestoreConfigmationVisible(false);
155
+ }
156
+ };
157
+ const handleRestoreCancel = () => setRestoreConfigmationVisible(false);
158
+
159
+ const handleRestart = async () => {
160
+ if (canChange) {
161
+ lockApp();
162
+ await restartMutation.mutateAsync();
163
+ setRestartRequired(false);
164
+ unlockApp();
165
+ }
166
+ };
167
+ const handleRestartDiscard = () => setRestartRequired(false);
168
+
169
+ const boxDefaultProps = {
170
+ background: "neutral0",
171
+ hasRadius: true,
172
+ shadow: "filterShadow",
173
+ padding: 6,
174
+ };
175
+
176
+ return (
177
+ <Main>
178
+ <Formik
179
+ initialValues={{
180
+ enabledCollections,
181
+ moderatorRoles,
182
+ badWords,
183
+ approvalFlow,
184
+ entryLabel,
185
+ gqlAuthEnabled,
186
+ }}
187
+ enableReinitialize={true}
188
+ onSubmit={handleUpdateConfiguration}
189
+ >
190
+ {({ handleSubmit, setFieldValue, values }) => (
191
+ <Form noValidate onSubmit={handleSubmit}>
192
+ <HeaderLayout
193
+ title={getMessage('page.settings.header.title')}
194
+ subtitle={getMessage('page.settings.header.description')}
195
+ primaryAction={
196
+ <CheckPermissions permissions={pluginPermissions.settingsChange}>
197
+ <Button type="submit" startIcon={<Check />} disabled={restartRequired} >
198
+ {getMessage('page.settings.actions.submit')}
199
+ </Button>
200
+ </CheckPermissions>
201
+ }
202
+ />
203
+ <ContentLayout>
204
+ <Stack size={6}>
205
+ { restartRequired && (
206
+ <RestartAlert
207
+ closeLabel={getMessage('page.settings.actions.restart.alert.cancel')}
208
+ title={getMessage('page.settings.actions.restart.alert.title')}
209
+ action={<Box><Button onClick={handleRestart} startIcon={<Play />}>{getMessage('page.settings.actions.restart')}</Button></Box>}
210
+ onClose={handleRestartDiscard}>
211
+ { getMessage('page.settings.actions.restart.alert.description')}
212
+ </RestartAlert>)}
213
+
214
+ <Box {...boxDefaultProps}>
215
+ <Stack size={4}>
216
+ <Typography variant="delta" as="h2">
217
+ {getMessage('page.settings.section.general')}
218
+ </Typography>
219
+ <Grid gap={4}>
220
+ <GridItem col={12}>
221
+ <Select
222
+ name="enabledCollections"
223
+ label={getMessage('page.settings.form.enabledCollections.label')}
224
+ placeholder={getMessage('page.settings.form.enabledCollections.placeholder')}
225
+ hint={getMessage('page.settings.form.enabledCollections.hint')}
226
+ onClear={() => setFieldValue('enabledCollections', [], false)}
227
+ value={values.enabledCollections}
228
+ onChange={(value) => setFieldValue('enabledCollections', value, false)}
229
+ disabled={restartRequired}
230
+ multi
231
+ withTags
232
+ >
233
+ { allCollections.map(({ uid, schema: { displayName } }) =>
234
+ (<Option key={uid} value={uid}>{displayName}</Option>))}
235
+ </Select>
236
+ </GridItem>
237
+ <GridItem col={6} xs={12}>
238
+ <Select
239
+ name="moderatorRoles"
240
+ label={getMessage('page.settings.form.moderatorRoles.label')}
241
+ placeholder={getMessage('page.settings.form.moderatorRoles.placeholder')}
242
+ hint={getMessage('page.settings.form.moderatorRoles.hint')}
243
+ onClear={() => setFieldValue('moderatorRoles', [], false)}
244
+ value={values.moderatorRoles}
245
+ onChange={(value) => setFieldValue('moderatorRoles', value, false)}
246
+ disabled={restartRequired}
247
+ multi
248
+ withTags
249
+ >
250
+ { allRoles.map(({ code, name }) =>
251
+ (<Option key={code} value={code}>{name}</Option>))}
252
+ </Select>
253
+ </GridItem>
254
+ <GridItem col={6} xs={12}>
255
+ <ToggleInput
256
+ name="badWords"
257
+ label={getMessage('page.settings.form.badWords.label')}
258
+ hint={getMessage('page.settings.form.badWords.hint')}
259
+ checked={values.badWords}
260
+ onChange={({ target: { checked } }) => setFieldValue('badWords', checked, false)}
261
+ onLabel={getMessage('compontents.toogle.enabled')}
262
+ offLabel={getMessage('compontents.toogle.disabled')}
263
+ disabled={restartRequired}
264
+ />
265
+ </GridItem>
266
+ { isGQLPluginEnabled && (<GridItem col={6} xs={12}>
267
+ <ToggleInput
268
+ name="badWords"
269
+ label={getMessage('page.settings.form.gqlAuth.label')}
270
+ hint={getMessage('page.settings.form.gqlAuth.hint')}
271
+ checked={values.gqlAuthEnabled}
272
+ onChange={({ target: { checked } }) => setFieldValue('gqlAuthEnabled', checked, false)}
273
+ onLabel={getMessage('compontents.toogle.enabled')}
274
+ offLabel={getMessage('compontents.toogle.disabled')}
275
+ disabled={restartRequired}
276
+ />
277
+ </GridItem>) }
278
+ </Grid>
279
+ </Stack>
280
+ </Box>
281
+ { !isEmpty(values.enabledCollections) && (<Box {...boxDefaultProps}>
282
+ <Stack size={4}>
283
+ <Typography variant="delta" as="h2">
284
+ {getMessage('page.settings.section.collections')}
285
+ </Typography>
286
+ <Grid gap={4}>
287
+ { orderBy(values.enabledCollections).map(uid => {
288
+ const { schema: { displayName, attributes = {} } } = allCollections.find(_ => _.uid === uid);
289
+ const stringAttributes = Object.keys(attributes).filter(_ => attributes[_].type === 'string');
290
+ return (<GridItem key={`collectionSettings-${uid}`} col={6} s={12} xs={12}>
291
+ <Card background="primary100" borderColor="primary200">
292
+ <CardBody>
293
+ <CardContent style={{ width: '100%' }}>
294
+ <Stack size={4}>
295
+ <Typography variant="epsilon" fontWeight="semibold" as="h3">{ displayName }</Typography>
296
+ <ToggleInput
297
+ name={`collectionSettings-${uid}-approvalFlow`}
298
+ label={getMessage('page.settings.form.approvalFlow.label')}
299
+ hind={getMessage({
300
+ id: 'page.settings.form.approvalFlow.hint',
301
+ params: { name: displayName },
302
+ })}
303
+ checked={values.approvalFlow.includes(uid)}
304
+ onChange={({ target: { checked } }) => setFieldValue('approvalFlow', changeApprovalFlowFor(uid, values.approvalFlow, checked), [])}
305
+ onLabel={getMessage('compontents.toogle.enabled')}
306
+ offLabel={getMessage('compontents.toogle.disabled')}
307
+ disabled={restartRequired}
308
+ />
309
+ { !isEmpty(stringAttributes) && (<Select
310
+ name={`collectionSettings-${uid}-entryLabel`}
311
+ label={getMessage('page.settings.form.entryLabel.label')}
312
+ placeholder={getMessage('page.settings.form.entryLabel.placeholder')}
313
+ hint={getMessage('page.settings.form.entryLabel.hint')}
314
+ onClear={() => setFieldValue('entryLabel', changeEntryLabelFor(uid, values.entryLabel))}
315
+ value={values.entryLabel[uid] || []}
316
+ onChange={(value) => setFieldValue('entryLabel', changeEntryLabelFor(uid, values.entryLabel, value))}
317
+ multi
318
+ withTags
319
+ disabled={restartRequired}
320
+ >
321
+ { stringAttributes.map(key =>
322
+ (<Option key={`collectionSettings-${uid}-entryLabel-${key}`} value={key}>{ capitalize(key.split('_').join(' ')) }</Option>))}
323
+ </Select>) }
324
+ </Stack>
325
+ </CardContent>
326
+ </CardBody>
327
+ </Card>
328
+ </GridItem>);
329
+ })}
330
+ </Grid>
331
+ </Stack>
332
+ </Box>)}
333
+
334
+ <CheckPermissions permissions={pluginPermissions.settingsChange}>
335
+ <Box {...boxDefaultProps}>
336
+ <Stack size={4}>
337
+ <Stack size={2}>
338
+ <Typography variant="delta" textColor="danger700" as="h2">
339
+ {getMessage('page.settings.section.restore')}
340
+ </Typography>
341
+ <Typography variant="pi"as="h4">
342
+ {getMessage('page.settings.section.restore.subtitle')}
343
+ </Typography>
344
+ </Stack>
345
+ <Grid gap={4}>
346
+ <GridItem col={6}>
347
+ <Button variant="danger-light" startIcon={<Refresh />} onClick={handleRestoreConfirmation}>
348
+ {getMessage('page.settings.actions.restore')}
349
+ </Button>
350
+
351
+ <ConfirmationDialog
352
+ isVisible={restoreConfigmationVisible}
353
+ isActionAsync={restoreMutation.isLoading}
354
+ header={getMessage('page.settings.actions.restore.confirmation.header')}
355
+ labelConfirm={getMessage('page.settings.actions.restore.confirmation.button.confirm')}
356
+ iconConfirm={<Refresh />}
357
+ onConfirm={handleRestoreConfiguration}
358
+ onCancel={handleRestoreCancel}>
359
+ { getMessage('page.settings.actions.restore.confirmation.description') }
360
+ </ConfirmationDialog>
361
+ </GridItem>
362
+ </Grid>
363
+ </Stack>
364
+ </Box>
365
+ </CheckPermissions>
366
+ </Stack>
367
+ </ContentLayout>
368
+ </Form>
369
+ )}
370
+ </Formik>
371
+ </Main>
372
+ );
373
+ }
374
+
375
+
376
+ export default Settings;
@@ -0,0 +1,60 @@
1
+ import { getApiURL, axiosInstance, handleAPIError } from '../../../utils';
2
+
3
+ // eslint-disable-next-line import/prefer-default-export
4
+ export const fetchConfig = async (toggleNotification) => {
5
+ try {
6
+ const { data } = await axiosInstance.get(getApiURL(`settings/config`));
7
+
8
+ return data;
9
+ } catch (err) {
10
+ handleAPIError(err, toggleNotification, 'page.settings.notification.fetch.error');
11
+ }
12
+ };
13
+
14
+ export const updateConfig = async (body, toggleNotification) => {
15
+ try {
16
+ const { data } = await axiosInstance.put(getApiURL(`settings/config`), body);
17
+
18
+ return data;
19
+ } catch (err) {
20
+ handleAPIError(err, toggleNotification);
21
+ }
22
+ };
23
+
24
+ export const restoreConfig = async (toggleNotification) => {
25
+ try {
26
+ const { data } = await axiosInstance.delete(getApiURL(`settings/config`));
27
+
28
+ return data;
29
+ } catch (err) {
30
+ handleAPIError(err, toggleNotification);
31
+ }
32
+ };
33
+
34
+ export const fetchAllContentTypes = async (toggleNotification) => {
35
+ try {
36
+ const { data } = await axiosInstance.get(`/content-type-builder/content-types`);
37
+ return data?.data;
38
+ } catch (err) {
39
+ handleAPIError(err, toggleNotification);
40
+ }
41
+ };
42
+
43
+ export const fetchRoles = async (toggleNotification) => {
44
+ try {
45
+ const { data } = await axiosInstance.get(`/admin/roles`);
46
+ return data;
47
+ } catch (err) {
48
+ handleAPIError(err, toggleNotification);
49
+ }
50
+ };
51
+
52
+ export const restartStrapi = async (toggleNotification) => {
53
+ try {
54
+ const { data } = await axiosInstance.get(getApiURL(`settings/restart`));
55
+
56
+ return data;
57
+ } catch (err) {
58
+ handleAPIError(err, toggleNotification);
59
+ }
60
+ };
@@ -6,11 +6,14 @@ const pluginPermissions = {
6
6
  { action: permissions.render(permissions.reports.read), subject: null },
7
7
  // { action: 'plugin::comments.discover.read', subject: null },
8
8
  { action: permissions.render(permissions.settings.read), subject: null },
9
+ { action: permissions.render(permissions.settings.read), subject: null },
9
10
  ],
10
11
  // discover: [{ action: 'plugin::comments.discover.read', subject: null }],
11
12
  moderate: [{ action: permissions.render(permissions.comments.moderate), subject: null }],
12
13
  reports: [{ action: permissions.render(permissions.reports.read), subject: null }],
13
14
  reportsReview: [{ action: permissions.render(permissions.reports.action), subject: null }],
15
+ settings: [{ action: permissions.render(permissions.settings.read), subject: null }],
16
+ settingsChange: [{ action: permissions.render(permissions.settings.change), subject: null }],
14
17
  };
15
18
 
16
19
  export default pluginPermissions;
@@ -1,5 +1,7 @@
1
1
  {
2
2
  "plugin.name": "Comments",
3
+ "plugin.section": "Comments plugin",
4
+ "plugin.section.item": "Configuration",
3
5
  "common.button.back": "Go back",
4
6
  "nav.header.moderation": "Moderation",
5
7
  "nav.header.settings": "Settings",
@@ -79,8 +81,49 @@
79
81
  "page.details.filters.label": "View",
80
82
  "page.details.filters.removed.visibility": "Show removed comments",
81
83
  "page.coming.soon": "Wait for what is coming soon...",
84
+ "page.settings": "Settings",
85
+ "page.settings.header.title": "Comments",
86
+ "page.settings.header.description": "Configure your comments moderation capabilities",
87
+ "page.settings.actions.submit": "Save",
88
+ "page.settings.actions.restore": "Restore",
89
+ "page.settings.actions.restart": "Restart Strapi",
90
+ "page.settings.section.general": "General configuration",
91
+ "page.settings.section.collections": "Collection(s) configuration",
92
+ "page.settings.section.restore": "Restore default configuration",
93
+ "page.settings.section.restore.subtitle": "Discarding all of applied settings and getting back to plugin default ones. Use reasonable.",
94
+ "page.settings.form.enabledCollections.label": "Enable Comments for Collection(s)",
95
+ "page.settings.form.enabledCollections.placeholder": "Select one or more collection",
96
+ "page.settings.form.enabledCollections.hint": "If none of collection is selected, feature are enabled for any of exsiting",
97
+ "page.settings.form.moderatorRoles.label": "Send significant notifications to",
98
+ "page.settings.form.moderatorRoles.placeholder": "Select one or more roles",
99
+ "page.settings.form.moderatorRoles.hint": "Roles which are going to be notified by the plugin about significant actions to perform",
100
+ "page.settings.form.badWords.label": "Bad words filtering",
101
+ "page.settings.form.badWords.hint": "If enabled, every post / update of comment is going to be checked against bad wording",
102
+ "page.settings.form.gqlAuth.label": "GraphQL queries authorization",
103
+ "page.settings.form.gqlAuth.hint": "If enabled, GraphQL API queries & mutations can be triggered only by Authenticated Strapi users. Otherwise API remains open.",
104
+ "page.settings.form.approvalFlow.label": "Enable approval flow",
105
+ "page.settings.form.approvalFlow.hint": "Comments for \"{name}\" are going to be taken through manual approval flow",
106
+ "page.settings.form.entryLabel.label": "Title fields",
107
+ "page.settings.form.entryLabel.placeholder": "Select at least one or leave empty to apply defaults",
108
+ "page.settings.form.entryLabel.hint": "If left empty title rendering is going to take following ordered fields: \"Title\", \"Subject\" & \"Name\"",
109
+ "page.settings.actions.restore.confirmation.header": "Restore default configuration",
110
+ "page.settings.actions.restore.confirmation.description": "You're about to restore plugin configuration to it default values. It might have destructive impact on already collected content. Do you really want to proceed?",
111
+ "page.settings.actions.restore.confirmation.button.confirm": "Yes, I want to restore",
112
+ "page.settings.actions.restart.alert.title": "Strapi requires restart",
113
+ "page.settings.actions.restart.alert.description": "You've made a configuration changes which requires your Strapi application to be restarted to take an effect in GraphQL schema. Do it manually or by using below trigger.",
114
+ "page.settings.actions.restart.alert.close": "Discard",
115
+ "page.settings.notification.fetch.error": "Failed to fetch configuration. Retrying...",
116
+ "page.settings.notification.submit.success": "Configuration has been saved successfully",
117
+ "page.settings.notification.submit.error": "Failed to save configuration. Try again.",
118
+ "page.settings.notification.restore.success": "Configuration has been restored successfully",
119
+ "page.settings.notification.restore.error": "Failed to restore configuration. Try again.",
120
+ "page.settings.notification.restart.success": "Application has been restarted successfully",
121
+ "page.settings.notification.restart.error": "Failed to restart your application. Try to do it manually.",
122
+ "page.settings.loading": "Fetching configuration...",
82
123
  "compontents.confirmation.dialog.header": "Confirmation",
83
124
  "compontents.confirmation.dialog.description": "Do you really want to perform this action?",
84
125
  "compontents.confirmation.dialog.button.confirm": "Yes, I do",
85
- "compontents.confirmation.dialog.button.cancel": "Cancel"
126
+ "compontents.confirmation.dialog.button.cancel": "Cancel",
127
+ "compontents.toogle.enabled": "Enabled",
128
+ "compontents.toogle.disabled": "Disabled"
86
129
  }
@@ -1,8 +1,9 @@
1
+ import pluginId from "../pluginId";
1
2
 
2
- const handleAPIError = (err = null, toggleNotification = null) => {
3
+ const handleAPIError = (err = null, toggleNotification = null, message = 'app.components.notification.error') => {
3
4
  toggleNotification({
4
5
  type: 'warning',
5
- message: 'app.components.notification.error',
6
+ message: `${pluginId}.${message}`,
6
7
  });
7
8
 
8
9
  if (err) {
@@ -7,4 +7,5 @@ export { default as getRelatedGroups } from './getRelatedGroups';
7
7
  export { default as renderEntryTitle } from './renderEntryTitle';
8
8
  export { default as renderInitials } from './renderInitials';
9
9
  export { default as resolveCommentStatus } from './resolveCommentStatus';
10
- export { default as resolveCommentStatusColor } from './resolveCommentStatusColor';
10
+ export { default as resolveCommentStatusColor } from './resolveCommentStatusColor';
11
+ export { default as parseRegExp } from './parseRegExp';
@@ -0,0 +1,10 @@
1
+
2
+ const parseRegExp = (regexpString) => {
3
+ const [value, flags] = regexpString.split('/').filter(_ => _.length > 0);
4
+ return {
5
+ value,
6
+ flags,
7
+ };
8
+ }
9
+
10
+ export default parseRegExp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-comments",
3
- "version": "2.0.0",
3
+ "version": "2.0.4",
4
4
  "description": "Strapi - Comments plugin",
5
5
  "strapi": {
6
6
  "name": "comments",
@@ -9,7 +9,8 @@
9
9
  "kind": "plugin"
10
10
  },
11
11
  "scripts": {
12
- "publish": "npm publish --tag latest",
12
+ "prepare": "husky install",
13
+ "publish:latest": "npm publish --tag latest",
13
14
  "test:unit": "jest --verbose --coverage"
14
15
  },
15
16
  "repository": {
@@ -26,14 +27,16 @@
26
27
  "jest": "^26.0.1",
27
28
  "jest-cli": "^26.0.1",
28
29
  "jest-styled-components": "^7.0.2",
29
- "koa": "2.13.3"
30
+ "koa": "2.13.3",
31
+ "husky": "7.0.4",
32
+ "prettier": "2.5.1"
30
33
  },
31
34
  "peerDependencies": {
32
35
  "@strapi/strapi": "4.x"
33
36
  },
34
37
  "author": {
35
- "name": "VirtusLab // Mateusz Ziarko",
36
- "email": "mziarko@virtuslab.com",
38
+ "name": "VirtusLab",
39
+ "email": "strapi@virtuslab.com",
37
40
  "url": "https://virtuslab.com"
38
41
  },
39
42
  "maintainers": [
@@ -1,8 +1,20 @@
1
1
  'use strict';
2
2
 
3
+ const { isEmpty } = require('lodash');
3
4
  const permissions = require('./../permissions');
5
+ const { getPluginService } = require('./utils/functions');
4
6
 
5
7
  module.exports = async ({ strapi }) => {
8
+
9
+ // Provide GQL support
10
+ if (strapi.plugin('graphql')) {
11
+ const config = await getPluginService('common').getConfig();
12
+ const { enabledCollections } = config;
13
+ if (!isEmpty(enabledCollections)) {
14
+ await require('./graphql')({ strapi, config });
15
+ }
16
+ }
17
+
6
18
  // Check if the plugin users-permissions is installed because the navigation needs it
7
19
  if (Object.keys(strapi.plugins).indexOf("users-permissions") === -1) {
8
20
  throw new Error(
@@ -35,6 +47,18 @@ module.exports = async ({ strapi }) => {
35
47
  uid: permissions.reports.action,
36
48
  pluginName: "comments",
37
49
  },
50
+ {
51
+ section: "plugins",
52
+ displayName: "Settings: Read",
53
+ uid: permissions.settings.read,
54
+ pluginName: "comments",
55
+ },
56
+ {
57
+ section: "plugins",
58
+ displayName: "Settings: Change",
59
+ uid: permissions.settings.change,
60
+ pluginName: "comments",
61
+ },
38
62
  ];
39
63
 
40
64
  await strapi.admin.services.permission.actionProvider.registerMany(actions);
@@ -2,6 +2,7 @@
2
2
 
3
3
  module.exports = {
4
4
  default: {
5
+ enabledCollections: [],
5
6
  moderatorRoles: [],
6
7
  approvalFlow: [],
7
8
  entryLabel: {