MCPcopy
hub / github.com/directus/directus / createOne

Method createOne

api/src/services/users.ts:208–235  ·  view source on GitHub ↗

* Create a new user

(data: Partial<Item>, opts: MutationOptions = {})

Source from the content-addressed store, hash-verified

206 * Create a new user
207 */
208 override async createOne(data: Partial<Item>, opts: MutationOptions = {}): Promise<PrimaryKey> {
209 try {
210 if ('email' in data && data['email'] !== undefined) {
211 this.validateEmail(data['email']);
212 await this.checkUniqueEmails([data['email']]);
213 }
214
215 if ('password' in data) {
216 await this.checkPasswordPolicy([data['password']]);
217 }
218
219 if ('provider' in data) {
220 this.checkProviderEntitlement(data['provider']);
221 }
222 } catch (err: any) {
223 opts.preMutationError = err;
224 }
225
226 if (!('status' in data) || data['status'] === 'active') {
227 // Creating a user only requires checking user limits if the user is active, no need to care about the role
228 opts.userIntegrityCheckFlags =
229 (opts.userIntegrityCheckFlags ?? UserIntegrityCheckFlag.None) | UserIntegrityCheckFlag.UserLimits;
230
231 opts.onRequireUserIntegrityCheck?.(opts.userIntegrityCheckFlags);
232 }
233
234 return await super.createOne(data, opts);
235 }
236
237 /**
238 * Create multiple new users

Callers 4

createAdminFunction · 0.95
usersCreateFunction · 0.95
inviteUserMethod · 0.95
registerUserMethod · 0.95

Calls 5

validateEmailMethod · 0.95
checkUniqueEmailsMethod · 0.95
checkPasswordPolicyMethod · 0.95
createOneMethod · 0.65

Tested by

no test coverage detected