- |
-
- |
-
- |
-
---|---|---|
- |
-
- |
-
- |
-
- |
-
- |
-
- |
-
- |
-
- |
-
- |
-
---|---|---|
- |
-
- |
-
- {canUpdate && (
- |
-
- |
-
- |
-
- |
-
- |
-
---|
We heard that you lost your password. Sorry about that!
- -But don’t worry! You can use the following link to reset your password:
-<%= URL %>?code=<%= TOKEN %>
- -Thanks.
`, - }, - }, - email_confirmation: { - display: 'Email.template.email_confirmation', - icon: 'check-square', - options: { - from: { - name: 'Administration Panel', - email: 'no-reply@strapi.io', - }, - response_email: '', - object: 'Account confirmation', - message: `Thank you for registering!
- -You have to confirm your email address. Please click on the link below.
- -<%= URL %>?confirmation=<%= CODE %>
- -Thanks.
`, - }, - }, - }; - - await pluginStore.set({ key: 'email', value }); - } -}; - -const initAdvancedOptions = async (pluginStore) => { - if (!(await pluginStore.get({ key: 'advanced' }))) { - const value = { - unique_email: true, - allow_register: true, - email_confirmation: false, - email_reset_password: null, - email_confirmation_redirection: null, - default_role: 'authenticated', - }; - - await pluginStore.set({ key: 'advanced', value }); - } -}; - -module.exports = async ({ strapi }) => { - const pluginStore = strapi.store({ type: 'plugin', name: 'users-permissions' }); - - await initGrant(pluginStore); - await initEmails(pluginStore); - await initAdvancedOptions(pluginStore); - - await strapi.admin.services.permission.actionProvider.registerMany( - usersPermissionsActions.actions - ); - - await getService('users-permissions').initialize(); - - if (!strapi.config.get('plugin.users-permissions.jwtSecret')) { - if (process.env.NODE_ENV !== 'development') { - throw new Error( - `Missing jwtSecret. Please, set configuration variable "jwtSecret" for the users-permissions plugin in config/plugins.js (ex: you can generate one using Node with \`crypto.randomBytes(16).toString('base64')\`). -For security reasons, prefer storing the secret in an environment variable and read it in config/plugins.js. See https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/optional/environment.html#configuration-using-environment-variables.` - ); - } - - const jwtSecret = crypto.randomBytes(16).toString('base64'); - - strapi.config.set('plugin.users-permissions.jwtSecret', jwtSecret); - - if (!process.env.JWT_SECRET) { - const envPath = process.env.ENV_PATH || '.env'; - strapi.fs.appendFile(envPath, `JWT_SECRET=${jwtSecret}\n`); - strapi.log.info( - `The Users & Permissions plugin automatically generated a jwt secret and stored it in ${envPath} under the name JWT_SECRET.` - ); - } - } -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/bootstrap/users-permissions-actions.js b/packages/strapi/src/extensions/users-permissions/server/bootstrap/users-permissions-actions.js deleted file mode 100644 index f017103..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/bootstrap/users-permissions-actions.js +++ /dev/null @@ -1,80 +0,0 @@ -'use strict'; - -module.exports = { - actions: [ - { - // Roles - section: 'plugins', - displayName: 'Create', - uid: 'roles.create', - subCategory: 'roles', - pluginName: 'users-permissions', - }, - { - section: 'plugins', - displayName: 'Read', - uid: 'roles.read', - subCategory: 'roles', - pluginName: 'users-permissions', - }, - { - section: 'plugins', - displayName: 'Update', - uid: 'roles.update', - subCategory: 'roles', - pluginName: 'users-permissions', - }, - { - section: 'plugins', - displayName: 'Delete', - uid: 'roles.delete', - subCategory: 'roles', - pluginName: 'users-permissions', - }, - { - // providers - section: 'plugins', - displayName: 'Read', - uid: 'providers.read', - subCategory: 'providers', - pluginName: 'users-permissions', - }, - { - section: 'plugins', - displayName: 'Edit', - uid: 'providers.update', - subCategory: 'providers', - pluginName: 'users-permissions', - }, - { - // emailTemplates - section: 'plugins', - displayName: 'Read', - uid: 'email-templates.read', - subCategory: 'emailTemplates', - pluginName: 'users-permissions', - }, - { - section: 'plugins', - displayName: 'Edit', - uid: 'email-templates.update', - subCategory: 'emailTemplates', - pluginName: 'users-permissions', - }, - { - // advancedSettings - section: 'plugins', - displayName: 'Read', - uid: 'advanced-settings.read', - subCategory: 'advancedSettings', - pluginName: 'users-permissions', - }, - { - section: 'plugins', - displayName: 'Edit', - uid: 'advanced-settings.update', - subCategory: 'advancedSettings', - pluginName: 'users-permissions', - }, - ], -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/config.js b/packages/strapi/src/extensions/users-permissions/server/config.js deleted file mode 100644 index 05b16a8..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/config.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict'; - -module.exports = { - default: ({ env }) => ({ - jwtSecret: env('JWT_SECRET'), - jwt: { - expiresIn: '30d', - }, - ratelimit: { - interval: 60000, - max: 10, - }, - layout: { - user: { - actions: { - create: 'contentManagerUser.create', // Use the User plugin's controller. - update: 'contentManagerUser.update', - }, - }, - }, - }), - validator() {}, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/content-types/index.js b/packages/strapi/src/extensions/users-permissions/server/content-types/index.js deleted file mode 100644 index 8476e7d..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/content-types/index.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -const permission = require('./permission'); -const role = require('./role'); -const user = require('./user'); - -module.exports = { - permission: { schema: permission }, - role: { schema: role }, - user: { schema: user }, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/content-types/permission/index.js b/packages/strapi/src/extensions/users-permissions/server/content-types/permission/index.js deleted file mode 100644 index 70648c8..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/content-types/permission/index.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -module.exports = { - collectionName: 'up_permissions', - info: { - name: 'permission', - description: '', - singularName: 'permission', - pluralName: 'permissions', - displayName: 'Permission', - }, - pluginOptions: { - 'content-manager': { - visible: false, - }, - 'content-type-builder': { - visible: false, - }, - }, - attributes: { - action: { - type: 'string', - required: true, - configurable: false, - }, - role: { - type: 'relation', - relation: 'manyToOne', - target: 'plugin::users-permissions.role', - inversedBy: 'permissions', - configurable: false, - }, - }, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/content-types/role/index.js b/packages/strapi/src/extensions/users-permissions/server/content-types/role/index.js deleted file mode 100644 index ceb45c6..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/content-types/role/index.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; - -module.exports = { - collectionName: 'up_roles', - info: { - name: 'role', - description: '', - singularName: 'role', - pluralName: 'roles', - displayName: 'Role', - }, - pluginOptions: { - 'content-manager': { - visible: false, - }, - 'content-type-builder': { - visible: false, - }, - }, - attributes: { - name: { - type: 'string', - minLength: 3, - required: true, - configurable: false, - }, - description: { - type: 'string', - configurable: false, - }, - type: { - type: 'string', - unique: true, - configurable: false, - }, - permissions: { - type: 'relation', - relation: 'oneToMany', - target: 'plugin::users-permissions.permission', - mappedBy: 'role', - configurable: false, - }, - users: { - type: 'relation', - relation: 'oneToMany', - target: 'plugin::users-permissions.user', - mappedBy: 'role', - configurable: false, - }, - }, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/content-types/user/index.js b/packages/strapi/src/extensions/users-permissions/server/content-types/user/index.js deleted file mode 100644 index d999d98..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/content-types/user/index.js +++ /dev/null @@ -1,75 +0,0 @@ -'use strict'; - -const schemaConfig = require('./schema-config'); - -module.exports = { - collectionName: 'up_users', - info: { - name: 'user', - description: '', - singularName: 'user', - pluralName: 'users', - displayName: 'User', - }, - options: { - draftAndPublish: false, - timestamps: true, - }, - attributes: { - username: { - type: 'string', - minLength: 3, - unique: true, - configurable: false, - required: true, - }, - email: { - type: 'email', - minLength: 6, - configurable: false, - required: true, - }, - provider: { - type: 'string', - configurable: false, - }, - password: { - type: 'password', - minLength: 6, - configurable: false, - private: true, - searchable: false, - }, - resetPasswordToken: { - type: 'string', - configurable: false, - private: true, - searchable: false, - }, - confirmationToken: { - type: 'string', - configurable: false, - private: true, - searchable: false, - }, - confirmed: { - type: 'boolean', - default: false, - configurable: false, - }, - blocked: { - type: 'boolean', - default: false, - configurable: false, - }, - role: { - type: 'relation', - relation: 'manyToOne', - target: 'plugin::users-permissions.role', - inversedBy: 'users', - configurable: false, - }, - }, - - config: schemaConfig, // TODO: to move to content-manager options -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/content-types/user/schema-config.js b/packages/strapi/src/extensions/users-permissions/server/content-types/user/schema-config.js deleted file mode 100644 index 7442cd1..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/content-types/user/schema-config.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -module.exports = { - attributes: { - resetPasswordToken: { - hidden: true, - }, - confirmationToken: { - hidden: true, - }, - provider: { - hidden: true, - }, - }, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/controllers/auth.js b/packages/strapi/src/extensions/users-permissions/server/controllers/auth.js deleted file mode 100644 index 02821f7..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/controllers/auth.js +++ /dev/null @@ -1,416 +0,0 @@ -'use strict'; - -/** - * Auth.js controller - * - * @description: A set of functions called "actions" for managing `Auth`. - */ - -/* eslint-disable no-useless-escape */ -const crypto = require('crypto'); -const _ = require('lodash'); -const utils = require('@strapi/utils'); -const { getService } = require('../utils'); -const { - validateCallbackBody, - validateRegisterBody, - validateSendEmailConfirmationBody, - validateForgotPasswordBody, - validateResetPasswordBody, - validateEmailConfirmationBody, - validateChangePasswordBody, -} = require('./validation/auth'); - -const { getAbsoluteAdminUrl, getAbsoluteServerUrl, sanitize } = utils; -const { ApplicationError, ValidationError } = utils.errors; - -const sanitizeUser = (user, ctx) => { - const { auth } = ctx.state; - const userSchema = strapi.getModel('plugin::users-permissions.user'); - - return sanitize.contentAPI.output(user, userSchema, { auth }); -}; - -module.exports = { - async callback(ctx) { - const provider = ctx.params.provider || 'local'; - const params = ctx.request.body; - - const store = strapi.store({ type: 'plugin', name: 'users-permissions' }); - const grantSettings = await store.get({ key: 'grant' }); - - const grantProvider = provider === 'local' ? 'email' : provider; - - if (!_.get(grantSettings, [grantProvider, 'enabled'])) { - throw new ApplicationError('This provider is disabled'); - } - - if (provider === 'local') { - await validateCallbackBody(params); - - const { identifier } = params; - - // Check if the user exists. - const user = await strapi.query('plugin::users-permissions.user').findOne({ - where: { - provider, - $or: [{ email: identifier.toLowerCase() }, { username: identifier }], - }, - }); - - if (!user) { - throw new ValidationError('Invalid identifier or password'); - } - - if (!user.password) { - throw new ValidationError('Invalid identifier or password'); - } - - const validPassword = await getService('user').validatePassword( - params.password, - user.password - ); - - if (!validPassword) { - throw new ValidationError('Invalid identifier or password'); - } - - const advancedSettings = await store.get({ key: 'advanced' }); - const requiresConfirmation = _.get(advancedSettings, 'email_confirmation'); - - if (requiresConfirmation && user.confirmed !== true) { - throw new ApplicationError('Your account email is not confirmed'); - } - - if (user.blocked === true) { - throw new ApplicationError('Your account has been blocked by an administrator'); - } - - return ctx.send({ - jwt: getService('jwt').issue({ id: user.id }), - user: await sanitizeUser(user, ctx), - }); - } - - // Connect the user with the third-party provider. - try { - const user = await getService('providers').connect(provider, ctx.query); - - return ctx.send({ - jwt: getService('jwt').issue({ id: user.id }), - user: await sanitizeUser(user, ctx), - }); - } catch (error) { - throw new ApplicationError(error.message); - } - }, - - async changePassword(ctx) { - if (!ctx.state.user) { - throw new ApplicationError('You must be authenticated to reset your password'); - } - - const { currentPassword, password } = await validateChangePasswordBody(ctx.request.body); - - const user = await strapi.entityService.findOne( - 'plugin::users-permissions.user', - ctx.state.user.id - ); - - const validPassword = await getService('user').validatePassword(currentPassword, user.password); - - if (!validPassword) { - throw new ValidationError('The provided current password is invalid'); - } - - if (currentPassword === password) { - throw new ValidationError('Your new password must be different than your current password'); - } - - await getService('user').edit(user.id, { password }); - - ctx.send({ - jwt: getService('jwt').issue({ id: user.id }), - user: await sanitizeUser(user, ctx), - }); - }, - - async resetPassword(ctx) { - const { password, passwordConfirmation, code } = await validateResetPasswordBody( - ctx.request.body - ); - - if (password !== passwordConfirmation) { - throw new ValidationError('Passwords do not match'); - } - - const user = await strapi - .query('plugin::users-permissions.user') - .findOne({ where: { resetPasswordToken: code } }); - - if (!user) { - throw new ValidationError('Incorrect code provided'); - } - - await getService('user').edit(user.id, { - resetPasswordToken: null, - password, - }); - - // Update the user. - ctx.send({ - jwt: getService('jwt').issue({ id: user.id }), - user: await sanitizeUser(user, ctx), - }); - }, - - async connect(ctx, next) { - const grant = require('grant-koa'); - - const providers = await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'grant' }) - .get(); - - const apiPrefix = strapi.config.get('api.rest.prefix'); - const grantConfig = { - defaults: { - prefix: `${apiPrefix}/connect`, - }, - ...providers, - }; - - const [requestPath] = ctx.request.url.split('?'); - const provider = requestPath.split('/connect/')[1].split('/')[0]; - - if (!_.get(grantConfig[provider], 'enabled')) { - throw new ApplicationError('This provider is disabled'); - } - - if (!strapi.config.server.url.startsWith('http')) { - strapi.log.warn( - 'You are using a third party provider for login. Make sure to set an absolute url in config/server.js. More info here: https://docs.strapi.io/developer-docs/latest/plugins/users-permissions.html#setting-up-the-server-url' - ); - } - - // Ability to pass OAuth callback dynamically - grantConfig[provider].callback = - _.get(ctx, 'query.callback') || - _.get(ctx, 'session.grant.dynamic.callback') || - grantConfig[provider].callback; - grantConfig[provider].redirect_uri = getService('providers').buildRedirectUri(provider); - - return grant(grantConfig)(ctx, next); - }, - - async forgotPassword(ctx) { - const { email } = await validateForgotPasswordBody(ctx.request.body); - - const pluginStore = await strapi.store({ type: 'plugin', name: 'users-permissions' }); - - const emailSettings = await pluginStore.get({ key: 'email' }); - const advancedSettings = await pluginStore.get({ key: 'advanced' }); - - // Find the user by email. - const user = await strapi - .query('plugin::users-permissions.user') - .findOne({ where: { email: email.toLowerCase() } }); - - if (!user || user.blocked) { - return ctx.send({ ok: true }); - } - - // Generate random token. - const userInfo = await sanitizeUser(user, ctx); - - const resetPasswordToken = crypto.randomBytes(64).toString('hex'); - - const resetPasswordSettings = _.get(emailSettings, 'reset_password.options', {}); - const emailBody = await getService('users-permissions').template( - resetPasswordSettings.message, - { - URL: advancedSettings.email_reset_password, - SERVER_URL: getAbsoluteServerUrl(strapi.config), - ADMIN_URL: getAbsoluteAdminUrl(strapi.config), - USER: userInfo, - TOKEN: resetPasswordToken, - } - ); - - const emailObject = await getService('users-permissions').template( - resetPasswordSettings.object, - { - USER: userInfo, - } - ); - - const emailToSend = { - to: user.email, - from: - resetPasswordSettings.from.email || resetPasswordSettings.from.name - ? `${resetPasswordSettings.from.name} <${resetPasswordSettings.from.email}>` - : undefined, - replyTo: resetPasswordSettings.response_email, - subject: emailObject, - text: emailBody, - html: emailBody, - }; - - // NOTE: Update the user before sending the email so an Admin can generate the link if the email fails - await getService('user').edit(user.id, { resetPasswordToken }); - - // Send an email to the user. - await strapi.plugin('email').service('email').send(emailToSend); - - ctx.send({ ok: true }); - }, - - async register(ctx) { - const pluginStore = await strapi.store({ type: 'plugin', name: 'users-permissions' }); - - const settings = await pluginStore.get({ key: 'advanced' }); - - if (!settings.allow_register) { - throw new ApplicationError('Register action is currently disabled'); - } - - const params = { - ..._.omit(ctx.request.body, [ - 'confirmed', - 'blocked', - 'confirmationToken', - 'resetPasswordToken', - 'provider', - 'id', - 'createdAt', - 'updatedAt', - 'createdBy', - 'updatedBy', - 'role', - ]), - provider: 'local', - }; - - await validateRegisterBody(params); - - const role = await strapi - .query('plugin::users-permissions.role') - .findOne({ where: { type: settings.default_role } }); - - if (!role) { - throw new ApplicationError('Impossible to find the default role'); - } - - const { email, username, provider } = params; - - const identifierFilter = { - $or: [ - { email: email.toLowerCase() }, - { username: email.toLowerCase() }, - { username }, - { email: username }, - ], - }; - - const conflictingUserCount = await strapi.query('plugin::users-permissions.user').count({ - where: { ...identifierFilter, provider }, - }); - - if (conflictingUserCount > 0) { - throw new ApplicationError('Email or Username are already taken'); - } - - if (settings.unique_email) { - const conflictingUserCount = await strapi.query('plugin::users-permissions.user').count({ - where: { ...identifierFilter }, - }); - - if (conflictingUserCount > 0) { - throw new ApplicationError('Email or Username are already taken'); - } - } - - const newUser = { - ...params, - role: role.id, - email: email.toLowerCase(), - username, - confirmed: !settings.email_confirmation, - }; - - const user = await getService('user').add(newUser); - - const sanitizedUser = await sanitizeUser(user, ctx); - - if (settings.email_confirmation) { - try { - await getService('user').sendConfirmationEmail(sanitizedUser); - } catch (err) { - throw new ApplicationError(err.message); - } - - return ctx.send({ user: sanitizedUser }); - } - - const jwt = getService('jwt').issue(_.pick(user, ['id'])); - - return ctx.send({ - jwt, - user: sanitizedUser, - }); - }, - - async emailConfirmation(ctx, next, returnUser) { - const { confirmation: confirmationToken } = await validateEmailConfirmationBody(ctx.query); - - const userService = getService('user'); - const jwtService = getService('jwt'); - - const [user] = await userService.fetchAll({ filters: { confirmationToken } }); - - if (!user) { - throw new ValidationError('Invalid token'); - } - - await userService.edit(user.id, { confirmed: true, confirmationToken: null }); - - if (returnUser) { - ctx.send({ - jwt: jwtService.issue({ id: user.id }), - user: await sanitizeUser(user, ctx), - }); - } else { - const settings = await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' }) - .get(); - - ctx.redirect(settings.email_confirmation_redirection || '/'); - } - }, - - async sendEmailConfirmation(ctx) { - const { email } = await validateSendEmailConfirmationBody(ctx.request.body); - - const user = await strapi.query('plugin::users-permissions.user').findOne({ - where: { email: email.toLowerCase() }, - }); - - if (!user) { - return ctx.send({ email, sent: true }); - } - - if (user.confirmed) { - throw new ApplicationError('Already confirmed'); - } - - if (user.blocked) { - throw new ApplicationError('User blocked'); - } - - await getService('user').sendConfirmationEmail(user); - - ctx.send({ - email: user.email, - sent: true, - }); - }, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/controllers/content-manager-user.js b/packages/strapi/src/extensions/users-permissions/server/controllers/content-manager-user.js deleted file mode 100644 index f003a2f..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/controllers/content-manager-user.js +++ /dev/null @@ -1,178 +0,0 @@ -'use strict'; - -const _ = require('lodash'); -const { contentTypes: contentTypesUtils } = require('@strapi/utils'); -const { ApplicationError, ValidationError, NotFoundError, ForbiddenError } = - require('@strapi/utils').errors; -const { validateCreateUserBody, validateUpdateUserBody } = require('./validation/user'); - -const { UPDATED_BY_ATTRIBUTE, CREATED_BY_ATTRIBUTE } = contentTypesUtils.constants; - -console.log(`>>>> Hey, it's me. Your sleep paralysis demon. I wanted to take this moment to console.log contentTypes in this content-manager-user.js file, because I'm having to debug this little shit of a program, Strapi js. (contentTypes is as follows)`) -console.log(contentTypes) - -const userModel = 'plugin::users-permissions.user'; -const ACTIONS = { - read: 'plugin::content-manager.explorer.read', - create: 'plugin::content-manager.explorer.create', - edit: 'plugin::content-manager.explorer.update', - delete: 'plugin::content-manager.explorer.delete', -}; - -const findEntityAndCheckPermissions = async (ability, action, model, id) => { - const entity = await strapi.query(userModel).findOne({ - where: { id }, - populate: [`${CREATED_BY_ATTRIBUTE}.roles`], - }); - - if (_.isNil(entity)) { - throw new NotFoundError(); - } - - const pm = strapi.admin.services.permission.createPermissionsManager({ ability, action, model }); - - if (pm.ability.cannot(pm.action, pm.toSubject(entity))) { - throw new ForbiddenError(); - } - - const entityWithoutCreatorRoles = _.omit(entity, `${CREATED_BY_ATTRIBUTE}.roles`); - - return { pm, entity: entityWithoutCreatorRoles }; -}; - -module.exports = { - /** - * Create a/an user record. - * @return {Object} - */ - async create(ctx) { - const { body } = ctx.request; - const { user: admin, userAbility } = ctx.state; - - const { email, username } = body; - - const pm = strapi.admin.services.permission.createPermissionsManager({ - ability: userAbility, - action: ACTIONS.create, - model: userModel, - }); - - if (!pm.isAllowed) { - return ctx.forbidden(); - } - - const sanitizedBody = await pm.pickPermittedFieldsOf(body, { subject: userModel }); - - const advanced = await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' }) - .get(); - - await validateCreateUserBody(ctx.request.body); - - const userWithSameUsername = await strapi - .query('plugin::users-permissions.user') - .findOne({ where: { username } }); - - if (userWithSameUsername) { - throw new ApplicationError('Username already taken'); - } - - if (advanced.unique_email) { - const userWithSameEmail = await strapi - .query('plugin::users-permissions.user') - .findOne({ where: { email: email.toLowerCase() } }); - - if (userWithSameEmail) { - throw new ApplicationError('Email already taken'); - } - } - - const user = { - ...sanitizedBody, - provider: 'local', - [CREATED_BY_ATTRIBUTE]: admin.id, - [UPDATED_BY_ATTRIBUTE]: admin.id, - }; - - user.email = _.toLower(user.email); - - if (!user.role) { - const defaultRole = await strapi - .query('plugin::users-permissions.role') - .findOne({ where: { type: advanced.default_role } }); - - user.role = defaultRole.id; - } - - try { - const data = await strapi - .service('plugin::content-manager.entity-manager') - .create(user, userModel); - const sanitizedData = await pm.sanitizeOutput(data, { action: ACTIONS.read }); - - ctx.created(sanitizedData); - } catch (error) { - throw new ApplicationError(error.message); - } - }, - /** - * Update a/an user record. - * @return {Object} - */ - - async update(ctx) { - const { id } = ctx.params; - const { body } = ctx.request; - const { user: admin, userAbility } = ctx.state; - - const advancedConfigs = await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' }) - .get(); - - const { email, username, password } = body; - - const { pm, entity } = await findEntityAndCheckPermissions( - userAbility, - ACTIONS.edit, - userModel, - id - ); - const user = entity; - - await validateUpdateUserBody(ctx.request.body); - - if (_.has(body, 'password') && !password && user.provider === 'local') { - throw new ValidationError('password.notNull'); - } - - if (_.has(body, 'username')) { - const userWithSameUsername = await strapi - .query('plugin::users-permissions.user') - .findOne({ where: { username } }); - - if (userWithSameUsername && _.toString(userWithSameUsername.id) !== _.toString(id)) { - throw new ApplicationError('Username already taken'); - } - } - - if (_.has(body, 'email') && advancedConfigs.unique_email) { - const userWithSameEmail = await strapi - .query('plugin::users-permissions.user') - .findOne({ where: { email: _.toLower(email) } }); - - if (userWithSameEmail && _.toString(userWithSameEmail.id) !== _.toString(id)) { - throw new ApplicationError('Email already taken'); - } - body.email = _.toLower(body.email); - } - - const sanitizedData = await pm.pickPermittedFieldsOf(body, { subject: pm.toSubject(user) }); - const updateData = _.omit({ ...sanitizedData, updatedBy: admin.id }, 'createdBy'); - - const data = await strapi - .service('plugin::content-manager.entity-manager') - .update({ id }, updateData, userModel); - - ctx.body = await pm.sanitizeOutput(data, { action: ACTIONS.read }); - }, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/controllers/index.js b/packages/strapi/src/extensions/users-permissions/server/controllers/index.js deleted file mode 100644 index 8a02508..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/controllers/index.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -const auth = require('./auth'); -const user = require('./user'); -const role = require('./role'); -const permissions = require('./permissions'); -const settings = require('./settings'); -const contentmanageruser = require('./content-manager-user'); - -module.exports = { - auth, - user, - role, - permissions, - settings, - contentmanageruser, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/controllers/permissions.js b/packages/strapi/src/extensions/users-permissions/server/controllers/permissions.js deleted file mode 100644 index 3213215..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/controllers/permissions.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -const _ = require('lodash'); -const { getService } = require('../utils'); - -module.exports = { - async getPermissions(ctx) { - const permissions = await getService('users-permissions').getActions(); - - ctx.send({ permissions }); - }, - - async getPolicies(ctx) { - const policies = _.keys(strapi.plugin('users-permissions').policies); - - ctx.send({ - policies: _.without(policies, 'permissions'), - }); - }, - - async getRoutes(ctx) { - const routes = await getService('users-permissions').getRoutes(); - - ctx.send({ routes }); - }, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/controllers/role.js b/packages/strapi/src/extensions/users-permissions/server/controllers/role.js deleted file mode 100644 index a31c86f..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/controllers/role.js +++ /dev/null @@ -1,77 +0,0 @@ -'use strict'; - -const _ = require('lodash'); -const { ApplicationError, ValidationError } = require('@strapi/utils').errors; -const { getService } = require('../utils'); -const { validateDeleteRoleBody } = require('./validation/user'); - -module.exports = { - /** - * Default action. - * - * @return {Object} - */ - async createRole(ctx) { - if (_.isEmpty(ctx.request.body)) { - throw new ValidationError('Request body cannot be empty'); - } - - await getService('role').createRole(ctx.request.body); - - ctx.send({ ok: true }); - }, - - async findOne(ctx) { - const { id } = ctx.params; - - const role = await getService('role').findOne(id); - - if (!role) { - return ctx.notFound(); - } - - ctx.send({ role }); - }, - - async find(ctx) { - const roles = await getService('role').find(); - - ctx.send({ roles }); - }, - - async updateRole(ctx) { - const roleID = ctx.params.role; - - if (_.isEmpty(ctx.request.body)) { - throw new ValidationError('Request body cannot be empty'); - } - - await getService('role').updateRole(roleID, ctx.request.body); - - ctx.send({ ok: true }); - }, - - async deleteRole(ctx) { - const roleID = ctx.params.role; - - if (!roleID) { - await validateDeleteRoleBody(ctx.params); - } - - // Fetch public role. - const publicRole = await strapi - .query('plugin::users-permissions.role') - .findOne({ where: { type: 'public' } }); - - const publicRoleID = publicRole.id; - - // Prevent from removing the public role. - if (roleID.toString() === publicRoleID.toString()) { - throw new ApplicationError('Cannot delete public role'); - } - - await getService('role').deleteRole(roleID, publicRoleID); - - ctx.send({ ok: true }); - }, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/controllers/settings.js b/packages/strapi/src/extensions/users-permissions/server/controllers/settings.js deleted file mode 100644 index 1ae8ab2..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/controllers/settings.js +++ /dev/null @@ -1,85 +0,0 @@ -'use strict'; - -const _ = require('lodash'); -const { ValidationError } = require('@strapi/utils').errors; -const { getService } = require('../utils'); -const { isValidEmailTemplate } = require('./validation/email-template'); - -module.exports = { - async getEmailTemplate(ctx) { - ctx.send(await strapi.store({ type: 'plugin', name: 'users-permissions', key: 'email' }).get()); - }, - - async updateEmailTemplate(ctx) { - if (_.isEmpty(ctx.request.body)) { - throw new ValidationError('Request body cannot be empty'); - } - - const emailTemplates = ctx.request.body['email-templates']; - - for (const key of Object.keys(emailTemplates)) { - const template = emailTemplates[key].options.message; - - if (!isValidEmailTemplate(template)) { - throw new ValidationError('Invalid template'); - } - } - - await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'email' }) - .set({ value: emailTemplates }); - - ctx.send({ ok: true }); - }, - - async getAdvancedSettings(ctx) { - const settings = await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' }) - .get(); - - const roles = await getService('role').find(); - - ctx.send({ settings, roles }); - }, - - async updateAdvancedSettings(ctx) { - if (_.isEmpty(ctx.request.body)) { - throw new ValidationError('Request body cannot be empty'); - } - - await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' }) - .set({ value: ctx.request.body }); - - ctx.send({ ok: true }); - }, - - async getProviders(ctx) { - const providers = await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'grant' }) - .get(); - - for (const provider in providers) { - if (provider !== 'email') { - providers[provider].redirectUri = strapi - .plugin('users-permissions') - .service('providers') - .buildRedirectUri(provider); - } - } - - ctx.send(providers); - }, - - async updateProviders(ctx) { - if (_.isEmpty(ctx.request.body)) { - throw new ValidationError('Request body cannot be empty'); - } - - await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'grant' }) - .set({ value: ctx.request.body.providers }); - - ctx.send({ ok: true }); - }, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/controllers/user.js b/packages/strapi/src/extensions/users-permissions/server/controllers/user.js deleted file mode 100644 index 1b45e05..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/controllers/user.js +++ /dev/null @@ -1,209 +0,0 @@ -'use strict'; - -/** - * User.js controller - * - * @description: A set of functions called "actions" for managing `User`. - */ - -const _ = require('lodash'); -const utils = require('@strapi/utils'); -const { getService } = require('../utils'); -const { validateCreateUserBody, validateUpdateUserBody } = require('./validation/user'); - -const { sanitize } = utils; -const { ApplicationError, ValidationError, NotFoundError } = utils.errors; - -const sanitizeOutput = async (user, ctx) => { - const schema = strapi.getModel('plugin::users-permissions.user'); - const { auth } = ctx.state; - - return sanitize.contentAPI.output(user, schema, { auth }); -}; - -const sanitizeQuery = async (query, ctx) => { - const schema = strapi.getModel('plugin::users-permissions.user'); - const { auth } = ctx.state; - - return sanitize.contentAPI.query(query, schema, { auth }); -}; - -module.exports = { - /** - * Create a/an user record. - * @return {Object} - */ - async create(ctx) { - const advanced = await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' }) - .get(); - - await validateCreateUserBody(ctx.request.body); - - const { email, username, role } = ctx.request.body; - - const userWithSameUsername = await strapi - .query('plugin::users-permissions.user') - .findOne({ where: { username } }); - - if (userWithSameUsername) { - if (!email) throw new ApplicationError('Username already taken'); - } - - if (advanced.unique_email) { - const userWithSameEmail = await strapi - .query('plugin::users-permissions.user') - .findOne({ where: { email: email.toLowerCase() } }); - - if (userWithSameEmail) { - throw new ApplicationError('Email already taken'); - } - } - - const user = { - ...ctx.request.body, - email: email.toLowerCase(), - provider: 'local', - }; - - if (!role) { - const defaultRole = await strapi - .query('plugin::users-permissions.role') - .findOne({ where: { type: advanced.default_role } }); - - user.role = defaultRole.id; - } - - try { - const data = await getService('user').add(user); - const sanitizedData = await sanitizeOutput(data, ctx); - - ctx.created(sanitizedData); - } catch (error) { - throw new ApplicationError(error.message); - } - }, - - /** - * Update a/an user record. - * @return {Object} - */ - async update(ctx) { - const advancedConfigs = await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' }) - .get(); - - const { id } = ctx.params; - const { email, username, password } = ctx.request.body; - - const user = await getService('user').fetch(id); - if (!user) { - throw new NotFoundError(`User not found`); - } - - await validateUpdateUserBody(ctx.request.body); - - if (user.provider === 'local' && _.has(ctx.request.body, 'password') && !password) { - throw new ValidationError('password.notNull'); - } - - if (_.has(ctx.request.body, 'username')) { - const userWithSameUsername = await strapi - .query('plugin::users-permissions.user') - .findOne({ where: { username } }); - - if (userWithSameUsername && _.toString(userWithSameUsername.id) !== _.toString(id)) { - throw new ApplicationError('Username already taken'); - } - } - - if (_.has(ctx.request.body, 'email') && advancedConfigs.unique_email) { - const userWithSameEmail = await strapi - .query('plugin::users-permissions.user') - .findOne({ where: { email: email.toLowerCase() } }); - - if (userWithSameEmail && _.toString(userWithSameEmail.id) !== _.toString(id)) { - throw new ApplicationError('Email already taken'); - } - ctx.request.body.email = ctx.request.body.email.toLowerCase(); - } - - const updateData = { - ...ctx.request.body, - }; - - const data = await getService('user').edit(user.id, updateData); - const sanitizedData = await sanitizeOutput(data, ctx); - - ctx.send(sanitizedData); - }, - - /** - * Retrieve user records. - * @return {Object|Array} - */ - async find(ctx) { - const sanitizedQuery = await sanitizeQuery(ctx.query, ctx); - const users = await getService('user').fetchAll(sanitizedQuery); - - ctx.body = await Promise.all(users.map((user) => sanitizeOutput(user, ctx))); - }, - - /** - * Retrieve a user record. - * @return {Object} - */ - async findOne(ctx) { - const { id } = ctx.params; - const sanitizedQuery = await sanitizeQuery(ctx.query, ctx); - - let data = await getService('user').fetch(id, sanitizedQuery); - - if (data) { - data = await sanitizeOutput(data, ctx); - } - - ctx.body = data; - }, - - /** - * Retrieve user count. - * @return {Number} - */ - async count(ctx) { - const sanitizedQuery = await sanitizeQuery(ctx.query, ctx); - - ctx.body = await getService('user').count(sanitizedQuery); - }, - - /** - * Destroy a/an user record. - * @return {Object} - */ - async destroy(ctx) { - const { id } = ctx.params; - - const data = await getService('user').remove({ id }); - const sanitizedUser = await sanitizeOutput(data, ctx); - - ctx.send(sanitizedUser); - }, - - /** - * Retrieve authenticated user. - * @return {Object|Array} - */ - async me(ctx) { - const authUser = ctx.state.user; - const { query } = ctx; - - if (!authUser) { - return ctx.unauthorized(); - } - - const sanitizedQuery = await sanitizeQuery(query, ctx); - const user = await getService('user').fetch(authUser.id, sanitizedQuery); - - ctx.body = await sanitizeOutput(user, ctx); - }, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/controllers/validation/auth.js b/packages/strapi/src/extensions/users-permissions/server/controllers/validation/auth.js deleted file mode 100644 index fdb4ac0..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/controllers/validation/auth.js +++ /dev/null @@ -1,57 +0,0 @@ -'use strict'; - -const { yup, validateYupSchema } = require('@strapi/utils'); - -const callbackSchema = yup.object({ - identifier: yup.string().required(), - password: yup.string().required(), -}); - -const registerSchema = yup.object({ - email: yup.string().email().required(), - username: yup.string().required(), - password: yup.string().required(), -}); - -const sendEmailConfirmationSchema = yup.object({ - email: yup.string().email().required(), -}); - -const validateEmailConfirmationSchema = yup.object({ - confirmation: yup.string().required(), -}); - -const forgotPasswordSchema = yup - .object({ - email: yup.string().email().required(), - }) - .noUnknown(); - -const resetPasswordSchema = yup - .object({ - password: yup.string().required(), - passwordConfirmation: yup.string().required(), - code: yup.string().required(), - }) - .noUnknown(); - -const changePasswordSchema = yup - .object({ - password: yup.string().required(), - passwordConfirmation: yup - .string() - .required() - .oneOf([yup.ref('password')], 'Passwords do not match'), - currentPassword: yup.string().required(), - }) - .noUnknown(); - -module.exports = { - validateCallbackBody: validateYupSchema(callbackSchema), - validateRegisterBody: validateYupSchema(registerSchema), - validateSendEmailConfirmationBody: validateYupSchema(sendEmailConfirmationSchema), - validateEmailConfirmationBody: validateYupSchema(validateEmailConfirmationSchema), - validateForgotPasswordBody: validateYupSchema(forgotPasswordSchema), - validateResetPasswordBody: validateYupSchema(resetPasswordSchema), - validateChangePasswordBody: validateYupSchema(changePasswordSchema), -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/controllers/validation/email-template.js b/packages/strapi/src/extensions/users-permissions/server/controllers/validation/email-template.js deleted file mode 100644 index 49b3f76..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/controllers/validation/email-template.js +++ /dev/null @@ -1,74 +0,0 @@ -'use strict'; - -const { trim } = require('lodash/fp'); -const { - template: { createLooseInterpolationRegExp, createStrictInterpolationRegExp }, -} = require('@strapi/utils'); - -const invalidPatternsRegexes = [ - // Ignore "evaluation" patterns: <% ... %> - /<%[^=]([\s\S]*?)%>/m, - // Ignore basic string interpolations - /\${([^{}]*)}/m, -]; - -const authorizedKeys = [ - 'URL', - 'ADMIN_URL', - 'SERVER_URL', - 'CODE', - 'USER', - 'USER.email', - 'USER.username', - 'TOKEN', -]; - -const matchAll = (pattern, src) => { - const matches = []; - let match; - - const regexPatternWithGlobal = RegExp(pattern, 'g'); - - // eslint-disable-next-line no-cond-assign - while ((match = regexPatternWithGlobal.exec(src))) { - const [, group] = match; - - matches.push(trim(group)); - } - - return matches; -}; - -const isValidEmailTemplate = (template) => { - // Check for known invalid patterns - for (const reg of invalidPatternsRegexes) { - if (reg.test(template)) { - return false; - } - } - - const interpolation = { - // Strict interpolation pattern to match only valid groups - strict: createStrictInterpolationRegExp(authorizedKeys), - // Weak interpolation pattern to match as many group as possible. - loose: createLooseInterpolationRegExp(), - }; - - // Compute both strict & loose matches - const strictMatches = matchAll(interpolation.strict, template); - const looseMatches = matchAll(interpolation.loose, template); - - // If we have more matches with the loose RegExp than with the strict one, - // then it means that at least one of the interpolation group is invalid - // Note: In the future, if we wanted to give more details for error formatting - // purposes, we could return the difference between the two arrays - if (looseMatches.length > strictMatches.length) { - return false; - } - - return true; -}; - -module.exports = { - isValidEmailTemplate, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/controllers/validation/user.js b/packages/strapi/src/extensions/users-permissions/server/controllers/validation/user.js deleted file mode 100644 index d62f3f7..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/controllers/validation/user.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -const { yup, validateYupSchema } = require('@strapi/utils'); - -const deleteRoleSchema = yup.object().shape({ - role: yup.strapiID().required(), -}); - -const createUserBodySchema = yup.object().shape({ - email: yup.string().email().required(), - username: yup.string().min(1).required(), - password: yup.string().min(1).required(), - role: yup.lazy((value) => - typeof value === 'object' - ? yup - .object() - .shape({ - connect: yup - .array() - .of(yup.object().shape({ id: yup.strapiID().required() })) - .min(1, 'Users must have a role') - .required(), - }) - .required() - : yup.strapiID().required() - ), -}); - -const updateUserBodySchema = yup.object().shape({ - email: yup.string().email().min(1), - username: yup.string().min(1), - password: yup.string().min(1), - role: yup.lazy((value) => - typeof value === 'object' - ? yup.object().shape({ - connect: yup - .array() - .of(yup.object().shape({ id: yup.strapiID().required() })) - .required(), - disconnect: yup - .array() - .test('CheckDisconnect', 'Cannot remove role', function test(disconnectValue) { - if (value.connect.length === 0 && disconnectValue.length > 0) { - return false; - } - - return true; - }) - .required(), - }) - : yup.strapiID() - ), -}); - -module.exports = { - validateCreateUserBody: validateYupSchema(createUserBodySchema), - validateUpdateUserBody: validateYupSchema(updateUserBodySchema), - validateDeleteRoleBody: validateYupSchema(deleteRoleSchema), -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/index.js b/packages/strapi/src/extensions/users-permissions/server/graphql/index.js deleted file mode 100644 index 4780f32..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/index.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -const getTypes = require('./types'); -const getQueries = require('./queries'); -const getMutations = require('./mutations'); -const getResolversConfig = require('./resolvers-configs'); - -module.exports = ({ strapi }) => { - const { config: graphQLConfig } = strapi.plugin('graphql'); - const extensionService = strapi.plugin('graphql').service('extension'); - - const isShadowCRUDEnabled = graphQLConfig('shadowCRUD', true); - - if (!isShadowCRUDEnabled) { - return; - } - - // Disable Permissions queries & mutations but allow the - // type to be used/selected in filters or nested resolvers - extensionService - .shadowCRUD('plugin::users-permissions.permission') - .disableQueries() - .disableMutations(); - - // Disable User & Role's Create/Update/Delete actions so they can be replaced - const actionsToDisable = ['create', 'update', 'delete']; - - extensionService.shadowCRUD('plugin::users-permissions.user').disableActions(actionsToDisable); - extensionService.shadowCRUD('plugin::users-permissions.role').disableActions(actionsToDisable); - - // Register new types & resolvers config - extensionService.use(({ nexus }) => { - const types = getTypes({ strapi, nexus }); - const queries = getQueries({ strapi, nexus }); - const mutations = getMutations({ strapi, nexus }); - const resolversConfig = getResolversConfig({ strapi }); - - return { - types: [types, queries, mutations], - - resolversConfig, - }; - }); -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/change-password.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/change-password.js deleted file mode 100644 index 956d7b7..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/change-password.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; - -const { toPlainObject } = require('lodash/fp'); - -const { checkBadRequest } = require('../../utils'); - -module.exports = ({ nexus, strapi }) => { - const { nonNull } = nexus; - - return { - type: 'UsersPermissionsLoginPayload', - - args: { - currentPassword: nonNull('String'), - password: nonNull('String'), - passwordConfirmation: nonNull('String'), - }, - - description: 'Change user password. Confirm with the current password.', - - async resolve(parent, args, context) { - const { koaContext } = context; - - koaContext.request.body = toPlainObject(args); - - await strapi.plugin('users-permissions').controller('auth').changePassword(koaContext); - - const output = koaContext.body; - - checkBadRequest(output); - - return { - user: output.user || output, - jwt: output.jwt, - }; - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/email-confirmation.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/email-confirmation.js deleted file mode 100644 index 1e97f9a..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/email-confirmation.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -const { toPlainObject } = require('lodash/fp'); - -const { checkBadRequest } = require('../../utils'); - -module.exports = ({ nexus, strapi }) => { - const { nonNull } = nexus; - - return { - type: 'UsersPermissionsLoginPayload', - - args: { - confirmation: nonNull('String'), - }, - - description: 'Confirm an email users email address', - - async resolve(parent, args, context) { - const { koaContext } = context; - - koaContext.query = toPlainObject(args); - - await strapi - .plugin('users-permissions') - .controller('auth') - .emailConfirmation(koaContext, null, true); - - const output = koaContext.body; - - checkBadRequest(output); - - return { - user: output.user || output, - jwt: output.jwt, - }; - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/forgot-password.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/forgot-password.js deleted file mode 100644 index ceea19a..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/forgot-password.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; - -const { toPlainObject } = require('lodash/fp'); - -const { checkBadRequest } = require('../../utils'); - -module.exports = ({ nexus, strapi }) => { - const { nonNull } = nexus; - - return { - type: 'UsersPermissionsPasswordPayload', - - args: { - email: nonNull('String'), - }, - - description: 'Request a reset password token', - - async resolve(parent, args, context) { - const { koaContext } = context; - - koaContext.request.body = toPlainObject(args); - - await strapi.plugin('users-permissions').controller('auth').forgotPassword(koaContext); - - const output = koaContext.body; - - checkBadRequest(output); - - return { - ok: output.ok || output, - }; - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/login.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/login.js deleted file mode 100644 index cc0f0de..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/login.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; - -const { toPlainObject } = require('lodash/fp'); - -const { checkBadRequest } = require('../../utils'); - -module.exports = ({ nexus, strapi }) => { - const { nonNull } = nexus; - - return { - type: nonNull('UsersPermissionsLoginPayload'), - - args: { - input: nonNull('UsersPermissionsLoginInput'), - }, - - async resolve(parent, args, context) { - const { koaContext } = context; - - koaContext.params = { provider: args.input.provider }; - koaContext.request.body = toPlainObject(args.input); - - await strapi.plugin('users-permissions').controller('auth').callback(koaContext); - - const output = koaContext.body; - - checkBadRequest(output); - - return { - user: output.user || output, - jwt: output.jwt, - }; - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/register.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/register.js deleted file mode 100644 index 296d967..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/register.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -const { toPlainObject } = require('lodash/fp'); - -const { checkBadRequest } = require('../../utils'); - -module.exports = ({ nexus, strapi }) => { - const { nonNull } = nexus; - - return { - type: nonNull('UsersPermissionsLoginPayload'), - - args: { - input: nonNull('UsersPermissionsRegisterInput'), - }, - - description: 'Register a user', - - async resolve(parent, args, context) { - const { koaContext } = context; - - koaContext.request.body = toPlainObject(args.input); - - await strapi.plugin('users-permissions').controller('auth').register(koaContext); - - const output = koaContext.body; - - checkBadRequest(output); - - return { - user: output.user || output, - jwt: output.jwt, - }; - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/reset-password.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/reset-password.js deleted file mode 100644 index 65251c7..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/auth/reset-password.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; - -const { toPlainObject } = require('lodash/fp'); - -const { checkBadRequest } = require('../../utils'); - -module.exports = ({ nexus, strapi }) => { - const { nonNull } = nexus; - - return { - type: 'UsersPermissionsLoginPayload', - - args: { - password: nonNull('String'), - passwordConfirmation: nonNull('String'), - code: nonNull('String'), - }, - - description: 'Reset user password. Confirm with a code (resetToken from forgotPassword)', - - async resolve(parent, args, context) { - const { koaContext } = context; - - koaContext.request.body = toPlainObject(args); - - await strapi.plugin('users-permissions').controller('auth').resetPassword(koaContext); - - const output = koaContext.body; - - checkBadRequest(output); - - return { - user: output.user || output, - jwt: output.jwt, - }; - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/role/create-role.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/role/create-role.js deleted file mode 100644 index 3dd0fed..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/role/create-role.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -const { toPlainObject } = require('lodash/fp'); - -const usersPermissionsRoleUID = 'plugin::users-permissions.role'; - -module.exports = ({ nexus, strapi }) => { - const { getContentTypeInputName } = strapi.plugin('graphql').service('utils').naming; - const { nonNull } = nexus; - - const roleContentType = strapi.getModel(usersPermissionsRoleUID); - - const roleInputName = getContentTypeInputName(roleContentType); - - return { - type: 'UsersPermissionsCreateRolePayload', - - args: { - data: nonNull(roleInputName), - }, - - description: 'Create a new role', - - async resolve(parent, args, context) { - const { koaContext } = context; - - koaContext.request.body = toPlainObject(args.data); - - await strapi.plugin('users-permissions').controller('role').createRole(koaContext); - - return { ok: true }; - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/role/delete-role.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/role/delete-role.js deleted file mode 100644 index 154bbd8..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/role/delete-role.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -module.exports = ({ nexus, strapi }) => { - const { nonNull } = nexus; - - return { - type: 'UsersPermissionsDeleteRolePayload', - - args: { - id: nonNull('ID'), - }, - - description: 'Delete an existing role', - - async resolve(parent, args, context) { - const { koaContext } = context; - - koaContext.params = { role: args.id }; - - await strapi.plugin('users-permissions').controller('role').deleteRole(koaContext); - - return { ok: true }; - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/role/update-role.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/role/update-role.js deleted file mode 100644 index 4d22a01..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/role/update-role.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; - -const usersPermissionsRoleUID = 'plugin::users-permissions.role'; - -module.exports = ({ nexus, strapi }) => { - const { getContentTypeInputName } = strapi.plugin('graphql').service('utils').naming; - const { nonNull } = nexus; - - const roleContentType = strapi.getModel(usersPermissionsRoleUID); - - const roleInputName = getContentTypeInputName(roleContentType); - - return { - type: 'UsersPermissionsUpdateRolePayload', - - args: { - id: nonNull('ID'), - data: nonNull(roleInputName), - }, - - description: 'Update an existing role', - - async resolve(parent, args, context) { - const { koaContext } = context; - - koaContext.params = { role: args.id }; - koaContext.request.body = args.data; - koaContext.request.body.role = args.id; - - await strapi.plugin('users-permissions').controller('role').updateRole(koaContext); - - return { ok: true }; - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/user/create-user.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/user/create-user.js deleted file mode 100644 index 7c1526e..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/user/create-user.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -const { toPlainObject } = require('lodash/fp'); - -const { checkBadRequest } = require('../../../utils'); - -const usersPermissionsUserUID = 'plugin::users-permissions.user'; - -module.exports = ({ nexus, strapi }) => { - const { nonNull } = nexus; - const { getContentTypeInputName, getEntityResponseName } = strapi - .plugin('graphql') - .service('utils').naming; - - const userContentType = strapi.getModel(usersPermissionsUserUID); - - const userInputName = getContentTypeInputName(userContentType); - const responseName = getEntityResponseName(userContentType); - - return { - type: nonNull(responseName), - - args: { - data: nonNull(userInputName), - }, - - description: 'Create a new user', - - async resolve(parent, args, context) { - const { koaContext } = context; - - koaContext.params = {}; - koaContext.request.body = toPlainObject(args.data); - - await strapi.plugin('users-permissions').controller('user').create(koaContext); - - checkBadRequest(koaContext.body); - - return { - value: koaContext.body, - info: { args, resourceUID: 'plugin::users-permissions.user' }, - }; - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/user/delete-user.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/user/delete-user.js deleted file mode 100644 index 500834e..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/user/delete-user.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -const { checkBadRequest } = require('../../../utils'); - -const usersPermissionsUserUID = 'plugin::users-permissions.user'; - -module.exports = ({ nexus, strapi }) => { - const { nonNull } = nexus; - const { getEntityResponseName } = strapi.plugin('graphql').service('utils').naming; - - const userContentType = strapi.getModel(usersPermissionsUserUID); - - const responseName = getEntityResponseName(userContentType); - - return { - type: nonNull(responseName), - - args: { - id: nonNull('ID'), - }, - - description: 'Delete an existing user', - - async resolve(parent, args, context) { - const { koaContext } = context; - - koaContext.params = { id: args.id }; - - await strapi.plugin('users-permissions').controller('user').destroy(koaContext); - - checkBadRequest(koaContext.body); - - return { - value: koaContext.body, - info: { args, resourceUID: 'plugin::users-permissions.user' }, - }; - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/user/update-user.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/user/update-user.js deleted file mode 100644 index a89cb3e..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/crud/user/update-user.js +++ /dev/null @@ -1,46 +0,0 @@ -'use strict'; - -const { toPlainObject } = require('lodash/fp'); - -const { checkBadRequest } = require('../../../utils'); - -const usersPermissionsUserUID = 'plugin::users-permissions.user'; - -module.exports = ({ nexus, strapi }) => { - const { nonNull } = nexus; - const { getContentTypeInputName, getEntityResponseName } = strapi - .plugin('graphql') - .service('utils').naming; - - const userContentType = strapi.getModel(usersPermissionsUserUID); - - const userInputName = getContentTypeInputName(userContentType); - const responseName = getEntityResponseName(userContentType); - - return { - type: nonNull(responseName), - - args: { - id: nonNull('ID'), - data: nonNull(userInputName), - }, - - description: 'Update an existing user', - - async resolve(parent, args, context) { - const { koaContext } = context; - - koaContext.params = { id: args.id }; - koaContext.request.body = toPlainObject(args.data); - - await strapi.plugin('users-permissions').controller('user').update(koaContext); - - checkBadRequest(koaContext.body); - - return { - value: koaContext.body, - info: { args, resourceUID: 'plugin::users-permissions.user' }, - }; - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/index.js b/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/index.js deleted file mode 100644 index 801d1f3..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/mutations/index.js +++ /dev/null @@ -1,43 +0,0 @@ -'use strict'; - -const userUID = 'plugin::users-permissions.user'; -const roleUID = 'plugin::users-permissions.role'; - -module.exports = (context) => { - const { nexus, strapi } = context; - - const { naming } = strapi.plugin('graphql').service('utils'); - - const user = strapi.getModel(userUID); - const role = strapi.getModel(roleUID); - - const mutations = { - // CRUD (user & role) - [naming.getCreateMutationTypeName(role)]: require('./crud/role/create-role'), - [naming.getUpdateMutationTypeName(role)]: require('./crud/role/update-role'), - [naming.getDeleteMutationTypeName(role)]: require('./crud/role/delete-role'), - [naming.getCreateMutationTypeName(user)]: require('./crud/user/create-user'), - [naming.getUpdateMutationTypeName(user)]: require('./crud/user/update-user'), - [naming.getDeleteMutationTypeName(user)]: require('./crud/user/delete-user'), - - // Other mutations - login: require('./auth/login'), - register: require('./auth/register'), - forgotPassword: require('./auth/forgot-password'), - resetPassword: require('./auth/reset-password'), - changePassword: require('./auth/change-password'), - emailConfirmation: require('./auth/email-confirmation'), - }; - - return nexus.extendType({ - type: 'Mutation', - - definition(t) { - for (const [name, getConfig] of Object.entries(mutations)) { - const config = getConfig(context); - - t.field(name, config); - } - }, - }); -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/queries/index.js b/packages/strapi/src/extensions/users-permissions/server/graphql/queries/index.js deleted file mode 100644 index d45d0f2..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/queries/index.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -const me = require('./me'); - -module.exports = ({ nexus }) => { - return nexus.extendType({ - type: 'Query', - - definition(t) { - t.field('me', me({ nexus })); - }, - }); -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/queries/me.js b/packages/strapi/src/extensions/users-permissions/server/graphql/queries/me.js deleted file mode 100644 index 0835ad6..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/queries/me.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -module.exports = () => ({ - type: 'UsersPermissionsMe', - - args: {}, - - resolve(parent, args, context) { - const { user } = context.state; - - if (!user) { - throw new Error('Authentication requested'); - } - - return user; - }, -}); diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/resolvers-configs.js b/packages/strapi/src/extensions/users-permissions/server/graphql/resolvers-configs.js deleted file mode 100644 index f149df2..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/resolvers-configs.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; - -const userUID = 'plugin::users-permissions.user'; -const roleUID = 'plugin::users-permissions.role'; - -module.exports = ({ strapi }) => { - const { naming } = strapi.plugin('graphql').service('utils'); - - const user = strapi.getModel(userUID); - const role = strapi.getModel(roleUID); - - const createRole = naming.getCreateMutationTypeName(role); - const updateRole = naming.getUpdateMutationTypeName(role); - const deleteRole = naming.getDeleteMutationTypeName(role); - const createUser = naming.getCreateMutationTypeName(user); - const updateUser = naming.getUpdateMutationTypeName(user); - const deleteUser = naming.getDeleteMutationTypeName(user); - - return { - // Disabled auth for some operations - 'Mutation.login': { auth: false }, - 'Mutation.register': { auth: false }, - 'Mutation.forgotPassword': { auth: false }, - 'Mutation.resetPassword': { auth: false }, - 'Mutation.emailConfirmation': { auth: false }, - 'Mutation.changePassword': { - auth: { - scope: 'plugin::users-permissions.auth.changePassword', - }, - }, - - // Scoped auth for replaced CRUD operations - // Role - [`Mutation.${createRole}`]: { auth: { scope: [`${roleUID}.createRole`] } }, - [`Mutation.${updateRole}`]: { auth: { scope: [`${roleUID}.updateRole`] } }, - [`Mutation.${deleteRole}`]: { auth: { scope: [`${roleUID}.deleteRole`] } }, - // User - [`Mutation.${createUser}`]: { auth: { scope: [`${userUID}.create`] } }, - [`Mutation.${updateUser}`]: { auth: { scope: [`${userUID}.update`] } }, - [`Mutation.${deleteUser}`]: { auth: { scope: [`${userUID}.destroy`] } }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/types/create-role-payload.js b/packages/strapi/src/extensions/users-permissions/server/graphql/types/create-role-payload.js deleted file mode 100644 index 33b5c47..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/types/create-role-payload.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports = ({ nexus }) => { - return nexus.objectType({ - name: 'UsersPermissionsCreateRolePayload', - - definition(t) { - t.nonNull.boolean('ok'); - }, - }); -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/types/delete-role-payload.js b/packages/strapi/src/extensions/users-permissions/server/graphql/types/delete-role-payload.js deleted file mode 100644 index 7e06005..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/types/delete-role-payload.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports = ({ nexus }) => { - return nexus.objectType({ - name: 'UsersPermissionsDeleteRolePayload', - - definition(t) { - t.nonNull.boolean('ok'); - }, - }); -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/types/index.js b/packages/strapi/src/extensions/users-permissions/server/graphql/types/index.js deleted file mode 100644 index 7888e84..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/types/index.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -const typesFactories = [ - require('./me'), - require('./me-role'), - require('./register-input'), - require('./login-input'), - require('./password-payload'), - require('./login-payload'), - require('./create-role-payload'), - require('./update-role-payload'), - require('./delete-role-payload'), -]; - -/** - * @param {object} context - * @param {object} context.nexus - * @param {object} context.strapi - * @return {any[]} - */ -module.exports = (context) => typesFactories.map((factory) => factory(context)); diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/types/login-input.js b/packages/strapi/src/extensions/users-permissions/server/graphql/types/login-input.js deleted file mode 100644 index b8d7f41..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/types/login-input.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -module.exports = ({ nexus }) => { - return nexus.inputObjectType({ - name: 'UsersPermissionsLoginInput', - - definition(t) { - t.nonNull.string('identifier'); - t.nonNull.string('password'); - t.nonNull.string('provider', { default: 'local' }); - }, - }); -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/types/login-payload.js b/packages/strapi/src/extensions/users-permissions/server/graphql/types/login-payload.js deleted file mode 100644 index 65f8ec4..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/types/login-payload.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -module.exports = ({ nexus }) => { - return nexus.objectType({ - name: 'UsersPermissionsLoginPayload', - - definition(t) { - t.string('jwt'); - t.nonNull.field('user', { type: 'UsersPermissionsMe' }); - }, - }); -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/types/me-role.js b/packages/strapi/src/extensions/users-permissions/server/graphql/types/me-role.js deleted file mode 100644 index 485fedb..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/types/me-role.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -module.exports = ({ nexus }) => { - return nexus.objectType({ - name: 'UsersPermissionsMeRole', - - definition(t) { - t.nonNull.id('id'); - t.nonNull.string('name'); - t.string('description'); - t.string('type'); - }, - }); -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/types/me.js b/packages/strapi/src/extensions/users-permissions/server/graphql/types/me.js deleted file mode 100644 index d3a8aee..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/types/me.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; - -module.exports = ({ nexus }) => { - return nexus.objectType({ - name: 'UsersPermissionsMe', - - definition(t) { - t.nonNull.id('id'); - t.nonNull.string('username'); - t.string('email'); - t.boolean('confirmed'); - t.boolean('blocked'); - t.field('role', { type: 'UsersPermissionsMeRole' }); - }, - }); -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/types/password-payload.js b/packages/strapi/src/extensions/users-permissions/server/graphql/types/password-payload.js deleted file mode 100644 index 5d68c8e..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/types/password-payload.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports = ({ nexus }) => { - return nexus.objectType({ - name: 'UsersPermissionsPasswordPayload', - - definition(t) { - t.nonNull.boolean('ok'); - }, - }); -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/types/register-input.js b/packages/strapi/src/extensions/users-permissions/server/graphql/types/register-input.js deleted file mode 100644 index 1585761..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/types/register-input.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -module.exports = ({ nexus }) => { - return nexus.inputObjectType({ - name: 'UsersPermissionsRegisterInput', - - definition(t) { - t.nonNull.string('username'); - t.nonNull.string('email'); - t.nonNull.string('password'); - }, - }); -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/types/update-role-payload.js b/packages/strapi/src/extensions/users-permissions/server/graphql/types/update-role-payload.js deleted file mode 100644 index cea281d..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/types/update-role-payload.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports = ({ nexus }) => { - return nexus.objectType({ - name: 'UsersPermissionsUpdateRolePayload', - - definition(t) { - t.nonNull.boolean('ok'); - }, - }); -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/graphql/utils.js b/packages/strapi/src/extensions/users-permissions/server/graphql/utils.js deleted file mode 100644 index 8439021..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/graphql/utils.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -const { getOr } = require('lodash/fp'); - -/** - * Throws an ApolloError if context body contains a bad request - * @param contextBody - body of the context object given to the resolver - * @throws ApolloError if the body is a bad request - */ -function checkBadRequest(contextBody) { - const statusCode = getOr(200, 'statusCode', contextBody); - - if (statusCode !== 200) { - const errorMessage = getOr('Bad Request', 'error', contextBody); - - const exception = new Error(errorMessage); - - exception.code = statusCode || 400; - exception.data = contextBody; - - throw exception; - } -} - -module.exports = { - checkBadRequest, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/index.js b/packages/strapi/src/extensions/users-permissions/server/index.js deleted file mode 100644 index 14629aa..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/index.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -const register = require('./register'); -const bootstrap = require('./bootstrap'); -const contentTypes = require('./content-types'); -const middlewares = require('./middlewares'); -const services = require('./services'); -const routes = require('./routes'); -const controllers = require('./controllers'); -const config = require('./config'); - -module.exports = () => ({ - register, - bootstrap, - config, - routes, - controllers, - contentTypes, - middlewares, - services, -}); diff --git a/packages/strapi/src/extensions/users-permissions/server/middlewares/index.js b/packages/strapi/src/extensions/users-permissions/server/middlewares/index.js deleted file mode 100644 index 2abf96c..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/middlewares/index.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -const rateLimit = require('./rateLimit'); - -module.exports = { - rateLimit, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/middlewares/rateLimit.js b/packages/strapi/src/extensions/users-permissions/server/middlewares/rateLimit.js deleted file mode 100644 index 9880aa7..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/middlewares/rateLimit.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -module.exports = - (config, { strapi }) => - async (ctx, next) => { - const ratelimit = require('koa2-ratelimit').RateLimit; - - const message = [ - { - messages: [ - { - id: 'Auth.form.error.ratelimit', - message: 'Too many attempts, please try again in a minute.', - }, - ], - }, - ]; - - return ratelimit.middleware({ - interval: 1 * 60 * 1000, - max: 5, - prefixKey: `${ctx.request.path}:${ctx.request.ip}`, - message, - ...strapi.config.get('plugin.users-permissions.ratelimit'), - ...config, - })(ctx, next); - }; diff --git a/packages/strapi/src/extensions/users-permissions/server/register.js b/packages/strapi/src/extensions/users-permissions/server/register.js deleted file mode 100644 index 214fe30..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/register.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -const fs = require('fs'); -const path = require('path'); - -const authStrategy = require('./strategies/users-permissions'); -const sanitizers = require('./utils/sanitize/sanitizers'); - -module.exports = ({ strapi }) => { - strapi.container.get('auth').register('content-api', authStrategy); - strapi.sanitizers.add('content-api.output', sanitizers.defaultSanitizeOutput); - - if (strapi.plugin('graphql')) { - require('./graphql')({ strapi }); - } - - if (strapi.plugin('documentation')) { - const specPath = path.join(__dirname, '../documentation/content-api.yaml'); - const spec = fs.readFileSync(specPath, 'utf8'); - - strapi - .plugin('documentation') - .service('override') - .registerOverride(spec, { - pluginOrigin: 'users-permissions', - excludeFromGeneration: ['users-permissions'], - }); - } -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/routes/admin/index.js b/packages/strapi/src/extensions/users-permissions/server/routes/admin/index.js deleted file mode 100644 index 3ae910e..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/routes/admin/index.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -const permissionsRoutes = require('./permissions'); -const settingsRoutes = require('./settings'); -const roleRoutes = require('./role'); - -module.exports = { - type: 'admin', - routes: [...roleRoutes, ...settingsRoutes, ...permissionsRoutes], -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/routes/admin/permissions.js b/packages/strapi/src/extensions/users-permissions/server/routes/admin/permissions.js deleted file mode 100644 index 7ad462f..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/routes/admin/permissions.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -module.exports = [ - { - method: 'GET', - path: '/permissions', - handler: 'permissions.getPermissions', - }, - { - method: 'GET', - path: '/policies', - handler: 'permissions.getPolicies', - }, - - { - method: 'GET', - path: '/routes', - handler: 'permissions.getRoutes', - }, -]; diff --git a/packages/strapi/src/extensions/users-permissions/server/routes/admin/role.js b/packages/strapi/src/extensions/users-permissions/server/routes/admin/role.js deleted file mode 100644 index 4bdbbda..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/routes/admin/role.js +++ /dev/null @@ -1,79 +0,0 @@ -'use strict'; - -module.exports = [ - { - method: 'GET', - path: '/roles/:id', - handler: 'role.findOne', - config: { - policies: [ - { - name: 'admin::hasPermissions', - config: { - actions: ['plugin::users-permissions.roles.read'], - }, - }, - ], - }, - }, - { - method: 'GET', - path: '/roles', - handler: 'role.find', - config: { - policies: [ - { - name: 'admin::hasPermissions', - config: { - actions: ['plugin::users-permissions.roles.read'], - }, - }, - ], - }, - }, - { - method: 'POST', - path: '/roles', - handler: 'role.createRole', - config: { - policies: [ - { - name: 'admin::hasPermissions', - config: { - actions: ['plugin::users-permissions.roles.create'], - }, - }, - ], - }, - }, - { - method: 'PUT', - path: '/roles/:role', - handler: 'role.updateRole', - config: { - policies: [ - { - name: 'admin::hasPermissions', - config: { - actions: ['plugin::users-permissions.roles.update'], - }, - }, - ], - }, - }, - { - method: 'DELETE', - path: '/roles/:role', - handler: 'role.deleteRole', - config: { - policies: [ - { - name: 'admin::hasPermissions', - config: { - actions: ['plugin::users-permissions.roles.delete'], - }, - }, - ], - }, - }, -]; diff --git a/packages/strapi/src/extensions/users-permissions/server/routes/admin/settings.js b/packages/strapi/src/extensions/users-permissions/server/routes/admin/settings.js deleted file mode 100644 index 7ac31f6..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/routes/admin/settings.js +++ /dev/null @@ -1,95 +0,0 @@ -'use strict'; - -module.exports = [ - { - method: 'GET', - path: '/email-templates', - handler: 'settings.getEmailTemplate', - config: { - policies: [ - { - name: 'admin::hasPermissions', - config: { - actions: ['plugin::users-permissions.email-templates.read'], - }, - }, - ], - }, - }, - { - method: 'PUT', - path: '/email-templates', - handler: 'settings.updateEmailTemplate', - config: { - policies: [ - { - name: 'admin::hasPermissions', - config: { - actions: ['plugin::users-permissions.email-templates.update'], - }, - }, - ], - }, - }, - { - method: 'GET', - path: '/advanced', - handler: 'settings.getAdvancedSettings', - config: { - policies: [ - { - name: 'admin::hasPermissions', - config: { - actions: ['plugin::users-permissions.advanced-settings.read'], - }, - }, - ], - }, - }, - { - method: 'PUT', - path: '/advanced', - handler: 'settings.updateAdvancedSettings', - config: { - policies: [ - { - name: 'admin::hasPermissions', - config: { - actions: ['plugin::users-permissions.advanced-settings.update'], - }, - }, - ], - }, - }, - { - method: 'GET', - path: '/providers', - handler: 'settings.getProviders', - config: { - policies: [ - { - name: 'admin::hasPermissions', - config: { - actions: ['plugin::users-permissions.providers.read'], - }, - }, - ], - }, - }, - - { - method: 'PUT', - path: '/providers', - handler: 'settings.updateProviders', - config: { - policies: [ - { - name: 'admin::hasPermissions', - config: { - actions: ['plugin::users-permissions.providers.update'], - }, - }, - ], - }, - }, -]; diff --git a/packages/strapi/src/extensions/users-permissions/server/routes/content-api/auth.js b/packages/strapi/src/extensions/users-permissions/server/routes/content-api/auth.js deleted file mode 100644 index bb34782..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/routes/content-api/auth.js +++ /dev/null @@ -1,82 +0,0 @@ -'use strict'; - -module.exports = [ - { - method: 'GET', - path: '/connect/(.*)', - handler: 'auth.connect', - config: { - middlewares: ['plugin::users-permissions.rateLimit'], - prefix: '', - }, - }, - { - method: 'POST', - path: '/auth/local', - handler: 'auth.callback', - config: { - middlewares: ['plugin::users-permissions.rateLimit'], - prefix: '', - }, - }, - { - method: 'POST', - path: '/auth/local/register', - handler: 'auth.register', - config: { - middlewares: ['plugin::users-permissions.rateLimit'], - prefix: '', - }, - }, - { - method: 'GET', - path: '/auth/:provider/callback', - handler: 'auth.callback', - config: { - prefix: '', - }, - }, - { - method: 'POST', - path: '/auth/forgot-password', - handler: 'auth.forgotPassword', - config: { - middlewares: ['plugin::users-permissions.rateLimit'], - prefix: '', - }, - }, - { - method: 'POST', - path: '/auth/reset-password', - handler: 'auth.resetPassword', - config: { - middlewares: ['plugin::users-permissions.rateLimit'], - prefix: '', - }, - }, - { - method: 'GET', - path: '/auth/email-confirmation', - handler: 'auth.emailConfirmation', - config: { - prefix: '', - }, - }, - { - method: 'POST', - path: '/auth/send-email-confirmation', - handler: 'auth.sendEmailConfirmation', - config: { - prefix: '', - }, - }, - { - method: 'POST', - path: '/auth/change-password', - handler: 'auth.changePassword', - config: { - middlewares: ['plugin::users-permissions.rateLimit'], - prefix: '', - }, - }, -]; diff --git a/packages/strapi/src/extensions/users-permissions/server/routes/content-api/index.js b/packages/strapi/src/extensions/users-permissions/server/routes/content-api/index.js deleted file mode 100644 index b23adf5..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/routes/content-api/index.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -const authRoutes = require('./auth'); -const userRoutes = require('./user'); -const roleRoutes = require('./role'); -const permissionsRoutes = require('./permissions'); - -module.exports = { - type: 'content-api', - routes: [...authRoutes, ...userRoutes, ...roleRoutes, ...permissionsRoutes], -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/routes/content-api/permissions.js b/packages/strapi/src/extensions/users-permissions/server/routes/content-api/permissions.js deleted file mode 100644 index f6cf4a0..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/routes/content-api/permissions.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -module.exports = [ - { - method: 'GET', - path: '/permissions', - handler: 'permissions.getPermissions', - }, -]; diff --git a/packages/strapi/src/extensions/users-permissions/server/routes/content-api/role.js b/packages/strapi/src/extensions/users-permissions/server/routes/content-api/role.js deleted file mode 100644 index ca72365..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/routes/content-api/role.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -module.exports = [ - { - method: 'GET', - path: '/roles/:id', - handler: 'role.findOne', - }, - { - method: 'GET', - path: '/roles', - handler: 'role.find', - }, - { - method: 'POST', - path: '/roles', - handler: 'role.createRole', - }, - { - method: 'PUT', - path: '/roles/:role', - handler: 'role.updateRole', - }, - { - method: 'DELETE', - path: '/roles/:role', - handler: 'role.deleteRole', - }, -]; diff --git a/packages/strapi/src/extensions/users-permissions/server/routes/content-api/user.js b/packages/strapi/src/extensions/users-permissions/server/routes/content-api/user.js deleted file mode 100644 index a573a1e..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/routes/content-api/user.js +++ /dev/null @@ -1,60 +0,0 @@ -'use strict'; - -module.exports = [ - { - method: 'GET', - path: '/users/count', - handler: 'user.count', - config: { - prefix: '', - }, - }, - { - method: 'GET', - path: '/users', - handler: 'user.find', - config: { - prefix: '', - }, - }, - { - method: 'GET', - path: '/users/me', - handler: 'user.me', - config: { - prefix: '', - }, - }, - { - method: 'GET', - path: '/users/:id', - handler: 'user.findOne', - config: { - prefix: '', - }, - }, - { - method: 'POST', - path: '/users', - handler: 'user.create', - config: { - prefix: '', - }, - }, - { - method: 'PUT', - path: '/users/:id', - handler: 'user.update', - config: { - prefix: '', - }, - }, - { - method: 'DELETE', - path: '/users/:id', - handler: 'user.destroy', - config: { - prefix: '', - }, - }, -]; diff --git a/packages/strapi/src/extensions/users-permissions/server/routes/index.js b/packages/strapi/src/extensions/users-permissions/server/routes/index.js deleted file mode 100644 index 6939f2d..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/routes/index.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -module.exports = { - admin: require('./admin'), - 'content-api': require('./content-api'), -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/services/index.js b/packages/strapi/src/extensions/users-permissions/server/services/index.js deleted file mode 100644 index 3df8e27..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/services/index.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -const jwt = require('./jwt'); -const providers = require('./providers'); -const user = require('./user'); -const role = require('./role'); -const usersPermissions = require('./users-permissions'); -const providersRegistry = require('./providers-registry'); -const permission = require('./permission'); - -module.exports = { - jwt, - providers, - 'providers-registry': providersRegistry, - role, - user, - 'users-permissions': usersPermissions, - permission, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/services/jwt.js b/packages/strapi/src/extensions/users-permissions/server/services/jwt.js deleted file mode 100644 index e5b300a..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/services/jwt.js +++ /dev/null @@ -1,79 +0,0 @@ -'use strict'; - -/** - * Jwt.js service - * - * @description: A set of functions similar to controller's actions to avoid code duplication. - */ - -const _ = require('lodash'); -const jwt = require('jsonwebtoken'); - -module.exports = ({ strapi }) => ({ - getToken(ctx) { - let token; - - if (ctx.request && ctx.request.header && ctx.request.header.authorization) { - const parts = ctx.request.header.authorization.split(/\s+/); - - if (parts[0].toLowerCase() !== 'bearer' || parts.length !== 2) { - return null; - } - - token = parts[1]; - } else { - return null; - } - - return this.verify(token); - }, - - issue(payload, jwtOptions = {}) { - _.defaults(jwtOptions, strapi.config.get('plugin.users-permissions.jwt')); - - // jwt.issue and jwt.verify are modified from stock strapi code because I believe there is an issue with how stock strapi handles JWT. - // see https://github.com/auth0/node-jsonwebtoken/issues/208#issuecomment-231861138 - // console.log(`>>> JWT ISSUE invoked!!! jwtSecret:${strapi.config.get('plugin.users-permissions.jwtSecret')}`) - - // const jwtOne = jwt.sign( - // _.clone(payload), - // strapi.config.get('plugin.users-permissions.jwtSecret'), - // jwtOptions - // ) - - // const jwtTwo = jwt.sign( - // _.clone(payload), - // new Buffer.from(strapi.config.get('plugin.users-permissions.jwtSecret'), 'base64'), - // jwtOptions - // ) - - // console.log(`ok so lets do the thing. here is jwtOne:${jwtOne}`) - // console.log(`ok so lets do the thing. here is jwtTwo:${jwtTwo}`) - - - return jwt.sign( - _.clone(payload.toJSON ? payload.toJSON() : payload), - new Buffer.from(strapi.config.get('plugin.users-permissions.jwtSecret'), 'base64'), - jwtOptions - ); - }, - - verify(token) { - return new Promise((resolve, reject) => { - // jwt.issue and jwt.verify are modified from stock strapi code because I believe there is an issue with how stock strapi handles JWT. - // see https://github.com/auth0/node-jsonwebtoken/issues/208#issuecomment-231861138 - - jwt.verify( - token, - new Buffer.from(strapi.config.get('plugin.users-permissions.jwtSecret'), 'base64'), - {}, - (err, tokenPayload = {}) => { - if (err) { - return reject(new Error('Invalid token.')); - } - resolve(tokenPayload); - } - ); - }); - }, -}); diff --git a/packages/strapi/src/extensions/users-permissions/server/services/permission.js b/packages/strapi/src/extensions/users-permissions/server/services/permission.js deleted file mode 100644 index fbcdd2d..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/services/permission.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -const PUBLIC_ROLE_FILTER = { role: { type: 'public' } }; - -module.exports = ({ strapi }) => ({ - /** - * Find permissions associated to a specific role ID - * - * @param {number} roleID - * - * @return {object[]} - */ - async findRolePermissions(roleID) { - return strapi.entityService.load( - 'plugin::users-permissions.role', - { id: roleID }, - 'permissions' - ); - }, - - /** - * Find permissions for the public role - * - * @return {object[]} - */ - async findPublicPermissions() { - return strapi.entityService.findMany('plugin::users-permissions.permission', { - filters: PUBLIC_ROLE_FILTER, - }); - }, - - /** - * Transform a Users-Permissions' action into a content API one - * - * @param {object} permission - * @param {string} permission.action - * - * @return {{ action: string }} - */ - toContentAPIPermission(permission) { - const { action } = permission; - - return { action }; - }, -}); diff --git a/packages/strapi/src/extensions/users-permissions/server/services/providers-registry.js b/packages/strapi/src/extensions/users-permissions/server/services/providers-registry.js deleted file mode 100644 index fe9490a..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/services/providers-registry.js +++ /dev/null @@ -1,382 +0,0 @@ -'use strict'; - -const { strict: assert } = require('assert'); -const jwt = require('jsonwebtoken'); -const jwkToPem = require('jwk-to-pem'); - -const getCognitoPayload = async ({ idToken, jwksUrl, purest }) => { - const { - header: { kid }, - payload, - } = jwt.decode(idToken, { complete: true }); - - if (!payload || !kid) { - throw new Error('The provided token is not valid'); - } - - const config = { - cognito: { - discovery: { - origin: jwksUrl.origin, - path: jwksUrl.pathname, - }, - }, - }; - try { - const cognito = purest({ provider: 'cognito', config }); - // get the JSON Web Key (JWK) for the user pool - const { body: jwk } = await cognito('discovery').request(); - // Get the key with the same Key ID as the provided token - const key = jwk.keys.find(({ kid: jwkKid }) => jwkKid === kid); - const pem = jwkToPem(key); - - // https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-verifying-a-jwt.html - const decodedToken = await new Promise((resolve, reject) => { - jwt.verify(idToken, pem, { algorithms: ['RS256'] }, (err, decodedToken) => { - if (err) { - reject(); - } - resolve(decodedToken); - }); - }); - return decodedToken; - } catch (err) { - throw new Error('There was an error verifying the token'); - } -}; - -const getInitialProviders = ({ purest }) => ({ - async discord({ accessToken }) { - const discord = purest({ provider: 'discord' }); - - return discord - .get('users/@me') - .auth(accessToken) - .request() - .then(({ body }) => { - // Combine username and discriminator because discord username is not unique - const username = `${body.username}#${body.discriminator}`; - return { - username, - email: body.email, - }; - }); - }, - async cognito({ query, providers }) { - const jwksUrl = new URL(providers.cognito.jwksurl); - const idToken = query.id_token; - const tokenPayload = await getCognitoPayload({ idToken, jwksUrl, purest }); - return { - username: tokenPayload['cognito:username'], - email: tokenPayload.email, - }; - }, - async facebook({ accessToken }) { - const facebook = purest({ provider: 'facebook' }); - - return facebook - .get('me') - .auth(accessToken) - .qs({ fields: 'name,email' }) - .request() - .then(({ body }) => ({ - username: body.name, - email: body.email, - })); - }, - async google({ accessToken }) { - const google = purest({ provider: 'google' }); - - return google - .query('oauth') - .get('tokeninfo') - .qs({ accessToken }) - .request() - .then(({ body }) => ({ - username: body.email.split('@')[0], - email: body.email, - })); - }, - async github({ accessToken }) { - const github = purest({ - provider: 'github', - defaults: { - headers: { - 'user-agent': 'strapi', - }, - }, - }); - - const { body: userBody } = await github.get('user').auth(accessToken).request(); - - // This is the public email on the github profile - if (userBody.email) { - return { - username: userBody.login, - email: userBody.email, - }; - } - // Get the email with Github's user/emails API - const { body: emailBody } = await github.get('user/emails').auth(accessToken).request(); - - return { - username: userBody.login, - email: Array.isArray(emailBody) - ? emailBody.find((email) => email.primary === true).email - : null, - }; - }, - async microsoft({ accessToken }) { - const microsoft = purest({ provider: 'microsoft' }); - - return microsoft - .get('me') - .auth(accessToken) - .request() - .then(({ body }) => ({ - username: body.userPrincipalName, - email: body.userPrincipalName, - })); - }, - async twitter({ accessToken, query, providers }) { - const twitter = purest({ - provider: 'twitter', - defaults: { - oauth: { - consumer_key: providers.twitter.key, - consumer_secret: providers.twitter.secret, - }, - }, - }); - - return twitter - .get('account/verify_credentials') - .auth(accessToken, query.access_secret) - .qs({ screen_name: query['raw[screen_name]'], include_email: 'true' }) - .request() - .then(({ body }) => ({ - username: body.screen_name, - email: body.email, - })); - }, - async instagram({ accessToken }) { - const instagram = purest({ provider: 'instagram' }); - - return instagram - .get('me') - .auth(accessToken) - .qs({ fields: 'id,username' }) - .request() - .then(({ body }) => ({ - username: body.username, - email: `${body.username}@strapi.io`, // dummy email as Instagram does not provide user email - })); - }, - async vk({ accessToken, query }) { - const vk = purest({ provider: 'vk' }); - - return vk - .get('users') - .auth(accessToken) - .qs({ id: query.raw.user_id, v: '5.122' }) - .request() - .then(({ body }) => ({ - username: `${body.response[0].last_name} ${body.response[0].first_name}`, - email: query.raw.email, - })); - }, - async twitch({ accessToken, providers }) { - const twitch = purest({ - provider: 'twitch', - config: { - twitch: { - default: { - origin: 'https://api.twitch.tv', - path: 'helix/{path}', - headers: { - Authorization: 'Bearer {auth}', - 'Client-Id': '{auth}', - }, - }, - }, - }, - }); - - return twitch - .get('users') - .auth(accessToken, providers.twitch.key) - .request() - .then(({ body }) => ({ - username: body.data[0].login, - email: body.data[0].email, - })); - }, - async linkedin({ accessToken }) { - const linkedIn = purest({ provider: 'linkedin' }); - const { - body: { localizedFirstName }, - } = await linkedIn.get('me').auth(accessToken).request(); - const { - body: { elements }, - } = await linkedIn - .get('emailAddress?q=members&projection=(elements*(handle~))') - .auth(accessToken) - .request(); - - const email = elements[0]['handle~']; - - return { - username: localizedFirstName, - email: email.emailAddress, - }; - }, - async reddit({ accessToken }) { - const reddit = purest({ - provider: 'reddit', - config: { - reddit: { - default: { - origin: 'https://oauth.reddit.com', - path: 'api/{version}/{path}', - version: 'v1', - headers: { - Authorization: 'Bearer {auth}', - 'user-agent': 'strapi', - }, - }, - }, - }, - }); - - return reddit - .get('me') - .auth(accessToken) - .request() - .then(({ body }) => ({ - username: body.name, - email: `${body.name}@strapi.io`, // dummy email as Reddit does not provide user email - })); - }, - async auth0({ accessToken, providers }) { - const auth0 = purest({ provider: 'auth0' }); - - return auth0 - .get('userinfo') - .subdomain(providers.auth0.subdomain) - .auth(accessToken) - .request() - .then(({ body }) => { - const username = body.username || body.nickname || body.name || body.email.split('@')[0]; - const email = body.email || `${username.replace(/\s+/g, '.')}@strapi.io`; - - return { - username, - email, - }; - }); - }, - async cas({ accessToken, providers }) { - const cas = purest({ provider: 'cas' }); - - return cas - .get('oidc/profile') - .subdomain(providers.cas.subdomain) - .auth(accessToken) - .request() - .then(({ body }) => { - // CAS attribute may be in body.attributes or "FLAT", depending on CAS config - const username = body.attributes - ? body.attributes.strapiusername || body.id || body.sub - : body.strapiusername || body.id || body.sub; - const email = body.attributes - ? body.attributes.strapiemail || body.attributes.email - : body.strapiemail || body.email; - if (!username || !email) { - strapi.log.warn( - `CAS Response Body did not contain required attributes: ${JSON.stringify(body)}` - ); - } - return { - username, - email, - }; - }); - }, - async patreon({ accessToken }) { - const patreon = purest({ - provider: 'patreon', - config: { - patreon: { - default: { - origin: 'https://www.patreon.com', - path: 'api/oauth2/{path}', - headers: { - authorization: 'Bearer {auth}', - }, - }, - }, - }, - }); - - return patreon - .get('v2/identity') - .auth(accessToken) - .qs(new URLSearchParams({ - 'include': 'memberships,memberships.currently_entitled_tiers,memberships.currently_entitled_tiers.benefits,memberships.campaign', - 'fields[user]': 'full_name,email', - 'fields[member]': 'full_name,is_follower,patron_status,currently_entitled_amount_cents,campaign_lifetime_support_cents', - 'fields[tier]': 'title', - 'fields[benefit]': 'title', - }).toString()) - .request() - .then(({ body }) => { - const patreonData = body.data.attributes; - - let memberships = [] - let benefits = [] - if (body?.included !== undefined) { - memberships = body.included - .filter((i) => i.type === 'member') - .filter((i) => i.attributes.patron_status === 'active_patron') - .map((i) => i.id) - - benefits = body.included - .filter((i) => i.type === 'benefit') - .map((i) => i.id) - } - - - return { - username: patreonData.full_name, - email: patreonData.email, - memberships: memberships, - benefits: benefits, - }; - }); - }, -}); - -module.exports = () => { - const purest = require('purest'); - - const providersCallbacks = getInitialProviders({ purest }); - - return { - register(providerName, provider) { - assert(typeof providerName === 'string', 'Provider name must be a string'); - assert(typeof provider === 'function', 'Provider callback must be a function'); - - providersCallbacks[providerName] = provider({ purest }); - }, - - async run({ provider, accessToken, query, providers }) { - if (!providersCallbacks[provider]) { - throw new Error('Unknown provider.'); - } - - const providerCb = providersCallbacks[provider]; - - return providerCb({ accessToken, query, providers }); - }, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/services/providers.js b/packages/strapi/src/extensions/users-permissions/server/services/providers.js deleted file mode 100644 index e5f919e..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/services/providers.js +++ /dev/null @@ -1,156 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ - -// Public node modules. -const _ = require('lodash'); -const urlJoin = require('url-join'); - -const { getAbsoluteServerUrl } = require('@strapi/utils'); -const { getService } = require('../utils'); - -module.exports = ({ strapi }) => { - /** - * Helper to get profiles - * - * @param {String} provider - */ - - const getProfile = async (provider, query) => { - const accessToken = query.access_token || query.code || query.oauth_token; - - const providers = await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'grant' }) - .get(); - - return getService('providers-registry').run({ - provider, - query, - accessToken, - providers, - }); - }; - - /** - * Connect thanks to a third-party provider. - * - * - * @param {String} provider - * @param {String} accessToken - * - * @return {*} - */ - - const connect = async (provider, query) => { - const accessToken = query.access_token || query.code || query.oauth_token; - - if (!accessToken) { - throw new Error('No access_token.'); - } - - // Get the profile. - const profile = await getProfile(provider, query); - - const email = _.toLower(profile.email); - - // We need at least the mail. - if (!email) { - throw new Error('Email was not available.'); - } - - const users = await strapi.query('plugin::users-permissions.user').findMany({ - where: { email }, - }); - - const advancedSettings = await strapi - .store({ type: 'plugin', name: 'users-permissions', key: 'advanced' }) - .get(); - - const user = _.find(users, { provider }); - - if (_.isEmpty(user) && !advancedSettings.allow_register) { - throw new Error('Register action is actually not available.'); - } - - if (!_.isEmpty(user)) { - console.log(`>>> welcome back, user!`) - console.log(user) - } - - - // Retrieve default role. - const defaultRole = await strapi - .query('plugin::users-permissions.role') - .findOne({ where: { type: advancedSettings.default_role } }); - - const patronRole = await strapi - .query('plugin::users-permissions.role') - .findOne({ where: { name: 'Patron' }}); - - if (_.isEmpty(patronRole)) throw new Error('Patron role is missing in Strapi. Please create it in users-permissions plugin.'); - - const patreonModel = await strapi - .query('api::patreon.patreon') - .findOne({ select: ['id', 'accessToken', 'benefitId'], where: { id: 1 } }); - - console.log(` >> patreon model`) - console.log(patreonModel) - console.log(` >> patreon:${patreonModel.id}`) - - // get the user's patron status - console.log(` >> HERE is the user's patreon profile`) - const isPatron = profile.benefits.includes(patreonModel.benefitId) - const patreonBenefits = profile.benefits.join(',') - console.log(`isPatron:${isPatron}`) - - - // Update the user's role to match their patron status - const selectedRole = (isPatron) ? patronRole : defaultRole - - - if (!_.isEmpty(user)) { - const updatedUser = await strapi - .query('plugin::users-permissions.user') - .update({ - where: { email }, - data: { - ...user, - role: selectedRole.id, - patreonBenefits - } - }) - return updatedUser; - } - - if (users.length && advancedSettings.unique_email) { - throw new Error('Email is already taken.'); - } - - // Create the new user. - const newUser = { - ...profile, - email, // overwrite with lowercased email - provider, - role: selectedRole.id, - confirmed: true, - }; - - const createdUser = await strapi - .query('plugin::users-permissions.user') - .create({ data: newUser }); - - return createdUser; - }; - - const buildRedirectUri = (provider = '') => { - const apiPrefix = strapi.config.get('api.rest.prefix'); - return urlJoin(getAbsoluteServerUrl(strapi.config), apiPrefix, 'connect', provider, 'callback'); - }; - - return { - connect, - buildRedirectUri, - }; -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/services/role.js b/packages/strapi/src/extensions/users-permissions/server/services/role.js deleted file mode 100644 index 7b2ab81..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/services/role.js +++ /dev/null @@ -1,177 +0,0 @@ -'use strict'; - -const _ = require('lodash'); -const { NotFoundError } = require('@strapi/utils').errors; -const { getService } = require('../utils'); - -module.exports = ({ strapi }) => ({ - async createRole(params) { - if (!params.type) { - params.type = _.snakeCase(_.deburr(_.toLower(params.name))); - } - - const role = await strapi - .query('plugin::users-permissions.role') - .create({ data: _.omit(params, ['users', 'permissions']) }); - - const createPromises = _.flatMap(params.permissions, (type, typeName) => { - return _.flatMap(type.controllers, (controller, controllerName) => { - return _.reduce( - controller, - (acc, action, actionName) => { - const { enabled /* policy */ } = action; - - if (enabled) { - const actionID = `${typeName}.${controllerName}.${actionName}`; - - acc.push( - strapi - .query('plugin::users-permissions.permission') - .create({ data: { action: actionID, role: role.id } }) - ); - } - - return acc; - }, - [] - ); - }); - }); - - await Promise.all(createPromises); - }, - - async findOne(roleID) { - const role = await strapi - .query('plugin::users-permissions.role') - .findOne({ where: { id: roleID }, populate: ['permissions'] }); - - if (!role) { - throw new NotFoundError('Role not found'); - } - - const allActions = getService('users-permissions').getActions(); - - // Group by `type`. - role.permissions.forEach((permission) => { - const [type, controller, action] = permission.action.split('.'); - - _.set(allActions, `${type}.controllers.${controller}.${action}`, { - enabled: true, - policy: '', - }); - }); - - return { - ...role, - permissions: allActions, - }; - }, - - async find() { - const roles = await strapi.query('plugin::users-permissions.role').findMany({ sort: ['name'] }); - - for (const role of roles) { - role.nb_users = await strapi - .query('plugin::users-permissions.user') - .count({ where: { role: { id: role.id } } }); - } - - return roles; - }, - - async updateRole(roleID, data) { - const role = await strapi - .query('plugin::users-permissions.role') - .findOne({ where: { id: roleID }, populate: ['permissions'] }); - - if (!role) { - throw new NotFoundError('Role not found'); - } - - await strapi.query('plugin::users-permissions.role').update({ - where: { id: roleID }, - data: _.pick(data, ['name', 'description']), - }); - - const { permissions } = data; - - const newActions = _.flatMap(permissions, (type, typeName) => { - return _.flatMap(type.controllers, (controller, controllerName) => { - return _.reduce( - controller, - (acc, action, actionName) => { - const { enabled /* policy */ } = action; - - if (enabled) { - acc.push(`${typeName}.${controllerName}.${actionName}`); - } - - return acc; - }, - [] - ); - }); - }); - - const oldActions = role.permissions.map(({ action }) => action); - - const toDelete = role.permissions.reduce((acc, permission) => { - if (!newActions.includes(permission.action)) { - acc.push(permission); - } - return acc; - }, []); - - const toCreate = newActions - .filter((action) => !oldActions.includes(action)) - .map((action) => ({ action, role: role.id })); - - await Promise.all( - toDelete.map((permission) => - strapi - .query('plugin::users-permissions.permission') - .delete({ where: { id: permission.id } }) - ) - ); - - await Promise.all( - toCreate.map((permissionInfo) => - strapi.query('plugin::users-permissions.permission').create({ data: permissionInfo }) - ) - ); - }, - - async deleteRole(roleID, publicRoleID) { - const role = await strapi - .query('plugin::users-permissions.role') - .findOne({ where: { id: roleID }, populate: ['users', 'permissions'] }); - - if (!role) { - throw new NotFoundError('Role not found'); - } - - // Move users to guest role. - await Promise.all( - role.users.map((user) => { - return strapi.query('plugin::users-permissions.user').update({ - where: { id: user.id }, - data: { role: publicRoleID }, - }); - }) - ); - - // Remove permissions related to this role. - // TODO: use delete many - await Promise.all( - role.permissions.map((permission) => { - return strapi.query('plugin::users-permissions.permission').delete({ - where: { id: permission.id }, - }); - }) - ); - - // Delete the role. - await strapi.query('plugin::users-permissions.role').delete({ where: { id: roleID } }); - }, -}); diff --git a/packages/strapi/src/extensions/users-permissions/server/services/user.js b/packages/strapi/src/extensions/users-permissions/server/services/user.js deleted file mode 100644 index 27cf71a..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/services/user.js +++ /dev/null @@ -1,148 +0,0 @@ -'use strict'; - -/** - * User.js service - * - * @description: A set of functions similar to controller's actions to avoid code duplication. - */ - -const crypto = require('crypto'); -const bcrypt = require('bcryptjs'); -const urlJoin = require('url-join'); - -const { getAbsoluteAdminUrl, getAbsoluteServerUrl, sanitize } = require('@strapi/utils'); -const { getService } = require('../utils'); - -module.exports = ({ strapi }) => ({ - /** - * Promise to count users - * - * @return {Promise} - */ - - count(params) { - return strapi.query('plugin::users-permissions.user').count({ where: params }); - }, - - /** - * Promise to search count users - * - * @return {Promise} - */ - - /** - * Promise to add a/an user. - * @return {Promise} - */ - async add(values) { - return strapi.entityService.create('plugin::users-permissions.user', { - data: values, - populate: ['role'], - }); - }, - - /** - * Promise to edit a/an user. - * @param {string} userId - * @param {object} params - * @return {Promise} - */ - async edit(userId, params = {}) { - return strapi.entityService.update('plugin::users-permissions.user', userId, { - data: params, - populate: ['role'], - }); - }, - - /** - * Promise to fetch a/an user. - * @return {Promise} - */ - fetch(id, params) { - return strapi.entityService.findOne('plugin::users-permissions.user', id, params); - }, - - /** - * Promise to fetch authenticated user. - * @return {Promise} - */ - fetchAuthenticatedUser(id) { - return strapi - .query('plugin::users-permissions.user') - .findOne({ where: { id }, populate: ['role'] }); - }, - - /** - * Promise to fetch all users. - * @return {Promise} - */ - fetchAll(params) { - return strapi.entityService.findMany('plugin::users-permissions.user', params); - }, - - /** - * Promise to remove a/an user. - * @return {Promise} - */ - async remove(params) { - return strapi.query('plugin::users-permissions.user').delete({ where: params }); - }, - - validatePassword(password, hash) { - return bcrypt.compare(password, hash); - }, - - async sendConfirmationEmail(user) { - const userPermissionService = getService('users-permissions'); - const pluginStore = await strapi.store({ type: 'plugin', name: 'users-permissions' }); - const userSchema = strapi.getModel('plugin::users-permissions.user'); - - const settings = await pluginStore - .get({ key: 'email' }) - .then((storeEmail) => storeEmail.email_confirmation.options); - - // Sanitize the template's user information - const sanitizedUserInfo = await sanitize.sanitizers.defaultSanitizeOutput(userSchema, user); - - const confirmationToken = crypto.randomBytes(20).toString('hex'); - - await this.edit(user.id, { confirmationToken }); - - const apiPrefix = strapi.config.get('api.rest.prefix'); - - try { - settings.message = await userPermissionService.template(settings.message, { - URL: urlJoin(getAbsoluteServerUrl(strapi.config), apiPrefix, '/auth/email-confirmation'), - SERVER_URL: getAbsoluteServerUrl(strapi.config), - ADMIN_URL: getAbsoluteAdminUrl(strapi.config), - USER: sanitizedUserInfo, - CODE: confirmationToken, - }); - - settings.object = await userPermissionService.template(settings.object, { - USER: sanitizedUserInfo, - }); - } catch { - strapi.log.error( - '[plugin::users-permissions.sendConfirmationEmail]: Failed to generate a template for "user confirmation email". Please make sure your email template is valid and does not contain invalid characters or patterns' - ); - return; - } - - // Send an email to the user. - await strapi - .plugin('email') - .service('email') - .send({ - to: user.email, - from: - settings.from.email && settings.from.name - ? `${settings.from.name} <${settings.from.email}>` - : undefined, - replyTo: settings.response_email, - subject: settings.object, - text: settings.message, - html: settings.message, - }); - }, -}); diff --git a/packages/strapi/src/extensions/users-permissions/server/services/users-permissions.js b/packages/strapi/src/extensions/users-permissions/server/services/users-permissions.js deleted file mode 100644 index 3389cdb..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/services/users-permissions.js +++ /dev/null @@ -1,249 +0,0 @@ -'use strict'; - -const _ = require('lodash'); -const { filter, map, pipe, prop } = require('lodash/fp'); -const urlJoin = require('url-join'); -const { - template: { createStrictInterpolationRegExp }, - errors, - keysDeep, -} = require('@strapi/utils'); - -const { getService } = require('../utils'); - -const DEFAULT_PERMISSIONS = [ - { action: 'plugin::users-permissions.auth.callback', roleType: 'public' }, - { action: 'plugin::users-permissions.auth.connect', roleType: 'public' }, - { action: 'plugin::users-permissions.auth.forgotPassword', roleType: 'public' }, - { action: 'plugin::users-permissions.auth.resetPassword', roleType: 'public' }, - { action: 'plugin::users-permissions.auth.register', roleType: 'public' }, - { action: 'plugin::users-permissions.auth.emailConfirmation', roleType: 'public' }, - { action: 'plugin::users-permissions.auth.sendEmailConfirmation', roleType: 'public' }, - { action: 'plugin::users-permissions.user.me', roleType: 'authenticated' }, - { action: 'plugin::users-permissions.auth.changePassword', roleType: 'authenticated' }, -]; - -const transformRoutePrefixFor = (pluginName) => (route) => { - const prefix = route.config && route.config.prefix; - const path = prefix !== undefined ? `${prefix}${route.path}` : `/${pluginName}${route.path}`; - - return { - ...route, - path, - }; -}; - -module.exports = ({ strapi }) => ({ - getActions({ defaultEnable = false } = {}) { - const actionMap = {}; - - const isContentApi = (action) => { - if (!_.has(action, Symbol.for('__type__'))) { - return false; - } - - return action[Symbol.for('__type__')].includes('content-api'); - }; - - _.forEach(strapi.api, (api, apiName) => { - const controllers = _.reduce( - api.controllers, - (acc, controller, controllerName) => { - const contentApiActions = _.pickBy(controller, isContentApi); - - if (_.isEmpty(contentApiActions)) { - return acc; - } - - acc[controllerName] = _.mapValues(contentApiActions, () => { - return { - enabled: defaultEnable, - policy: '', - }; - }); - - return acc; - }, - {} - ); - - if (!_.isEmpty(controllers)) { - actionMap[`api::${apiName}`] = { controllers }; - } - }); - - _.forEach(strapi.plugins, (plugin, pluginName) => { - const controllers = _.reduce( - plugin.controllers, - (acc, controller, controllerName) => { - const contentApiActions = _.pickBy(controller, isContentApi); - - if (_.isEmpty(contentApiActions)) { - return acc; - } - - acc[controllerName] = _.mapValues(contentApiActions, () => { - return { - enabled: defaultEnable, - policy: '', - }; - }); - - return acc; - }, - {} - ); - - if (!_.isEmpty(controllers)) { - actionMap[`plugin::${pluginName}`] = { controllers }; - } - }); - - return actionMap; - }, - - async getRoutes() { - const routesMap = {}; - - _.forEach(strapi.api, (api, apiName) => { - const routes = _.flatMap(api.routes, (route) => { - if (_.has(route, 'routes')) { - return route.routes; - } - - return route; - }).filter((route) => route.info.type === 'content-api'); - - if (routes.length === 0) { - return; - } - - const apiPrefix = strapi.config.get('api.rest.prefix'); - routesMap[`api::${apiName}`] = routes.map((route) => ({ - ...route, - path: urlJoin(apiPrefix, route.path), - })); - }); - - _.forEach(strapi.plugins, (plugin, pluginName) => { - const transformPrefix = transformRoutePrefixFor(pluginName); - - const routes = _.flatMap(plugin.routes, (route) => { - if (_.has(route, 'routes')) { - return route.routes.map(transformPrefix); - } - - return transformPrefix(route); - }).filter((route) => route.info.type === 'content-api'); - - if (routes.length === 0) { - return; - } - - const apiPrefix = strapi.config.get('api.rest.prefix'); - routesMap[`plugin::${pluginName}`] = routes.map((route) => ({ - ...route, - path: urlJoin(apiPrefix, route.path), - })); - }); - - return routesMap; - }, - - async syncPermissions() { - const roles = await strapi.query('plugin::users-permissions.role').findMany(); - const dbPermissions = await strapi.query('plugin::users-permissions.permission').findMany(); - - const permissionsFoundInDB = _.uniq(_.map(dbPermissions, 'action')); - - const appActions = _.flatMap(strapi.api, (api, apiName) => { - return _.flatMap(api.controllers, (controller, controllerName) => { - return _.keys(controller).map((actionName) => { - return `api::${apiName}.${controllerName}.${actionName}`; - }); - }); - }); - - const pluginsActions = _.flatMap(strapi.plugins, (plugin, pluginName) => { - return _.flatMap(plugin.controllers, (controller, controllerName) => { - return _.keys(controller).map((actionName) => { - return `plugin::${pluginName}.${controllerName}.${actionName}`; - }); - }); - }); - - const allActions = [...appActions, ...pluginsActions]; - - const toDelete = _.difference(permissionsFoundInDB, allActions); - - await Promise.all( - toDelete.map((action) => { - return strapi.query('plugin::users-permissions.permission').delete({ where: { action } }); - }) - ); - - if (permissionsFoundInDB.length === 0) { - // create default permissions - for (const role of roles) { - const toCreate = pipe( - filter(({ roleType }) => roleType === role.type || roleType === null), - map(prop('action')) - )(DEFAULT_PERMISSIONS); - - await Promise.all( - toCreate.map((action) => { - return strapi.query('plugin::users-permissions.permission').create({ - data: { - action, - role: role.id, - }, - }); - }) - ); - } - } - }, - - async initialize() { - const roleCount = await strapi.query('plugin::users-permissions.role').count(); - - if (roleCount === 0) { - await strapi.query('plugin::users-permissions.role').create({ - data: { - name: 'Authenticated', - description: 'Default role given to authenticated user.', - type: 'authenticated', - }, - }); - - await strapi.query('plugin::users-permissions.role').create({ - data: { - name: 'Public', - description: 'Default role given to unauthenticated user.', - type: 'public', - }, - }); - } - - return getService('users-permissions').syncPermissions(); - }, - - async updateUserRole(user, role) { - return strapi - .query('plugin::users-permissions.user') - .update({ where: { id: user.id }, data: { role } }); - }, - - template(layout, data) { - const allowedTemplateVariables = keysDeep(data); - - // Create a strict interpolation RegExp based on possible variable names - const interpolate = createStrictInterpolationRegExp(allowedTemplateVariables, 'g'); - - try { - return _.template(layout, { interpolate, evaluate: false, escape: false })(data); - } catch (e) { - throw new errors.ApplicationError('Invalid email template'); - } - }, -}); diff --git a/packages/strapi/src/extensions/users-permissions/server/strategies/users-permissions.js b/packages/strapi/src/extensions/users-permissions/server/strategies/users-permissions.js deleted file mode 100644 index 7ff3421..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/strategies/users-permissions.js +++ /dev/null @@ -1,114 +0,0 @@ -'use strict'; - -const { castArray, map, every, pipe } = require('lodash/fp'); -const { ForbiddenError, UnauthorizedError } = require('@strapi/utils').errors; - -const { getService } = require('../utils'); - -const getAdvancedSettings = () => { - return strapi.store({ type: 'plugin', name: 'users-permissions' }).get({ key: 'advanced' }); -}; - -const authenticate = async (ctx) => { - try { - const token = await getService('jwt').getToken(ctx); - - if (token) { - const { id } = token; - - // Invalid token - if (id === undefined) { - return { authenticated: false }; - } - - const user = await getService('user').fetchAuthenticatedUser(id); - - // No user associated to the token - if (!user) { - return { error: 'Invalid credentials' }; - } - - const advancedSettings = await getAdvancedSettings(); - - // User not confirmed - if (advancedSettings.email_confirmation && !user.confirmed) { - return { error: 'Invalid credentials' }; - } - - // User blocked - if (user.blocked) { - return { error: 'Invalid credentials' }; - } - - // Fetch user's permissions - const permissions = await Promise.resolve(user.role.id) - .then(getService('permission').findRolePermissions) - .then(map(getService('permission').toContentAPIPermission)); - - // Generate an ability (content API engine) based on the given permissions - const ability = await strapi.contentAPI.permissions.engine.generateAbility(permissions); - - ctx.state.user = user; - - return { - authenticated: true, - credentials: user, - ability, - }; - } - - const publicPermissions = await getService('permission') - .findPublicPermissions() - .then(map(getService('permission').toContentAPIPermission)); - - if (publicPermissions.length === 0) { - return { authenticated: false }; - } - - const ability = await strapi.contentAPI.permissions.engine.generateAbility(publicPermissions); - - return { - authenticated: true, - credentials: null, - ability, - }; - } catch (err) { - return { authenticated: false }; - } -}; - -const verify = async (auth, config) => { - const { credentials: user, ability } = auth; - - if (!config.scope) { - if (!user) { - // A non authenticated user cannot access routes that do not have a scope - throw new UnauthorizedError(); - } else { - // An authenticated user can access non scoped routes - return; - } - } - - // If no ability have been generated, then consider auth is missing - if (!ability) { - throw new UnauthorizedError(); - } - - const isAllowed = pipe( - // Make sure we're dealing with an array - castArray, - // Transform the scope array into an action array - every((scope) => ability.can(scope)) - )(config.scope); - - if (!isAllowed) { - throw new ForbiddenError(); - } -}; - -module.exports = { - name: 'users-permissions', - authenticate, - verify, -}; diff --git a/packages/strapi/src/extensions/users-permissions/server/utils/index.d.ts b/packages/strapi/src/extensions/users-permissions/server/utils/index.d.ts deleted file mode 100644 index b9d7e20..0000000 --- a/packages/strapi/src/extensions/users-permissions/server/utils/index.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import * as usersPermissions from '../services/users-permissions'; -import * as user from '../services/user'; -import * as role from '../services/role'; -import * as jwt from '../services/jwt'; -import * as providers from '../services/providers'; -import * as permission from '../services/permission'; - -type S = { - ['users-permissions']: typeof usersPermissions; - ['role']: typeof role; - user: typeof user; - jwt: typeof jwt; - providers: typeof providers; - ['providers-registry']: typeof providers; - permission: typeof permission; -}; - -export function getService