@strapi/plugin-users-permissions 4.0.0-next.6 → 4.0.0

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 (196) hide show
  1. package/admin/src/components/BoundRoute/getMethodColor.js +41 -0
  2. package/admin/src/components/BoundRoute/index.js +40 -24
  3. package/admin/src/components/FormModal/Input/index.js +121 -0
  4. package/admin/src/components/FormModal/index.js +123 -0
  5. package/admin/src/components/Permissions/PermissionRow/CheckboxWrapper.js +19 -26
  6. package/admin/src/components/Permissions/PermissionRow/SubCategory.js +118 -0
  7. package/admin/src/components/Permissions/PermissionRow/index.js +9 -48
  8. package/admin/src/components/Permissions/index.js +36 -24
  9. package/admin/src/components/Permissions/init.js +1 -6
  10. package/admin/src/components/Policies/index.js +46 -47
  11. package/admin/src/components/UsersPermissions/index.js +29 -26
  12. package/admin/src/components/UsersPermissions/init.js +1 -2
  13. package/admin/src/hooks/useFetchRole/index.js +17 -7
  14. package/admin/src/hooks/useForm/index.js +3 -29
  15. package/admin/src/hooks/useForm/reducer.js +2 -21
  16. package/admin/src/hooks/usePlugins/index.js +12 -21
  17. package/admin/src/hooks/usePlugins/reducer.js +0 -3
  18. package/admin/src/index.js +29 -34
  19. package/admin/src/pages/AdvancedSettings/index.js +210 -193
  20. package/admin/src/pages/AdvancedSettings/utils/api.js +13 -0
  21. package/admin/src/pages/AdvancedSettings/utils/layout.js +96 -0
  22. package/admin/src/pages/AdvancedSettings/utils/schema.js +22 -0
  23. package/admin/src/pages/EmailTemplates/components/EmailForm.js +173 -0
  24. package/admin/src/pages/EmailTemplates/components/EmailTable.js +116 -0
  25. package/admin/src/pages/EmailTemplates/index.js +125 -198
  26. package/admin/src/pages/EmailTemplates/utils/api.js +13 -0
  27. package/admin/src/pages/Providers/index.js +208 -216
  28. package/admin/src/pages/Providers/utils/api.js +21 -0
  29. package/admin/src/pages/Providers/utils/forms.js +168 -126
  30. package/admin/src/pages/Roles/CreatePage/index.js +155 -147
  31. package/admin/src/pages/Roles/EditPage/index.js +162 -134
  32. package/admin/src/pages/Roles/ListPage/components/TableBody.js +96 -0
  33. package/admin/src/pages/Roles/ListPage/index.js +176 -156
  34. package/admin/src/pages/Roles/ListPage/utils/api.js +28 -0
  35. package/admin/src/pages/Roles/index.js +14 -8
  36. package/admin/src/permissions.js +12 -14
  37. package/admin/src/translations/ar.json +0 -8
  38. package/admin/src/translations/cs.json +0 -8
  39. package/admin/src/translations/de.json +0 -8
  40. package/admin/src/translations/dk.json +0 -8
  41. package/admin/src/translations/en.json +33 -12
  42. package/admin/src/translations/es.json +0 -8
  43. package/admin/src/translations/fr.json +0 -8
  44. package/admin/src/translations/id.json +0 -8
  45. package/admin/src/translations/it.json +0 -8
  46. package/admin/src/translations/ja.json +0 -8
  47. package/admin/src/translations/ko.json +0 -8
  48. package/admin/src/translations/ms.json +0 -8
  49. package/admin/src/translations/nl.json +0 -8
  50. package/admin/src/translations/pl.json +0 -8
  51. package/admin/src/translations/pt-BR.json +0 -8
  52. package/admin/src/translations/pt.json +0 -8
  53. package/admin/src/translations/ru.json +0 -8
  54. package/admin/src/translations/sk.json +0 -8
  55. package/admin/src/translations/sv.json +0 -8
  56. package/admin/src/translations/th.json +0 -8
  57. package/admin/src/translations/tr.json +0 -8
  58. package/admin/src/translations/uk.json +0 -8
  59. package/admin/src/translations/vi.json +0 -8
  60. package/admin/src/translations/zh-Hans.json +5 -14
  61. package/admin/src/translations/zh.json +0 -8
  62. package/admin/src/utils/axiosInstance.js +36 -0
  63. package/admin/src/utils/formatPluginName.js +26 -0
  64. package/admin/src/utils/index.js +1 -0
  65. package/documentation/1.0.0/overrides/users-permissions-Role.json +6 -6
  66. package/documentation/1.0.0/overrides/users-permissions-User.json +7 -7
  67. package/package.json +30 -29
  68. package/{config/functions/bootstrap.js → server/bootstrap/index.js} +26 -33
  69. package/{config → server/bootstrap}/users-permissions-actions.js +0 -0
  70. package/server/config.js +23 -0
  71. package/server/content-types/index.js +11 -0
  72. package/server/content-types/permission/index.js +34 -0
  73. package/server/content-types/role/index.js +51 -0
  74. package/server/content-types/user/index.js +72 -0
  75. package/{models/User.config.js → server/content-types/user/schema-config.js} +0 -0
  76. package/server/controllers/auth.js +440 -0
  77. package/server/controllers/content-manager-user.js +183 -0
  78. package/server/controllers/index.js +17 -0
  79. package/server/controllers/permissions.js +26 -0
  80. package/server/controllers/role.js +77 -0
  81. package/server/controllers/settings.js +85 -0
  82. package/server/controllers/user.js +191 -0
  83. package/server/controllers/validation/auth.js +29 -0
  84. package/{controllers → server/controllers}/validation/email-template.js +0 -0
  85. package/server/controllers/validation/user.js +38 -0
  86. package/server/graphql/index.js +44 -0
  87. package/server/graphql/mutations/auth/email-confirmation.js +39 -0
  88. package/server/graphql/mutations/auth/forgot-password.js +38 -0
  89. package/server/graphql/mutations/auth/login.js +38 -0
  90. package/server/graphql/mutations/auth/register.js +39 -0
  91. package/server/graphql/mutations/auth/reset-password.js +41 -0
  92. package/server/graphql/mutations/crud/role/create-role.js +37 -0
  93. package/server/graphql/mutations/crud/role/delete-role.js +28 -0
  94. package/server/graphql/mutations/crud/role/update-role.js +38 -0
  95. package/server/graphql/mutations/crud/user/create-user.js +48 -0
  96. package/server/graphql/mutations/crud/user/delete-user.js +42 -0
  97. package/server/graphql/mutations/crud/user/update-user.js +49 -0
  98. package/server/graphql/mutations/index.js +42 -0
  99. package/server/graphql/queries/index.js +13 -0
  100. package/server/graphql/queries/me.js +17 -0
  101. package/server/graphql/resolvers-configs.js +37 -0
  102. package/server/graphql/types/create-role-payload.js +11 -0
  103. package/server/graphql/types/delete-role-payload.js +11 -0
  104. package/server/graphql/types/index.js +21 -0
  105. package/server/graphql/types/login-input.js +13 -0
  106. package/server/graphql/types/login-payload.js +12 -0
  107. package/server/graphql/types/me-role.js +14 -0
  108. package/server/graphql/types/me.js +16 -0
  109. package/server/graphql/types/password-payload.js +11 -0
  110. package/server/graphql/types/register-input.js +13 -0
  111. package/server/graphql/types/update-role-payload.js +11 -0
  112. package/server/graphql/utils.js +27 -0
  113. package/server/index.js +21 -0
  114. package/server/middlewares/index.js +7 -0
  115. package/{config/policies → server/middlewares}/rateLimit.js +4 -8
  116. package/server/register.js +11 -0
  117. package/server/routes/admin/index.js +10 -0
  118. package/server/routes/admin/permissions.js +20 -0
  119. package/server/routes/admin/role.js +79 -0
  120. package/server/routes/admin/settings.js +95 -0
  121. package/server/routes/content-api/auth.js +73 -0
  122. package/server/routes/content-api/index.js +11 -0
  123. package/server/routes/content-api/permissions.js +9 -0
  124. package/server/routes/content-api/role.js +29 -0
  125. package/server/routes/content-api/user.js +61 -0
  126. package/server/routes/index.js +6 -0
  127. package/server/services/index.js +15 -0
  128. package/server/services/jwt.js +55 -0
  129. package/server/services/providers.js +599 -0
  130. package/server/services/role.js +177 -0
  131. package/{services → server/services}/user.js +32 -35
  132. package/server/services/users-permissions.js +233 -0
  133. package/server/strategies/users-permissions.js +123 -0
  134. package/{utils → server/utils}/index.d.ts +6 -1
  135. package/server/utils/index.js +9 -0
  136. package/strapi-admin.js +3 -0
  137. package/strapi-server.js +3 -0
  138. package/admin/src/assets/images/logo.svg +0 -1
  139. package/admin/src/components/BaselineAlignement/index.js +0 -33
  140. package/admin/src/components/Bloc/index.js +0 -10
  141. package/admin/src/components/BoundRoute/Components.js +0 -78
  142. package/admin/src/components/ContainerFluid/index.js +0 -13
  143. package/admin/src/components/FormBloc/index.js +0 -61
  144. package/admin/src/components/IntlInput/index.js +0 -38
  145. package/admin/src/components/ListBaselineAlignment/index.js +0 -8
  146. package/admin/src/components/ListRow/Components.js +0 -74
  147. package/admin/src/components/ListRow/index.js +0 -35
  148. package/admin/src/components/ModalForm/Wrapper.js +0 -12
  149. package/admin/src/components/ModalForm/index.js +0 -59
  150. package/admin/src/components/Permissions/ListWrapper.js +0 -9
  151. package/admin/src/components/Permissions/PermissionRow/BaselineAlignment.js +0 -7
  152. package/admin/src/components/Permissions/PermissionRow/RowStyle.js +0 -28
  153. package/admin/src/components/Permissions/PermissionRow/SubCategory/ConditionsButtonWrapper.js +0 -13
  154. package/admin/src/components/Permissions/PermissionRow/SubCategory/PolicyWrapper.js +0 -8
  155. package/admin/src/components/Permissions/PermissionRow/SubCategory/SubCategoryWrapper.js +0 -26
  156. package/admin/src/components/Permissions/PermissionRow/SubCategory/index.js +0 -116
  157. package/admin/src/components/Policies/Components.js +0 -26
  158. package/admin/src/components/PrefixedIcon/index.js +0 -27
  159. package/admin/src/components/Roles/EmptyRole/BaselineAlignment.js +0 -7
  160. package/admin/src/components/Roles/EmptyRole/index.js +0 -27
  161. package/admin/src/components/Roles/RoleListWrapper/index.js +0 -17
  162. package/admin/src/components/Roles/RoleRow/RoleDescription.js +0 -9
  163. package/admin/src/components/Roles/RoleRow/index.js +0 -45
  164. package/admin/src/components/Roles/index.js +0 -3
  165. package/admin/src/components/SizedInput/index.js +0 -24
  166. package/admin/src/pages/AdvancedSettings/reducer.js +0 -65
  167. package/admin/src/pages/AdvancedSettings/utils/form.js +0 -52
  168. package/admin/src/pages/EmailTemplates/CustomTextInput.js +0 -105
  169. package/admin/src/pages/EmailTemplates/Wrapper.js +0 -36
  170. package/admin/src/pages/EmailTemplates/reducer.js +0 -58
  171. package/admin/src/pages/EmailTemplates/utils/forms.js +0 -81
  172. package/admin/src/pages/Roles/ListPage/BaselineAlignment.js +0 -8
  173. package/config/layout.js +0 -10
  174. package/config/policies/isAuthenticated.js +0 -9
  175. package/config/policies/permissions.js +0 -94
  176. package/config/request.json +0 -6
  177. package/config/routes.json +0 -381
  178. package/config/schema.graphql.js +0 -284
  179. package/config/security.json +0 -5
  180. package/controllers/auth.js +0 -596
  181. package/controllers/user/admin.js +0 -230
  182. package/controllers/user/api.js +0 -174
  183. package/controllers/user.js +0 -117
  184. package/controllers/users-permissions.js +0 -271
  185. package/middlewares/users-permissions/defaults.json +0 -5
  186. package/middlewares/users-permissions/index.js +0 -40
  187. package/models/Permission.js +0 -7
  188. package/models/Permission.settings.json +0 -45
  189. package/models/Role.js +0 -7
  190. package/models/Role.settings.json +0 -43
  191. package/models/User.js +0 -7
  192. package/models/User.settings.json +0 -63
  193. package/services/jwt.js +0 -65
  194. package/services/providers.js +0 -598
  195. package/services/users-permissions.js +0 -429
  196. package/utils/index.js +0 -11
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ const _ = require('lodash');
4
+ const { ApplicationError, ValidationError } = require('@strapi/utils').errors;
5
+ const { getService } = require('../utils');
6
+ const { validateDeleteRoleBody } = require('./validation/user');
7
+
8
+ module.exports = {
9
+ /**
10
+ * Default action.
11
+ *
12
+ * @return {Object}
13
+ */
14
+ async createRole(ctx) {
15
+ if (_.isEmpty(ctx.request.body)) {
16
+ throw new ValidationError('Request body cannot be empty');
17
+ }
18
+
19
+ await getService('role').createRole(ctx.request.body);
20
+
21
+ ctx.send({ ok: true });
22
+ },
23
+
24
+ async getRole(ctx) {
25
+ const { id } = ctx.params;
26
+
27
+ const role = await getService('role').getRole(id);
28
+
29
+ if (!role) {
30
+ return ctx.notFound();
31
+ }
32
+
33
+ ctx.send({ role });
34
+ },
35
+
36
+ async getRoles(ctx) {
37
+ const roles = await getService('role').getRoles();
38
+
39
+ ctx.send({ roles });
40
+ },
41
+
42
+ async updateRole(ctx) {
43
+ const roleID = ctx.params.role;
44
+
45
+ if (_.isEmpty(ctx.request.body)) {
46
+ throw new ValidationError('Request body cannot be empty');
47
+ }
48
+
49
+ await getService('role').updateRole(roleID, ctx.request.body);
50
+
51
+ ctx.send({ ok: true });
52
+ },
53
+
54
+ async deleteRole(ctx) {
55
+ const roleID = ctx.params.role;
56
+
57
+ if (!roleID) {
58
+ await validateDeleteRoleBody(ctx.params);
59
+ }
60
+
61
+ // Fetch public role.
62
+ const publicRole = await strapi
63
+ .query('plugin::users-permissions.role')
64
+ .findOne({ where: { type: 'public' } });
65
+
66
+ const publicRoleID = publicRole.id;
67
+
68
+ // Prevent from removing the public role.
69
+ if (roleID.toString() === publicRoleID.toString()) {
70
+ throw new ApplicationError('Cannot delete public role');
71
+ }
72
+
73
+ await getService('role').deleteRole(roleID, publicRoleID);
74
+
75
+ ctx.send({ ok: true });
76
+ },
77
+ };
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ const _ = require('lodash');
4
+ const { ValidationError } = require('@strapi/utils').errors;
5
+ const { getService } = require('../utils');
6
+ const { isValidEmailTemplate } = require('./validation/email-template');
7
+
8
+ module.exports = {
9
+ async getEmailTemplate(ctx) {
10
+ ctx.send(await strapi.store({ type: 'plugin', name: 'users-permissions', key: 'email' }).get());
11
+ },
12
+
13
+ async updateEmailTemplate(ctx) {
14
+ if (_.isEmpty(ctx.request.body)) {
15
+ throw new ValidationError('Request body cannot be empty');
16
+ }
17
+
18
+ const emailTemplates = ctx.request.body['email-templates'];
19
+
20
+ for (let key in emailTemplates) {
21
+ const template = emailTemplates[key].options.message;
22
+
23
+ if (!isValidEmailTemplate(template)) {
24
+ throw new ValidationError('Invalid template');
25
+ }
26
+ }
27
+
28
+ await strapi
29
+ .store({ type: 'plugin', name: 'users-permissions', key: 'email' })
30
+ .set({ value: emailTemplates });
31
+
32
+ ctx.send({ ok: true });
33
+ },
34
+
35
+ async getAdvancedSettings(ctx) {
36
+ const settings = await strapi
37
+ .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' })
38
+ .get();
39
+
40
+ const roles = await getService('role').getRoles();
41
+
42
+ ctx.send({ settings, roles });
43
+ },
44
+
45
+ async updateAdvancedSettings(ctx) {
46
+ if (_.isEmpty(ctx.request.body)) {
47
+ throw new ValidationError('Request body cannot be empty');
48
+ }
49
+
50
+ await strapi
51
+ .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' })
52
+ .set({ value: ctx.request.body });
53
+
54
+ ctx.send({ ok: true });
55
+ },
56
+
57
+ async getProviders(ctx) {
58
+ const providers = await strapi
59
+ .store({ type: 'plugin', name: 'users-permissions', key: 'grant' })
60
+ .get();
61
+
62
+ for (const provider in providers) {
63
+ if (provider !== 'email') {
64
+ providers[provider].redirectUri = strapi
65
+ .plugin('users-permissions')
66
+ .service('providers')
67
+ .buildRedirectUri(provider);
68
+ }
69
+ }
70
+
71
+ ctx.send(providers);
72
+ },
73
+
74
+ async updateProviders(ctx) {
75
+ if (_.isEmpty(ctx.request.body)) {
76
+ throw new ValidationError('Request body cannot be empty');
77
+ }
78
+
79
+ await strapi
80
+ .store({ type: 'plugin', name: 'users-permissions', key: 'grant' })
81
+ .set({ value: ctx.request.body.providers });
82
+
83
+ ctx.send({ ok: true });
84
+ },
85
+ };
@@ -0,0 +1,191 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * User.js controller
5
+ *
6
+ * @description: A set of functions called "actions" for managing `User`.
7
+ */
8
+
9
+ const _ = require('lodash');
10
+ const utils = require('@strapi/utils');
11
+ const { getService } = require('../utils');
12
+ const { validateCreateUserBody, validateUpdateUserBody } = require('./validation/user');
13
+
14
+ const { sanitize } = utils;
15
+ const { ApplicationError, ValidationError } = utils.errors;
16
+
17
+ const sanitizeOutput = (user, ctx) => {
18
+ const schema = strapi.getModel('plugin::users-permissions.user');
19
+ const { auth } = ctx.state;
20
+
21
+ return sanitize.contentAPI.output(user, schema, { auth });
22
+ };
23
+
24
+ module.exports = {
25
+ /**
26
+ * Create a/an user record.
27
+ * @return {Object}
28
+ */
29
+ async create(ctx) {
30
+ const advanced = await strapi
31
+ .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' })
32
+ .get();
33
+
34
+ await validateCreateUserBody(ctx.request.body);
35
+
36
+ const { email, username, role } = ctx.request.body;
37
+
38
+ const userWithSameUsername = await strapi
39
+ .query('plugin::users-permissions.user')
40
+ .findOne({ where: { username } });
41
+
42
+ if (userWithSameUsername) {
43
+ if (!email) throw new ApplicationError('Username already taken');
44
+ }
45
+
46
+ if (advanced.unique_email) {
47
+ const userWithSameEmail = await strapi
48
+ .query('plugin::users-permissions.user')
49
+ .findOne({ where: { email: email.toLowerCase() } });
50
+
51
+ if (userWithSameEmail) {
52
+ throw new ApplicationError('Email already taken');
53
+ }
54
+ }
55
+
56
+ const user = {
57
+ ...ctx.request.body,
58
+ provider: 'local',
59
+ };
60
+
61
+ user.email = _.toLower(user.email);
62
+
63
+ if (!role) {
64
+ const defaultRole = await strapi
65
+ .query('plugin::users-permissions.role')
66
+ .findOne({ where: { type: advanced.default_role } });
67
+
68
+ user.role = defaultRole.id;
69
+ }
70
+
71
+ try {
72
+ const data = await getService('user').add(user);
73
+ const sanitizedData = await sanitizeOutput(data, ctx);
74
+
75
+ ctx.created(sanitizedData);
76
+ } catch (error) {
77
+ throw new ApplicationError(error.message);
78
+ }
79
+ },
80
+
81
+ /**
82
+ * Update a/an user record.
83
+ * @return {Object}
84
+ */
85
+ async update(ctx) {
86
+ const advancedConfigs = await strapi
87
+ .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' })
88
+ .get();
89
+
90
+ const { id } = ctx.params;
91
+ const { email, username, password } = ctx.request.body;
92
+
93
+ const user = await getService('user').fetch({ id });
94
+
95
+ await validateUpdateUserBody(ctx.request.body);
96
+
97
+ if (user.provider === 'local' && _.has(ctx.request.body, 'password') && !password) {
98
+ throw new ValidationError('password.notNull');
99
+ }
100
+
101
+ if (_.has(ctx.request.body, 'username')) {
102
+ const userWithSameUsername = await strapi
103
+ .query('plugin::users-permissions.user')
104
+ .findOne({ where: { username } });
105
+
106
+ if (userWithSameUsername && userWithSameUsername.id != id) {
107
+ throw new ApplicationError('Username already taken');
108
+ }
109
+ }
110
+
111
+ if (_.has(ctx.request.body, 'email') && advancedConfigs.unique_email) {
112
+ const userWithSameEmail = await strapi
113
+ .query('plugin::users-permissions.user')
114
+ .findOne({ where: { email: email.toLowerCase() } });
115
+
116
+ if (userWithSameEmail && userWithSameEmail.id != id) {
117
+ throw new ApplicationError('Email already taken');
118
+ }
119
+ ctx.request.body.email = ctx.request.body.email.toLowerCase();
120
+ }
121
+
122
+ let updateData = {
123
+ ...ctx.request.body,
124
+ };
125
+
126
+ const data = await getService('user').edit({ id }, updateData);
127
+ const sanitizedData = await sanitizeOutput(data, ctx);
128
+
129
+ ctx.send(sanitizedData);
130
+ },
131
+
132
+ /**
133
+ * Retrieve user records.
134
+ * @return {Object|Array}
135
+ */
136
+ async find(ctx, next, { populate } = {}) {
137
+ const users = await getService('user').fetchAll(ctx.query, populate);
138
+
139
+ ctx.body = await Promise.all(users.map(user => sanitizeOutput(user, ctx)));
140
+ },
141
+
142
+ /**
143
+ * Retrieve a user record.
144
+ * @return {Object}
145
+ */
146
+ async findOne(ctx) {
147
+ const { id } = ctx.params;
148
+ let data = await getService('user').fetch({ id });
149
+
150
+ if (data) {
151
+ data = await sanitizeOutput(data, ctx);
152
+ }
153
+
154
+ ctx.body = data;
155
+ },
156
+
157
+ /**
158
+ * Retrieve user count.
159
+ * @return {Number}
160
+ */
161
+ async count(ctx) {
162
+ ctx.body = await getService('user').count(ctx.query);
163
+ },
164
+
165
+ /**
166
+ * Destroy a/an user record.
167
+ * @return {Object}
168
+ */
169
+ async destroy(ctx) {
170
+ const { id } = ctx.params;
171
+
172
+ const data = await getService('user').remove({ id });
173
+ const sanitizedUser = await sanitizeOutput(data, ctx);
174
+
175
+ ctx.send(sanitizedUser);
176
+ },
177
+
178
+ /**
179
+ * Retrieve authenticated user.
180
+ * @return {Object|Array}
181
+ */
182
+ async me(ctx) {
183
+ const user = ctx.state.user;
184
+
185
+ if (!user) {
186
+ return ctx.unauthorized();
187
+ }
188
+
189
+ ctx.body = await sanitizeOutput(user, ctx);
190
+ },
191
+ };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const { yup, validateYupSchema } = require('@strapi/utils');
4
+
5
+ const callbackBodySchema = yup.object().shape({
6
+ identifier: yup.string().required(),
7
+ password: yup.string().required(),
8
+ });
9
+
10
+ const registerBodySchema = yup.object().shape({
11
+ email: yup
12
+ .string()
13
+ .email()
14
+ .required(),
15
+ password: yup.string().required(),
16
+ });
17
+
18
+ const sendEmailConfirmationBodySchema = yup.object().shape({
19
+ email: yup
20
+ .string()
21
+ .email()
22
+ .required(),
23
+ });
24
+
25
+ module.exports = {
26
+ validateCallbackBody: validateYupSchema(callbackBodySchema),
27
+ validateRegisterBody: validateYupSchema(registerBodySchema),
28
+ validateSendEmailConfirmationBody: validateYupSchema(sendEmailConfirmationBodySchema),
29
+ };
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ const { yup, validateYupSchema } = require('@strapi/utils');
4
+
5
+ const deleteRoleSchema = yup.object().shape({
6
+ role: yup.strapiID().required(),
7
+ });
8
+
9
+ const createUserBodySchema = yup.object().shape({
10
+ email: yup
11
+ .string()
12
+ .email()
13
+ .required(),
14
+ username: yup
15
+ .string()
16
+ .min(1)
17
+ .required(),
18
+ password: yup
19
+ .string()
20
+ .min(1)
21
+ .required(),
22
+ role: yup.strapiID(),
23
+ });
24
+
25
+ const updateUserBodySchema = yup.object().shape({
26
+ email: yup
27
+ .string()
28
+ .email()
29
+ .min(1),
30
+ username: yup.string().min(1),
31
+ password: yup.string().min(1),
32
+ });
33
+
34
+ module.exports = {
35
+ validateCreateUserBody: validateYupSchema(createUserBodySchema),
36
+ validateUpdateUserBody: validateYupSchema(updateUserBodySchema),
37
+ validateDeleteRoleBody: validateYupSchema(deleteRoleSchema),
38
+ };
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ const getTypes = require('./types');
4
+ const getQueries = require('./queries');
5
+ const getMutations = require('./mutations');
6
+ const getResolversConfig = require('./resolvers-configs');
7
+
8
+ module.exports = ({ strapi }) => {
9
+ const { config: graphQLConfig } = strapi.plugin('graphql');
10
+ const extensionService = strapi.plugin('graphql').service('extension');
11
+
12
+ const isShadowCRUDEnabled = graphQLConfig('shadowCRUD', true);
13
+
14
+ if (!isShadowCRUDEnabled) {
15
+ return;
16
+ }
17
+
18
+ // Disable Permissions queries & mutations but allow the
19
+ // type to be used/selected in filters or nested resolvers
20
+ extensionService
21
+ .shadowCRUD('plugin::users-permissions.permission')
22
+ .disableQueries()
23
+ .disableMutations();
24
+
25
+ // Disable User & Role's Create/Update/Delete actions so they can be replaced
26
+ const actionsToDisable = ['create', 'update', 'delete'];
27
+
28
+ extensionService.shadowCRUD('plugin::users-permissions.user').disableActions(actionsToDisable);
29
+ extensionService.shadowCRUD('plugin::users-permissions.role').disableActions(actionsToDisable);
30
+
31
+ // Register new types & resolvers config
32
+ extensionService.use(({ nexus }) => {
33
+ const types = getTypes({ strapi, nexus });
34
+ const queries = getQueries({ strapi, nexus });
35
+ const mutations = getMutations({ strapi, nexus });
36
+ const resolversConfig = getResolversConfig({ strapi });
37
+
38
+ return {
39
+ types: [types, queries, mutations],
40
+
41
+ resolversConfig,
42
+ };
43
+ });
44
+ };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ const { toPlainObject } = require('lodash/fp');
4
+
5
+ const { checkBadRequest } = require('../../utils');
6
+
7
+ module.exports = ({ nexus, strapi }) => {
8
+ const { nonNull } = nexus;
9
+
10
+ return {
11
+ type: 'UsersPermissionsLoginPayload',
12
+
13
+ args: {
14
+ confirmation: nonNull('String'),
15
+ },
16
+
17
+ description: 'Confirm an email users email address',
18
+
19
+ async resolve(parent, args, context) {
20
+ const { koaContext } = context;
21
+
22
+ koaContext.request.body = toPlainObject(args);
23
+
24
+ await strapi
25
+ .plugin('users-permissions')
26
+ .controller('auth')
27
+ .emailConfirmation(koaContext, null, true);
28
+
29
+ const output = koaContext.body;
30
+
31
+ checkBadRequest(output);
32
+
33
+ return {
34
+ user: output.user || output,
35
+ jwt: output.jwt,
36
+ };
37
+ },
38
+ };
39
+ };
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ const { toPlainObject } = require('lodash/fp');
4
+
5
+ const { checkBadRequest } = require('../../utils');
6
+
7
+ module.exports = ({ nexus, strapi }) => {
8
+ const { nonNull } = nexus;
9
+
10
+ return {
11
+ type: 'UsersPermissionsPasswordPayload',
12
+
13
+ args: {
14
+ email: nonNull('String'),
15
+ },
16
+
17
+ description: 'Request a reset password token',
18
+
19
+ async resolve(parent, args, context) {
20
+ const { koaContext } = context;
21
+
22
+ koaContext.request.body = toPlainObject(args);
23
+
24
+ await strapi
25
+ .plugin('users-permissions')
26
+ .controller('auth')
27
+ .forgotPassword(koaContext);
28
+
29
+ const output = koaContext.body;
30
+
31
+ checkBadRequest(output);
32
+
33
+ return {
34
+ ok: output.ok || output,
35
+ };
36
+ },
37
+ };
38
+ };
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ const { toPlainObject } = require('lodash/fp');
4
+
5
+ const { checkBadRequest } = require('../../utils');
6
+
7
+ module.exports = ({ nexus, strapi }) => {
8
+ const { nonNull } = nexus;
9
+
10
+ return {
11
+ type: nonNull('UsersPermissionsLoginPayload'),
12
+
13
+ args: {
14
+ input: nonNull('UsersPermissionsLoginInput'),
15
+ },
16
+
17
+ async resolve(parent, args, context) {
18
+ const { koaContext } = context;
19
+
20
+ koaContext.params = { provider: args.input.provider };
21
+ koaContext.request.body = toPlainObject(args.input);
22
+
23
+ await strapi
24
+ .plugin('users-permissions')
25
+ .controller('auth')
26
+ .callback(koaContext);
27
+
28
+ const output = koaContext.body;
29
+
30
+ checkBadRequest(output);
31
+
32
+ return {
33
+ user: output.user || output,
34
+ jwt: output.jwt,
35
+ };
36
+ },
37
+ };
38
+ };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ const { toPlainObject } = require('lodash/fp');
4
+
5
+ const { checkBadRequest } = require('../../utils');
6
+
7
+ module.exports = ({ nexus, strapi }) => {
8
+ const { nonNull } = nexus;
9
+
10
+ return {
11
+ type: nonNull('UsersPermissionsLoginPayload'),
12
+
13
+ args: {
14
+ input: nonNull('UsersPermissionsRegisterInput'),
15
+ },
16
+
17
+ description: 'Register a user',
18
+
19
+ async resolve(parent, args, context) {
20
+ const { koaContext } = context;
21
+
22
+ koaContext.request.body = toPlainObject(args.input);
23
+
24
+ await strapi
25
+ .plugin('users-permissions')
26
+ .controller('auth')
27
+ .register(koaContext);
28
+
29
+ const output = koaContext.body;
30
+
31
+ checkBadRequest(output);
32
+
33
+ return {
34
+ user: output.user || output,
35
+ jwt: output.jwt,
36
+ };
37
+ },
38
+ };
39
+ };
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ const { toPlainObject } = require('lodash/fp');
4
+
5
+ const { checkBadRequest } = require('../../utils');
6
+
7
+ module.exports = ({ nexus, strapi }) => {
8
+ const { nonNull } = nexus;
9
+
10
+ return {
11
+ type: 'UsersPermissionsLoginPayload',
12
+
13
+ args: {
14
+ password: nonNull('String'),
15
+ passwordConfirmation: nonNull('String'),
16
+ code: nonNull('String'),
17
+ },
18
+
19
+ description: 'Reset user password. Confirm with a code (resetToken from forgotPassword)',
20
+
21
+ async resolve(parent, args, context) {
22
+ const { koaContext } = context;
23
+
24
+ koaContext.request.body = toPlainObject(args);
25
+
26
+ await strapi
27
+ .plugin('users-permissions')
28
+ .controller('auth')
29
+ .forgotPassword(koaContext);
30
+
31
+ const output = koaContext.body;
32
+
33
+ checkBadRequest(output);
34
+
35
+ return {
36
+ user: output.user || output,
37
+ jwt: output.jwt,
38
+ };
39
+ },
40
+ };
41
+ };
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ const { toPlainObject } = require('lodash/fp');
4
+
5
+ const usersPermissionsRoleUID = 'plugin::users-permissions.role';
6
+
7
+ module.exports = ({ nexus, strapi }) => {
8
+ const { getContentTypeInputName } = strapi.plugin('graphql').service('utils').naming;
9
+ const { nonNull } = nexus;
10
+
11
+ const roleContentType = strapi.getModel(usersPermissionsRoleUID);
12
+
13
+ const roleInputName = getContentTypeInputName(roleContentType);
14
+
15
+ return {
16
+ type: 'UsersPermissionsCreateRolePayload',
17
+
18
+ args: {
19
+ data: nonNull(roleInputName),
20
+ },
21
+
22
+ description: 'Create a new role',
23
+
24
+ async resolve(parent, args, context) {
25
+ const { koaContext } = context;
26
+
27
+ koaContext.request.body = toPlainObject(args.data);
28
+
29
+ await strapi
30
+ .plugin('users-permissions')
31
+ .controller('role')
32
+ .createRole(koaContext);
33
+
34
+ return { ok: true };
35
+ },
36
+ };
37
+ };