fix: refs #6744 remove params
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2024-02-13 10:10:48 +01:00
parent 6e915d36d6
commit 47bfb34507
2 changed files with 13 additions and 16 deletions

View File

@ -3,27 +3,23 @@ module.exports = Self => {
Self.remoteMethodCtx('setPassword', {
description: 'Set a new password',
accepts: [{
arg: 'workerFk',
arg: 'id',
type: 'number',
required: true,
description: 'The worker id',
http: {source: 'path'}
}, {
arg: 'newPass',
type: 'String',
required: true,
description: 'The new worker password'
}, {
arg: 'emailVerified',
type: 'Boolean',
required: true,
},
],
}],
http: {
path: `/:id/setPassword`,
verb: 'PATCH'
}
});
Self.setPassword = async(ctx, workerFk, newPass, emailVerified, options) => {
Self.setPassword = async(ctx, workerId, newPass, options) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const myOptions = {};
@ -37,12 +33,13 @@ module.exports = Self => {
}
try {
const ishimself = userId === workerFk;
const isSubordinate = await models.Worker.isSubordinate(ctx, workerFk, myOptions);
const ishimself = userId === workerId;
const isSubordinate = await Self.isSubordinate(ctx, workerId, myOptions);
const {emailVerified} = await models.VnUser.findById(workerId, {fields: ['emailVerified']}, myOptions);
if (ishimself || (isSubordinate && !emailVerified)) {
await models.VnUser.setPassword(workerFk, newPass, myOptions);
await models.VnUser.updateAll({id: workerFk}, {emailVerified: true}, myOptions);
await models.VnUser.setPassword(workerId, newPass, myOptions);
await models.VnUser.updateAll({id: workerId}, {emailVerified: true}, myOptions);
} else
throw new UserError('You don\'t have enough privileges.');

View File

@ -5,6 +5,9 @@ class Controller extends Descriptor {
constructor($element, $, $rootScope) {
super($element, $);
this.$rootScope = $rootScope;
this.$http.get(`UserConfigs/getUserConfig`)
.then(res => this.userFk = res.data.userFk);
}
get worker() {
@ -15,8 +18,6 @@ class Controller extends Descriptor {
this.entity = value;
if (value)
this.getIsExcluded();
this.$http.get(`UserConfigs/getUserConfig`)
.then(res => this.userFk = res.data.userFk);
if (this.entity && !this.entity.user.emailVerified)
this.getPassRequirements();
@ -89,8 +90,7 @@ class Controller extends Descriptor {
if (this.newPassword != this.repeatPassword)
throw new UserError(`Passwords don't match`);
this.$http.patch(
`Workers/${this.entity.id}/setPassword`,
{workerFk: this.entity.id, newPass: this.newPassword, emailVerified: !!this.entity.user.emailVerified}
`Workers/${this.entity.id}/setPassword`, {newPass: this.newPassword}
) .then(() => {
this.vnApp.showSuccess(this.$translate.instant('Password changed!'));
});