fix: refs #6023 Rollback privileges.js
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Guillermo Bonet 2023-11-10 11:43:42 +01:00
parent 9668468f94
commit 9f92bc4b4c
1 changed files with 27 additions and 39 deletions

View File

@ -40,17 +40,10 @@ module.exports = Self => {
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const myOptions = {}; const myOptions = {};
let tx;
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
};
try {
const user = await Self.findById(userId, {fields: ['hasGrant']}, myOptions); const user = await Self.findById(userId, {fields: ['hasGrant']}, myOptions);
const userToUpdate = await Self.findById(id, { const userToUpdate = await Self.findById(id, {
@ -84,12 +77,7 @@ module.exports = Self => {
userToUpdate.roleFk = roleFk; userToUpdate.roleFk = roleFk;
} }
await userToUpdate.save(myOptions); await userToUpdate.save(userToUpdate);
await models.Account.sync(userToUpdate.name, null, null, myOptions); await models.Account.sync(userToUpdate.name);
if (tx) await tx.commit();
} catch (err) {
if (tx) await tx.rollback();
throw err;
};
}; };
}; };