mirror of
https://github.com/strapi/strapi.git
synced 2025-11-13 00:29:51 +00:00
Add useSSORegistration option for gold users on admin creation
This commit is contained in:
parent
4369af5361
commit
9f01afca88
36
packages/strapi-admin/ee/controllers/user.js
Normal file
36
packages/strapi-admin/ee/controllers/user.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { pick } = require('lodash/fp');
|
||||||
|
const { validateUserCreationInput } = require('../validation/user');
|
||||||
|
|
||||||
|
const pickUserCreationAttributes = pick(['firstname', 'lastname', 'email', 'roles']);
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
async create(ctx) {
|
||||||
|
const { body } = ctx.request;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await validateUserCreationInput(body);
|
||||||
|
} catch (err) {
|
||||||
|
return ctx.badRequest('ValidationError', err);
|
||||||
|
}
|
||||||
|
|
||||||
|
const attributes = pickUserCreationAttributes(body);
|
||||||
|
const { useSSORegistration } = body;
|
||||||
|
|
||||||
|
const userAlreadyExists = await strapi.admin.services.user.exists({ email: attributes.email });
|
||||||
|
|
||||||
|
if (userAlreadyExists) {
|
||||||
|
return ctx.badRequest('Email already taken');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useSSORegistration) {
|
||||||
|
Object.assign(attributes, { registrationToken: null, isActive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
const createdUser = await strapi.admin.services.user.create(attributes);
|
||||||
|
const userInfo = strapi.admin.services.user.sanitizeUser(createdUser);
|
||||||
|
|
||||||
|
ctx.created({ data: userInfo });
|
||||||
|
},
|
||||||
|
};
|
||||||
29
packages/strapi-admin/ee/validation/user.js
Normal file
29
packages/strapi-admin/ee/validation/user.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { yup, formatYupErrors } = require('strapi-utils');
|
||||||
|
// eslint-disable-next-line node/no-extraneous-require
|
||||||
|
const { features } = require('strapi/lib/utils/ee');
|
||||||
|
const { schemas } = require('../../validation/user');
|
||||||
|
|
||||||
|
const handleReject = error => Promise.reject(formatYupErrors(error));
|
||||||
|
|
||||||
|
const ssoUserCreationInputExtension = yup
|
||||||
|
.object()
|
||||||
|
.shape({
|
||||||
|
useSSORegistration: yup.boolean(),
|
||||||
|
})
|
||||||
|
.noUnknown();
|
||||||
|
|
||||||
|
const validateUserCreationInput = data => {
|
||||||
|
let schema = schemas.userCreationSchema;
|
||||||
|
|
||||||
|
if (features.isEnabled('sso')) {
|
||||||
|
schema = schema.concat(ssoUserCreationInputExtension);
|
||||||
|
}
|
||||||
|
|
||||||
|
return schema.validate(data, { strict: true, abortEarly: false }).catch(handleReject);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
validateUserCreationInput,
|
||||||
|
};
|
||||||
@ -73,4 +73,10 @@ module.exports = {
|
|||||||
validateProfileUpdateInput,
|
validateProfileUpdateInput,
|
||||||
validateUserUpdateInput,
|
validateUserUpdateInput,
|
||||||
validateUsersDeleteInput,
|
validateUsersDeleteInput,
|
||||||
|
|
||||||
|
schemas: {
|
||||||
|
userCreationSchema,
|
||||||
|
usersDeleteSchema,
|
||||||
|
userUpdateSchema,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user