diff --git a/back/methods/vn-user/createUser.js b/back/methods/vn-user/createUser.js new file mode 100644 index 000000000..0c9151fb1 --- /dev/null +++ b/back/methods/vn-user/createUser.js @@ -0,0 +1,72 @@ +module.exports = function(Self) { + Self.remoteMethodCtx('createUser', { + description: 'Create a user', + accessType: 'WRITE', + accepts: [{ + arg: 'name', + type: 'string', + required: true + }, + { + arg: 'nickname', + type: 'string', + required: true + }, + { + arg: 'email', + type: 'string', + required: true + }, + { + arg: 'roleFk', + type: 'number', + required: true + }, + { + arg: 'password', + type: 'string', + required: true + }, + { + arg: 'active', + type: 'boolean' + }], + returns: { + root: true, + type: 'object' + }, + http: { + verb: 'POST', + path: '/createUser' + } + }); + + Self.createUser = async(ctx, options) => { + const models = Self.app.models; + const args = ctx.args; + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + if (!args.active) args.active = false; + + delete args.ctx; // Remove unwanted properties + const newUser = await models.VnUser.create(args, myOptions); + + if (tx) await tx.commit(); + + return newUser; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/back/models/vn-user.js b/back/models/vn-user.js index 84ba11794..2fa040d84 100644 --- a/back/models/vn-user.js +++ b/back/models/vn-user.js @@ -10,6 +10,9 @@ module.exports = function(Self) { require('../methods/vn-user/recover-password')(Self); require('../methods/vn-user/validate-token')(Self); require('../methods/vn-user/privileges')(Self); + require('../methods/vn-user/createUser')(Self); + + Self.definition.settings.acls.find(acl => acl.property == 'create').permission = 'DENY'; // Validations diff --git a/db/changes/232001/00-aclAccount.sql b/db/changes/232201/00-aclAccount.sql similarity index 100% rename from db/changes/232001/00-aclAccount.sql rename to db/changes/232201/00-aclAccount.sql diff --git a/db/changes/232001/00-aclVnUser.sql b/db/changes/232201/00-aclVnUser.sql similarity index 71% rename from db/changes/232001/00-aclVnUser.sql rename to db/changes/232201/00-aclVnUser.sql index 1a63ed964..2cbadb548 100644 --- a/db/changes/232001/00-aclVnUser.sql +++ b/db/changes/232201/00-aclVnUser.sql @@ -6,4 +6,5 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp VALUES ('VnUser', '*', '*', 'ALLOW', 'ROLE', 'itManagement'), ('VnUser', '__get__preview', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('VnUser', 'preview', '*', 'ALLOW', 'ROLE', 'employee'); + ('VnUser', 'preview', '*', 'ALLOW', 'ROLE', 'employee'), + ('VnUser', 'createUser', 'WRITE', 'ALLOW', 'ROLE', 'itManagement'); diff --git a/modules/account/front/create/index.html b/modules/account/front/create/index.html index ee2de926a..f373cc468 100644 --- a/modules/account/front/create/index.html +++ b/modules/account/front/create/index.html @@ -1,6 +1,6 @@ @@ -12,18 +12,18 @@ @@ -39,7 +39,7 @@ type="password"> diff --git a/modules/account/front/index/index.html b/modules/account/front/index/index.html index d067c8c37..7502c8b3d 100644 --- a/modules/account/front/index/index.html +++ b/modules/account/front/index/index.html @@ -14,11 +14,11 @@
{{::user.nickname}}
@@ -36,12 +36,12 @@ - - \ No newline at end of file +