474b09c7f2
* perf: add perf_hooks * perf: add cache * fix: test * feat: support bloom filter * feat: caching token black list * perf: caching i18n instance * fix: test * fix: test * chore: remove prePerfHooks on app * chore: improve i18n instances cache * chore: remove performance measure * fix: package.json * perf: optimize cache strategy * fix: test * fix: bug * test: storer of auth-manager * fix: afterDestroy hook when updating null value * fix: version * chore: fix bug and add test * fix: test * fix: test
48 lines
848 B
TypeScript
48 lines
848 B
TypeScript
import { Context, Next } from '@nocobase/actions';
|
|
|
|
export async function setDefaultRole(ctx: Context, next: Next) {
|
|
const {
|
|
values: { roleName },
|
|
} = ctx.action.params;
|
|
|
|
const {
|
|
db,
|
|
state: { currentUser },
|
|
action: {
|
|
params: { values },
|
|
},
|
|
} = ctx;
|
|
|
|
if (values.roleName == 'anonymous') {
|
|
return next();
|
|
}
|
|
|
|
const repository = db.getRepository('rolesUsers');
|
|
|
|
await db.sequelize.transaction(async (transaction) => {
|
|
await repository.update({
|
|
filter: {
|
|
userId: currentUser.id,
|
|
},
|
|
values: {
|
|
default: false,
|
|
},
|
|
transaction,
|
|
});
|
|
await repository.update({
|
|
filter: {
|
|
userId: currentUser.id,
|
|
roleName,
|
|
},
|
|
values: {
|
|
default: true,
|
|
},
|
|
transaction,
|
|
});
|
|
});
|
|
|
|
ctx.body = 'ok';
|
|
|
|
await next();
|
|
}
|