@akemona-org/strapi-plugin-users-permissions 3.7.0 → 3.7.1

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 (42) hide show
  1. package/admin/src/components/BoundRoute/index.js +1 -1
  2. package/admin/src/components/Permissions/PermissionRow/RowStyle.js +1 -1
  3. package/admin/src/components/Permissions/PermissionRow/SubCategory/index.js +6 -11
  4. package/admin/src/components/Permissions/PermissionRow/index.js +1 -1
  5. package/admin/src/components/Permissions/index.js +2 -2
  6. package/admin/src/components/Permissions/reducer.js +1 -1
  7. package/admin/src/components/Policies/index.js +1 -1
  8. package/admin/src/components/Roles/RoleRow/RoleDescription.js +1 -1
  9. package/admin/src/components/UsersPermissions/index.js +2 -2
  10. package/admin/src/components/UsersPermissions/reducer.js +1 -1
  11. package/admin/src/containers/AdvancedSettings/index.js +5 -7
  12. package/admin/src/containers/AdvancedSettings/reducer.js +5 -2
  13. package/admin/src/containers/EmailTemplates/CustomTextInput.js +1 -1
  14. package/admin/src/containers/EmailTemplates/index.js +6 -6
  15. package/admin/src/containers/EmailTemplates/reducer.js +1 -1
  16. package/admin/src/containers/EmailTemplates/utils/schema.js +1 -4
  17. package/admin/src/containers/Providers/index.js +8 -8
  18. package/admin/src/containers/Providers/reducer.js +1 -1
  19. package/admin/src/containers/Providers/utils/createProvidersArray.js +1 -1
  20. package/admin/src/containers/Roles/CreatePage/index.js +2 -2
  21. package/admin/src/containers/Roles/EditPage/index.js +2 -2
  22. package/admin/src/containers/Roles/ListPage/index.js +6 -6
  23. package/admin/src/hooks/useFetchRole/index.js +3 -3
  24. package/admin/src/hooks/useFetchRole/reducer.js +1 -1
  25. package/admin/src/hooks/useForm/index.js +1 -1
  26. package/admin/src/hooks/useForm/reducer.js +1 -1
  27. package/admin/src/hooks/usePlugins/index.js +2 -2
  28. package/admin/src/hooks/usePlugins/reducer.js +1 -1
  29. package/admin/src/hooks/useRolesList/reducer.js +1 -1
  30. package/admin/src/index.js +1 -1
  31. package/admin/src/pluginId.js +1 -1
  32. package/admin/src/utils/cleanPermissions.js +1 -1
  33. package/admin/src/utils/formatPolicies.js +1 -1
  34. package/admin/src/utils/getRequestURL.js +1 -1
  35. package/admin/src/utils/getTrad.js +1 -1
  36. package/config/functions/bootstrap.js +1 -1
  37. package/controllers/UsersPermissions.js +4 -5
  38. package/controllers/validation/email-template.js +1 -1
  39. package/middlewares/users-permissions/index.js +5 -5
  40. package/package.json +4 -4
  41. package/services/Jwt.js +2 -2
  42. package/services/UsersPermissions.js +24 -24
@@ -26,7 +26,7 @@ function BoundRoute({ route }) {
26
26
  <Wrapper>
27
27
  <Verb className={toLower(get(route, 'method'))}>{get(route, 'method')}</Verb>
28
28
  <Path>
29
- {map(formattedRoute, value => (
29
+ {map(formattedRoute, (value) => (
30
30
  <span key={value} style={includes(value, ':') ? { color: '#787E8F' } : {}}>
31
31
  /{value}
32
32
  </span>
@@ -1,7 +1,7 @@
1
1
  import styled from 'styled-components';
2
2
  import { Text } from '@buffetjs/core';
3
3
 
4
- const activeStyle = theme => `
4
+ const activeStyle = (theme) => `
5
5
  background-color: ${({ theme }) => theme.main.colors.lightestBlue};
6
6
  border: 1px solid ${theme.main.colors.darkBlue};
7
7
  ${Text} {
@@ -20,25 +20,20 @@ const Border = styled.div`
20
20
 
21
21
  const SubCategory = ({ subCategory }) => {
22
22
  const { formatMessage } = useIntl();
23
- const {
24
- onChange,
25
- onChangeSelectAll,
26
- onSelectedAction,
27
- selectedAction,
28
- modifiedData,
29
- } = useUsersPermissions();
23
+ const { onChange, onChangeSelectAll, onSelectedAction, selectedAction, modifiedData } =
24
+ useUsersPermissions();
30
25
 
31
26
  const currentScopedModifiedData = useMemo(() => {
32
27
  return get(modifiedData, subCategory.name, {});
33
28
  }, [modifiedData, subCategory]);
34
29
 
35
30
  const hasAllActionsSelected = useMemo(() => {
36
- return Object.values(currentScopedModifiedData).every(action => action.enabled === true);
31
+ return Object.values(currentScopedModifiedData).every((action) => action.enabled === true);
37
32
  }, [currentScopedModifiedData]);
38
33
 
39
34
  const hasSomeActionsSelected = useMemo(() => {
40
35
  return (
41
- Object.values(currentScopedModifiedData).some(action => action.enabled === true) &&
36
+ Object.values(currentScopedModifiedData).some((action) => action.enabled === true) &&
42
37
  !hasAllActionsSelected
43
38
  );
44
39
  }, [currentScopedModifiedData, hasAllActionsSelected]);
@@ -51,7 +46,7 @@ const SubCategory = ({ subCategory }) => {
51
46
  );
52
47
 
53
48
  const isActionSelected = useCallback(
54
- actionName => {
49
+ (actionName) => {
55
50
  return selectedAction === actionName;
56
51
  },
57
52
  [selectedAction]
@@ -86,7 +81,7 @@ const SubCategory = ({ subCategory }) => {
86
81
  <BaselineAlignment />
87
82
  <Padded top size="xs">
88
83
  <Flex flexWrap="wrap">
89
- {subCategory.actions.map(action => {
84
+ {subCategory.actions.map((action) => {
90
85
  const name = `${action.name}.enabled`;
91
86
 
92
87
  return (
@@ -72,7 +72,7 @@ const PermissionRow = ({ isOpen, isWhite, name, onOpenPlugin, permissions }) =>
72
72
  </RowStyle>
73
73
  {isOpen && (
74
74
  <PermissionsWrapper isWhite={isWhite}>
75
- {subCategories.map(subCategory => (
75
+ {subCategories.map((subCategory) => (
76
76
  <SubCategory key={subCategory.name} subCategory={subCategory} />
77
77
  ))}
78
78
  </PermissionsWrapper>
@@ -8,11 +8,11 @@ import { initialState, reducer } from './reducer';
8
8
 
9
9
  const Permissions = () => {
10
10
  const { modifiedData } = useUsersPermissions();
11
- const [{ collapses }, dispatch] = useReducer(reducer, initialState, state =>
11
+ const [{ collapses }, dispatch] = useReducer(reducer, initialState, (state) =>
12
12
  init(state, modifiedData)
13
13
  );
14
14
 
15
- const handleOpenPlugin = useCallback(index => {
15
+ const handleOpenPlugin = useCallback((index) => {
16
16
  dispatch({
17
17
  type: 'TOGGLE_COLLAPSE',
18
18
  index,
@@ -6,7 +6,7 @@ const initialState = {
6
6
 
7
7
  const reducer = (state, action) =>
8
8
  // eslint-disable-next-line consistent-return
9
- produce(state, draftState => {
9
+ produce(state, (draftState) => {
10
10
  switch (action.type) {
11
11
  case 'TOGGLE_COLLAPSE': {
12
12
  draftState.collapses = state.collapses.map((collapse, index) => {
@@ -16,7 +16,7 @@ const Policies = () => {
16
16
  const controllerRoutes = get(routes, path[0]);
17
17
  const displayedRoutes = isEmpty(controllerRoutes)
18
18
  ? []
19
- : controllerRoutes.filter(o => toLower(o.handler) === toLower(takeRight(path, 2).join('.')));
19
+ : controllerRoutes.filter((o) => toLower(o.handler) === toLower(takeRight(path, 2).join('.')));
20
20
 
21
21
  const inputName = `${selectedAction}.policy`;
22
22
 
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import styled from 'styled-components';
3
3
  import { Text } from '@buffetjs/core';
4
4
 
5
- const RoleDescription = styled(props => <Text {...props} ellipsis />)`
5
+ const RoleDescription = styled((props) => <Text {...props} ellipsis />)`
6
6
  max-width: 25rem;
7
7
  `;
8
8
 
@@ -13,7 +13,7 @@ import init from './init';
13
13
 
14
14
  const UsersPermissions = forwardRef(({ permissions, routes, policies }, ref) => {
15
15
  const { formatMessage } = useIntl();
16
- const [state, dispatch] = useReducer(reducer, initialState, state =>
16
+ const [state, dispatch] = useReducer(reducer, initialState, (state) =>
17
17
  init(state, permissions, routes, policies)
18
18
  );
19
19
 
@@ -47,7 +47,7 @@ const UsersPermissions = forwardRef(({ permissions, routes, policies }, ref) =>
47
47
  });
48
48
  }, []);
49
49
 
50
- const handleSelectedAction = useCallback(actionToSelect => {
50
+ const handleSelectedAction = useCallback((actionToSelect) => {
51
51
  dispatch({
52
52
  type: 'SELECT_ACTION',
53
53
  actionToSelect,
@@ -11,7 +11,7 @@ export const initialState = {
11
11
  };
12
12
 
13
13
  const reducer = (state, action) =>
14
- produce(state, draftState => {
14
+ produce(state, (draftState) => {
15
15
  switch (action.type) {
16
16
  case 'ON_CHANGE': {
17
17
  const keysLength = action.keys.length;
@@ -34,10 +34,8 @@ const AdvancedSettingsPage = () => {
34
34
  isLoading: isLoadingForPermissions,
35
35
  allowedActions: { canUpdate },
36
36
  } = useUserPermissions(updatePermissions);
37
- const [
38
- { initialData, isConfirmButtonLoading, isLoading, modifiedData, roles },
39
- dispatch,
40
- ] = useReducer(reducer, initialState);
37
+ const [{ initialData, isConfirmButtonLoading, isLoading, modifiedData, roles }, dispatch] =
38
+ useReducer(reducer, initialState);
41
39
  const isMounted = useRef(true);
42
40
  const abortController = new AbortController();
43
41
  const { signal } = abortController;
@@ -90,7 +88,7 @@ const AdvancedSettingsPage = () => {
90
88
  }, []);
91
89
 
92
90
  const handleSubmit = useCallback(
93
- async e => {
91
+ async (e) => {
94
92
  e.preventDefault();
95
93
 
96
94
  try {
@@ -134,7 +132,7 @@ const AdvancedSettingsPage = () => {
134
132
  }, []);
135
133
 
136
134
  const handleToggleModal = useCallback(() => {
137
- setShowModalWarning(prev => !prev);
135
+ setShowModalWarning((prev) => !prev);
138
136
  }, []);
139
137
 
140
138
  const headerActions = useMemo(() => {
@@ -184,7 +182,7 @@ const AdvancedSettingsPage = () => {
184
182
  <Header actions={headerActions} title={{ label: pageTitle }} isLoading={showLoader} />
185
183
  <ListBaselineAlignment />
186
184
  <FormBloc title={formTitle} isLoading={showLoader}>
187
- {form.map(input => {
185
+ {form.map((input) => {
188
186
  return (
189
187
  <SizedInput
190
188
  key={input.name}
@@ -11,7 +11,7 @@ const initialState = {
11
11
 
12
12
  const reducer = (state, action) =>
13
13
  // eslint-disable-next-line consistent-return
14
- produce(state, draftState => {
14
+ produce(state, (draftState) => {
15
15
  switch (action.type) {
16
16
  case 'GET_DATA': {
17
17
  draftState.isLoading = true;
@@ -26,7 +26,10 @@ const reducer = (state, action) =>
26
26
  draftState.isLoading = false;
27
27
  draftState.initialData = action.data.settings;
28
28
  draftState.modifiedData = action.data.settings;
29
- draftState.roles = action.data.roles.map(role => ({ label: role.name, value: role.type }));
29
+ draftState.roles = action.data.roles.map((role) => ({
30
+ label: role.name,
31
+ value: role.type,
32
+ }));
30
33
 
31
34
  break;
32
35
  }
@@ -56,7 +56,7 @@ const CustomTextInput = ({
56
56
  id={inputId}
57
57
  aria-invalid={error ? 'true' : 'false'}
58
58
  onBlur={onBlur}
59
- onChange={e => {
59
+ onChange={(e) => {
60
60
  if (!canCheck) {
61
61
  dispatch({
62
62
  type: 'SET_CHECK',
@@ -78,11 +78,11 @@ const EmailTemplatesPage = () => {
78
78
  }, [dispatchResetForm]);
79
79
 
80
80
  const handleToggle = useCallback(() => {
81
- setIsOpen(prev => !prev);
81
+ setIsOpen((prev) => !prev);
82
82
  }, []);
83
83
 
84
84
  const handleClickEdit = useCallback(
85
- template => {
85
+ (template) => {
86
86
  setTemplateToEdit(template);
87
87
  handleToggle();
88
88
  },
@@ -90,7 +90,7 @@ const EmailTemplatesPage = () => {
90
90
  );
91
91
 
92
92
  const handleSubmit = useCallback(
93
- async e => {
93
+ async (e) => {
94
94
  e.preventDefault();
95
95
 
96
96
  let errors = {};
@@ -157,7 +157,7 @@ const EmailTemplatesPage = () => {
157
157
  title={listTitle}
158
158
  items={emailTemplates}
159
159
  isLoading={isLoadingForPermissions || isLoading}
160
- customRowComponent={template => (
160
+ customRowComponent={(template) => (
161
161
  <ListRow
162
162
  {...template}
163
163
  onClick={() => {
@@ -168,7 +168,7 @@ const EmailTemplatesPage = () => {
168
168
  links={[
169
169
  {
170
170
  icon: canUpdate ? <Pencil fill="#0e1622" /> : null,
171
- onClick: e => {
171
+ onClick: (e) => {
172
172
  e.stopPropagation();
173
173
  handleClickEdit(template);
174
174
  },
@@ -194,7 +194,7 @@ const EmailTemplatesPage = () => {
194
194
  {showForm && (
195
195
  <form onSubmit={handleSubmit}>
196
196
  <Row>
197
- {forms.map(input => {
197
+ {forms.map((input) => {
198
198
  const id = get(templateToEdit, 'id');
199
199
 
200
200
  return (
@@ -10,7 +10,7 @@ const initialState = {
10
10
 
11
11
  const reducer = (state, action) =>
12
12
  // eslint-disable-next-line consistent-return
13
- produce(state, draftState => {
13
+ produce(state, (draftState) => {
14
14
  switch (action.type) {
15
15
  case 'GET_DATA': {
16
16
  draftState.isLoading = true;
@@ -9,10 +9,7 @@ const schema = yup.object().shape({
9
9
  .object()
10
10
  .shape({
11
11
  name: yup.string().required(translatedErrors.required),
12
- email: yup
13
- .string()
14
- .email(translatedErrors.email)
15
- .required(translatedErrors.required),
12
+ email: yup.string().email(translatedErrors.email).required(translatedErrors.required),
16
13
  })
17
14
  .required(),
18
15
  response_email: yup.string().email(translatedErrors.email),
@@ -49,7 +49,7 @@ const ProvidersPage = () => {
49
49
 
50
50
  const providers = useMemo(() => createProvidersArray(modifiedData), [modifiedData]);
51
51
  const enabledProvidersCount = useMemo(
52
- () => providers.filter(provider => provider.enabled).length,
52
+ () => providers.filter((provider) => provider.enabled).length,
53
53
  [providers]
54
54
  );
55
55
  const isProviderWithSubdomain = useMemo(() => {
@@ -57,7 +57,7 @@ const ProvidersPage = () => {
57
57
  return false;
58
58
  }
59
59
 
60
- const providerToEdit = providers.find(obj => obj.name === providerToEditName);
60
+ const providerToEdit = providers.find((obj) => obj.name === providerToEditName);
61
61
 
62
62
  return has(providerToEdit, 'subdomain');
63
63
  }, [providers, providerToEditName]);
@@ -105,11 +105,11 @@ const ProvidersPage = () => {
105
105
  }, []);
106
106
 
107
107
  const handleToggle = useCallback(() => {
108
- setIsOpen(prev => !prev);
108
+ setIsOpen((prev) => !prev);
109
109
  }, []);
110
110
 
111
111
  const handleClickEdit = useCallback(
112
- provider => {
112
+ (provider) => {
113
113
  if (canUpdate) {
114
114
  setProviderToEditName(provider.name);
115
115
  handleToggle();
@@ -129,7 +129,7 @@ const ProvidersPage = () => {
129
129
  }, []);
130
130
 
131
131
  const handleSubmit = useCallback(
132
- async e => {
132
+ async (e) => {
133
133
  e.preventDefault();
134
134
  const { schema } = formToRender;
135
135
  let errors = {};
@@ -196,14 +196,14 @@ const ProvidersPage = () => {
196
196
  title={listTitle}
197
197
  items={providers}
198
198
  isLoading={isLoadingForPermissions || isLoading}
199
- customRowComponent={provider => (
199
+ customRowComponent={(provider) => (
200
200
  <ListRow
201
201
  {...provider}
202
202
  onClick={() => handleClickEdit(provider)}
203
203
  links={[
204
204
  {
205
205
  icon: canUpdate ? <Pencil fill="#0e1622" /> : null,
206
- onClick: e => {
206
+ onClick: (e) => {
207
207
  e.stopPropagation();
208
208
  handleClickEdit(provider);
209
209
  },
@@ -247,7 +247,7 @@ const ProvidersPage = () => {
247
247
  {showForm && (
248
248
  <form onSubmit={handleSubmit}>
249
249
  <Row>
250
- {formToRender.form.map(input => {
250
+ {formToRender.form.map((input) => {
251
251
  const label = input.label.params
252
252
  ? { ...input.label, params: { provider: upperFirst(providerToEditName) } }
253
253
  : input.label;
@@ -10,7 +10,7 @@ const initialState = {
10
10
 
11
11
  const reducer = (state, action) =>
12
12
  // eslint-disable-next-line consistent-return
13
- produce(state, draftState => {
13
+ produce(state, (draftState) => {
14
14
  switch (action.type) {
15
15
  case 'GET_DATA': {
16
16
  draftState.isLoading = true;
@@ -1,6 +1,6 @@
1
1
  import { sortBy } from 'lodash';
2
2
 
3
- const createProvidersArray = data => {
3
+ const createProvidersArray = (data) => {
4
4
  return sortBy(
5
5
  Object.keys(data).reduce((acc, current) => {
6
6
  const { icon: iconName, enabled, subdomain } = data[current];
@@ -54,7 +54,7 @@ const CreatePage = () => {
54
54
  ];
55
55
  };
56
56
 
57
- const handleCreateRoleSubmit = data => {
57
+ const handleCreateRoleSubmit = (data) => {
58
58
  strapi.lockAppWithOverlay();
59
59
  setIsSubmiting(true);
60
60
 
@@ -76,7 +76,7 @@ const CreatePage = () => {
76
76
  // TODO
77
77
  goBack();
78
78
  })
79
- .catch(err => {
79
+ .catch((err) => {
80
80
  console.error(err);
81
81
  strapi.notification.toggle({
82
82
  type: 'warning',
@@ -59,7 +59,7 @@ const EditPage = () => {
59
59
  ];
60
60
  };
61
61
 
62
- const handleCreateRoleSubmit = data => {
62
+ const handleCreateRoleSubmit = (data) => {
63
63
  strapi.lockAppWithOverlay();
64
64
  setIsSubmiting(true);
65
65
 
@@ -79,7 +79,7 @@ const EditPage = () => {
79
79
  message: { id: getTrad('Settings.roles.edited') },
80
80
  });
81
81
  })
82
- .catch(err => {
82
+ .catch((err) => {
83
83
  console.error(err);
84
84
  strapi.notification.toggle({
85
85
  type: 'warning',
@@ -38,7 +38,7 @@ const RoleListPage = () => {
38
38
 
39
39
  const { roles, getData, isLoading } = useRolesList(shouldFetchData);
40
40
 
41
- const handleGoTo = id => {
41
+ const handleGoTo = (id) => {
42
42
  if (canUpdate) {
43
43
  push(`/settings/${pluginId}/roles/${id}`);
44
44
  }
@@ -61,7 +61,7 @@ const RoleListPage = () => {
61
61
  message: { id: getTrad('Settings.roles.deleted') },
62
62
  });
63
63
  })
64
- .catch(err => {
64
+ .catch((err) => {
65
65
  console.error(err);
66
66
  strapi.notification.toggle({
67
67
  type: 'warning',
@@ -105,13 +105,13 @@ const RoleListPage = () => {
105
105
  /* eslint-enable indent */
106
106
 
107
107
  const checkCanDeleteRole = useCallback(
108
- role => {
108
+ (role) => {
109
109
  return canDelete && !['public', 'authenticated'].includes(role.type);
110
110
  },
111
111
  [canDelete]
112
112
  );
113
113
 
114
- const getLinks = role => {
114
+ const getLinks = (role) => {
115
115
  const links = [];
116
116
 
117
117
  if (canUpdate) {
@@ -123,7 +123,7 @@ const RoleListPage = () => {
123
123
  if (checkCanDeleteRole(role)) {
124
124
  links.push({
125
125
  icon: <FontAwesomeIcon icon="trash-alt" />,
126
- onClick: e => {
126
+ onClick: (e) => {
127
127
  e.preventDefault();
128
128
  setModalDelete(role.id);
129
129
  e.stopPropagation();
@@ -167,7 +167,7 @@ const RoleListPage = () => {
167
167
  )}
168
168
  items={roles}
169
169
  isLoading={isLoading || isLoadingForPermissions}
170
- customRowComponent={role => (
170
+ customRowComponent={(role) => (
171
171
  <RoleRow onClick={() => handleGoTo(role.id)} links={getLinks(role)} role={role} />
172
172
  )}
173
173
  />
@@ -5,7 +5,7 @@ import reducer, { initialState } from './reducer';
5
5
 
6
6
  import pluginId from '../../pluginId';
7
7
 
8
- const useFetchRole = id => {
8
+ const useFetchRole = (id) => {
9
9
  const [state, dispatch] = useReducer(reducer, initialState);
10
10
 
11
11
  useEffect(() => {
@@ -21,7 +21,7 @@ const useFetchRole = id => {
21
21
  // eslint-disable-next-line react-hooks/exhaustive-deps
22
22
  }, [id]);
23
23
 
24
- const fetchRole = async roleId => {
24
+ const fetchRole = async (roleId) => {
25
25
  try {
26
26
  const { role } = await request(`/${pluginId}/roles/${roleId}`, { method: 'GET' });
27
27
 
@@ -42,7 +42,7 @@ const useFetchRole = id => {
42
42
  }
43
43
  };
44
44
 
45
- const handleSubmitSucceeded = useCallback(data => {
45
+ const handleSubmitSucceeded = useCallback((data) => {
46
46
  dispatch({
47
47
  type: 'ON_SUBMIT_SUCCEEDED',
48
48
  ...data,
@@ -7,7 +7,7 @@ export const initialState = {
7
7
  };
8
8
 
9
9
  const reducer = (state, action) =>
10
- produce(state, draftState => {
10
+ produce(state, (draftState) => {
11
11
  switch (action.type) {
12
12
  case 'GET_DATA_SUCCEEDED': {
13
13
  draftState.role = action.role;
@@ -68,7 +68,7 @@ const useUserForm = (endPoint, permissions) => {
68
68
  });
69
69
  }, []);
70
70
 
71
- const dispatchSetFormErrors = useCallback(errors => {
71
+ const dispatchSetFormErrors = useCallback((errors) => {
72
72
  dispatch({ type: 'SET_ERRORS', errors });
73
73
  }, []);
74
74
 
@@ -10,7 +10,7 @@ const initialState = {
10
10
 
11
11
  const reducer = (state, action) =>
12
12
  // eslint-disable-next-line consistent-return
13
- produce(state, draftState => {
13
+ produce(state, (draftState) => {
14
14
  switch (action.type) {
15
15
  case 'GET_DATA': {
16
16
  draftState.isLoading = true;
@@ -22,8 +22,8 @@ const usePlugins = (shouldFetchData = true) => {
22
22
  });
23
23
 
24
24
  const [{ permissions }, { routes }, { policies }] = await Promise.all(
25
- [`/${pluginId}/permissions`, `/${pluginId}/routes`, `/${pluginId}/policies`].map(endpoint =>
26
- request(endpoint, { method: 'GET' })
25
+ [`/${pluginId}/permissions`, `/${pluginId}/routes`, `/${pluginId}/policies`].map(
26
+ (endpoint) => request(endpoint, { method: 'GET' })
27
27
  )
28
28
  );
29
29
 
@@ -9,7 +9,7 @@ export const initialState = {
9
9
  };
10
10
 
11
11
  const reducer = (state, action) =>
12
- produce(state, draftState => {
12
+ produce(state, (draftState) => {
13
13
  switch (action.type) {
14
14
  case 'GET_DATA': {
15
15
  draftState.isLoading = true;
@@ -7,7 +7,7 @@ export const initialState = {
7
7
  };
8
8
 
9
9
  const reducer = (state, action) =>
10
- produce(state, draftState => {
10
+ produce(state, (draftState) => {
11
11
  switch (action.type) {
12
12
  case 'GET_DATA': {
13
13
  draftState.isLoading = true;
@@ -18,7 +18,7 @@ import EmailTemplatesPage from './containers/EmailTemplates';
18
18
  import AdvancedSettingsPage from './containers/AdvancedSettings';
19
19
  import getTrad from './utils/getTrad';
20
20
 
21
- export default strapi => {
21
+ export default (strapi) => {
22
22
  const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
23
23
  const icon = pluginPkg.strapi.icon;
24
24
  const name = pluginPkg.strapi.name;
@@ -1,5 +1,5 @@
1
1
  import pluginPkg from '../../package.json';
2
2
 
3
- const pluginId = pluginPkg.name.replace(/^strapi-plugin-/i, '');
3
+ const pluginId = pluginPkg.name.replace(/^@akemona-org\/strapi-plugin-/i, '');
4
4
 
5
5
  export default pluginId;
@@ -1,6 +1,6 @@
1
1
  import { isEmpty } from 'lodash';
2
2
 
3
- const cleanPermissions = permissions =>
3
+ const cleanPermissions = (permissions) =>
4
4
  Object.keys(permissions).reduce((acc, current) => {
5
5
  const currentPermission = permissions[current].controllers;
6
6
  const cleanedControllers = Object.keys(currentPermission).reduce((acc2, curr) => {
@@ -1,4 +1,4 @@
1
- const formatPolicies = policies =>
1
+ const formatPolicies = (policies) =>
2
2
  policies.reduce((acc, current) => {
3
3
  acc.push({ label: current, value: current });
4
4
 
@@ -1,5 +1,5 @@
1
1
  import pluginId from '../pluginId';
2
2
 
3
- const getRequestURL = endPoint => `/${pluginId}/${endPoint}`;
3
+ const getRequestURL = (endPoint) => `/${pluginId}/${endPoint}`;
4
4
 
5
5
  export default getRequestURL;
@@ -1,5 +1,5 @@
1
1
  import pluginId from '../pluginId';
2
2
 
3
- const getTrad = id => `${pluginId}.${id}`;
3
+ const getTrad = (id) => `${pluginId}.${id}`;
4
4
 
5
5
  export default getTrad;
@@ -146,7 +146,7 @@ module.exports = async () => {
146
146
  // or we have added/deleted provider here.
147
147
  if (!prevGrantConfig || !_.isEqual(_.keys(prevGrantConfig), _.keys(grantConfig))) {
148
148
  // merge with the previous provider config.
149
- _.keys(grantConfig).forEach(key => {
149
+ _.keys(grantConfig).forEach((key) => {
150
150
  if (key in prevGrantConfig) {
151
151
  grantConfig[key] = _.merge(grantConfig[key], prevGrantConfig[key]);
152
152
  }
@@ -241,9 +241,8 @@ module.exports = {
241
241
 
242
242
  for (const provider in providers) {
243
243
  if (provider !== 'email') {
244
- providers[provider].redirectUri = strapi.plugins[
245
- 'users-permissions'
246
- ].services.providers.buildRedirectUri(provider);
244
+ providers[provider].redirectUri =
245
+ strapi.plugins['users-permissions'].services.providers.buildRedirectUri(provider);
247
246
  }
248
247
  }
249
248
 
@@ -272,11 +271,11 @@ const searchQueries = {
272
271
  bookshelf({ model }) {
273
272
  return ({ id }) => {
274
273
  return model
275
- .query(function(qb) {
274
+ .query(function (qb) {
276
275
  qb.where('username', 'LIKE', `%${id}%`).orWhere('email', 'LIKE', `%${id}%`);
277
276
  })
278
277
  .fetchAll()
279
- .then(results => results.toJSON());
278
+ .then((results) => results.toJSON());
280
279
  };
281
280
  },
282
281
  mongoose({ model }) {
@@ -18,7 +18,7 @@ const matchAll = (pattern, src) => {
18
18
  return matches;
19
19
  };
20
20
 
21
- const isValidEmailTemplate = template => {
21
+ const isValidEmailTemplate = (template) => {
22
22
  for (let reg of invalidPatternsRegexes) {
23
23
  if (reg.test(template)) {
24
24
  return false;
@@ -7,28 +7,28 @@
7
7
  // Public node modules.
8
8
  const _ = require('lodash');
9
9
 
10
- module.exports = strapi => {
10
+ module.exports = (strapi) => {
11
11
  return {
12
12
  beforeInitialize() {
13
13
  strapi.config.middleware.load.before.unshift('users-permissions');
14
14
  },
15
15
 
16
16
  initialize() {
17
- _.forEach(strapi.admin.config.routes, value => {
17
+ _.forEach(strapi.admin.config.routes, (value) => {
18
18
  if (_.get(value.config, 'policies')) {
19
19
  value.config.policies.unshift('plugins::users-permissions.permissions');
20
20
  }
21
21
  });
22
22
 
23
- _.forEach(strapi.config.routes, value => {
23
+ _.forEach(strapi.config.routes, (value) => {
24
24
  if (_.get(value.config, 'policies')) {
25
25
  value.config.policies.unshift('plugins::users-permissions.permissions');
26
26
  }
27
27
  });
28
28
 
29
29
  if (strapi.plugins) {
30
- _.forEach(strapi.plugins, plugin => {
31
- _.forEach(plugin.config.routes, value => {
30
+ _.forEach(strapi.plugins, (plugin) => {
31
+ _.forEach(plugin.config.routes, (value) => {
32
32
  if (_.get(value.config, 'policies')) {
33
33
  value.config.policies.unshift('plugins::users-permissions.permissions');
34
34
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.7.0",
6
+ "version": "3.7.1",
7
7
  "description": "Protect your API with a full-authentication process based on JWT",
8
8
  "strapi": {
9
9
  "name": "Roles & Permissions",
@@ -15,8 +15,8 @@
15
15
  "test": "echo \"no tests yet\""
16
16
  },
17
17
  "dependencies": {
18
- "@akemona-org/strapi-helper-plugin": "3.7.0",
19
- "@akemona-org/strapi-utils": "3.7.0",
18
+ "@akemona-org/strapi-helper-plugin": "3.7.1",
19
+ "@akemona-org/strapi-utils": "3.7.1",
20
20
  "@buffetjs/core": "3.3.8",
21
21
  "@buffetjs/custom": "3.3.8",
22
22
  "@buffetjs/hooks": "3.3.8",
@@ -66,5 +66,5 @@
66
66
  "npm": ">=6.0.0"
67
67
  },
68
68
  "license": "SEE LICENSE IN LICENSE",
69
- "gitHead": "129a8d6191b55810fd66448dcc47fee829df986c"
69
+ "gitHead": "5545ca033e2fb1aa3afbd546c370972426058525"
70
70
  }
package/services/Jwt.js CHANGED
@@ -48,12 +48,12 @@ module.exports = {
48
48
  },
49
49
 
50
50
  verify(token) {
51
- return new Promise(function(resolve, reject) {
51
+ return new Promise(function (resolve, reject) {
52
52
  jwt.verify(
53
53
  token,
54
54
  _.get(strapi.plugins, ['users-permissions', 'config', 'jwtSecret']),
55
55
  {},
56
- function(err, tokenPayload = {}) {
56
+ function (err, tokenPayload = {}) {
57
57
  if (err) {
58
58
  return reject(new Error('Invalid token.'));
59
59
  }
@@ -30,7 +30,7 @@ const DEFAULT_PERMISSIONS = [
30
30
 
31
31
  const isPermissionEnabled = (permission, role) =>
32
32
  DEFAULT_PERMISSIONS.some(
33
- defaultPerm =>
33
+ (defaultPerm) =>
34
34
  (defaultPerm.action === null || permission.action === defaultPerm.action) &&
35
35
  (defaultPerm.controller === null || permission.controller === defaultPerm.controller) &&
36
36
  (defaultPerm.type === null || permission.type === defaultPerm.type) &&
@@ -48,8 +48,8 @@ module.exports = {
48
48
  .create(_.omit(params, ['users', 'permissions']));
49
49
 
50
50
  const arrayOfPromises = Object.keys(params.permissions || {}).reduce((acc, type) => {
51
- Object.keys(params.permissions[type].controllers).forEach(controller => {
52
- Object.keys(params.permissions[type].controllers[controller]).forEach(action => {
51
+ Object.keys(params.permissions[type].controllers).forEach((controller) => {
52
+ Object.keys(params.permissions[type].controllers[controller]).forEach((action) => {
53
53
  acc.push(
54
54
  strapi.query('permission', 'users-permissions').create({
55
55
  role: role.id,
@@ -105,7 +105,7 @@ module.exports = {
105
105
  }, []);
106
106
 
107
107
  // Remove permissions related to this role.
108
- role.permissions.forEach(permission => {
108
+ role.permissions.forEach((permission) => {
109
109
  arrayOfPromises.push(
110
110
  strapi.query('permission', 'users-permissions').delete({
111
111
  id: permission.id,
@@ -120,7 +120,7 @@ module.exports = {
120
120
  },
121
121
 
122
122
  getPlugins(lang = 'en') {
123
- return new Promise(resolve => {
123
+ return new Promise((resolve) => {
124
124
  request(
125
125
  {
126
126
  uri: `https://marketplace.strapi.io/plugins?lang=${lang}`,
@@ -142,7 +142,7 @@ module.exports = {
142
142
  },
143
143
 
144
144
  getActions() {
145
- const generateActions = data =>
145
+ const generateActions = (data) =>
146
146
  Object.keys(data).reduce((acc, key) => {
147
147
  if (_.isFunction(data[key])) {
148
148
  acc[key] = { enabled: false, policy: '' };
@@ -152,10 +152,10 @@ module.exports = {
152
152
  }, {});
153
153
 
154
154
  const appControllers = Object.keys(strapi.api || {})
155
- .filter(key => !!strapi.api[key].controllers)
155
+ .filter((key) => !!strapi.api[key].controllers)
156
156
  .reduce(
157
157
  (acc, key) => {
158
- Object.keys(strapi.api[key].controllers).forEach(controller => {
158
+ Object.keys(strapi.api[key].controllers).forEach((controller) => {
159
159
  acc.controllers[controller] = generateActions(strapi.api[key].controllers[controller]);
160
160
  });
161
161
 
@@ -205,7 +205,7 @@ module.exports = {
205
205
 
206
206
  if (permission.type !== 'application' && !acc[permission.type].information) {
207
207
  acc[permission.type].information =
208
- plugins.find(plugin => plugin.id === permission.type) || {};
208
+ plugins.find((plugin) => plugin.id === permission.type) || {};
209
209
  }
210
210
 
211
211
  return acc;
@@ -260,16 +260,16 @@ module.exports = {
260
260
  .query('permission', 'users-permissions')
261
261
  .find({ _limit: -1 });
262
262
  let permissionsFoundInDB = dbPermissions.map(
263
- p => `${p.type}.${p.controller}.${p.action}.${p.role[primaryKey]}`
263
+ (p) => `${p.type}.${p.controller}.${p.action}.${p.role[primaryKey]}`
264
264
  );
265
265
  permissionsFoundInDB = _.uniq(permissionsFoundInDB);
266
266
 
267
267
  // Aggregate first level actions.
268
268
  const appActions = Object.keys(strapi.api || {}).reduce((acc, api) => {
269
- Object.keys(_.get(strapi.api[api], 'controllers', {})).forEach(controller => {
269
+ Object.keys(_.get(strapi.api[api], 'controllers', {})).forEach((controller) => {
270
270
  const actions = Object.keys(strapi.api[api].controllers[controller])
271
- .filter(action => _.isFunction(strapi.api[api].controllers[controller][action]))
272
- .map(action => `application.${controller}.${action.toLowerCase()}`);
271
+ .filter((action) => _.isFunction(strapi.api[api].controllers[controller][action]))
272
+ .map((action) => `application.${controller}.${action.toLowerCase()}`);
273
273
 
274
274
  acc = acc.concat(actions);
275
275
  });
@@ -279,10 +279,10 @@ module.exports = {
279
279
 
280
280
  // Aggregate plugins' actions.
281
281
  const pluginsActions = Object.keys(strapi.plugins).reduce((acc, plugin) => {
282
- Object.keys(strapi.plugins[plugin].controllers).forEach(controller => {
282
+ Object.keys(strapi.plugins[plugin].controllers).forEach((controller) => {
283
283
  const actions = Object.keys(strapi.plugins[plugin].controllers[controller])
284
- .filter(action => _.isFunction(strapi.plugins[plugin].controllers[controller][action]))
285
- .map(action => `${plugin}.${controller}.${action.toLowerCase()}`);
284
+ .filter((action) => _.isFunction(strapi.plugins[plugin].controllers[controller][action]))
285
+ .map((action) => `${plugin}.${controller}.${action.toLowerCase()}`);
286
286
 
287
287
  acc = acc.concat(actions);
288
288
  });
@@ -294,14 +294,14 @@ module.exports = {
294
294
 
295
295
  // create permissions for each role
296
296
  let permissionsFoundInFiles = actionsFoundInFiles.reduce(
297
- (acc, action) => [...acc, ...roles.map(role => `${action}.${role[primaryKey]}`)],
297
+ (acc, action) => [...acc, ...roles.map((role) => `${action}.${role[primaryKey]}`)],
298
298
  []
299
299
  );
300
300
  permissionsFoundInFiles = _.uniq(permissionsFoundInFiles);
301
301
 
302
302
  // Compare to know if actions have been added or removed from controllers.
303
303
  if (!_.isEqual(permissionsFoundInDB.sort(), permissionsFoundInFiles.sort())) {
304
- const splitted = str => {
304
+ const splitted = (str) => {
305
305
  const [type, controller, action, roleId] = str.split('.');
306
306
 
307
307
  return { type, controller, action, roleId };
@@ -315,7 +315,7 @@ module.exports = {
315
315
 
316
316
  // Execute request to update entries in database for each role.
317
317
  await Promise.all(
318
- toAdd.map(permission =>
318
+ toAdd.map((permission) =>
319
319
  query.create({
320
320
  type: permission.type,
321
321
  controller: permission.controller,
@@ -328,7 +328,7 @@ module.exports = {
328
328
  );
329
329
 
330
330
  await Promise.all(
331
- toRemove.map(permission => {
331
+ toRemove.map((permission) => {
332
332
  const { type, controller, action, roleId: role } = permission;
333
333
  return query.delete({ type, controller, action, role });
334
334
  })
@@ -368,8 +368,8 @@ module.exports = {
368
368
 
369
369
  await Promise.all(
370
370
  Object.keys(body.permissions || {}).reduce((acc, type) => {
371
- Object.keys(body.permissions[type].controllers).forEach(controller => {
372
- Object.keys(body.permissions[type].controllers[controller]).forEach(action => {
371
+ Object.keys(body.permissions[type].controllers).forEach((controller) => {
372
+ Object.keys(body.permissions[type].controllers[controller]).forEach((action) => {
373
373
  const bodyAction = body.permissions[type].controllers[controller][action];
374
374
  const currentAction = _.get(
375
375
  role.permissions,
@@ -399,10 +399,10 @@ module.exports = {
399
399
 
400
400
  // Add user to this role.
401
401
  const newUsers = _.differenceBy(body.users, role.users, 'id');
402
- await Promise.all(newUsers.map(user => this.updateUserRole(user, roleID)));
402
+ await Promise.all(newUsers.map((user) => this.updateUserRole(user, roleID)));
403
403
 
404
404
  const oldUsers = _.differenceBy(role.users, body.users, 'id');
405
- await Promise.all(oldUsers.map(user => this.updateUserRole(user, authenticated.id)));
405
+ await Promise.all(oldUsers.map((user) => this.updateUserRole(user, authenticated.id)));
406
406
  },
407
407
 
408
408
  async updateUserRole(user, role) {