fix: Check permissions earlier in users.update_role (#14156)

This commit is contained in:
Tom Moor authored and GitHub committed 2026-10-19 23:33:44 -04:00
1 parent d249b34e8e
commit 584e27ad10
2 files changed
+30 -1

No files matched your search

+28
View File
@@ -1266,6 +1266,34 @@ describe("#users.update_role", () => {
});
expect(res.status).toEqual(400);
});
it("should return the same error for a user in another team", async () => {
const admin = await buildAdmin();
const user = await buildAdmin();
for (const role of [UserRole.Admin, UserRole.Member]) {
const res = await server.post("/api/users.update_role", admin, {
body: {
id: user.id,
role,
},
});
expect(res.status).toEqual(403);
}
expect((await user.reload()).role).toEqual(UserRole.Admin);
});
it("should return the same error for an unknown user", async () => {
const admin = await buildAdmin();
const res = await server.post("/api/users.update_role", admin, {
body: {
id: faker.string.uuid(),
role: UserRole.Admin,
},
});
expect(res.status).toEqual(403);
});
});
describe("#users.promote", () => {
+2 -1
View File
@@ -371,10 +371,11 @@ async function updateRole(ctx: APIContext<T.UsersChangeRoleReq>) {
const actor = ctx.state.auth.user;
const user = await User.findByPk(userId, {
rejectOnEmpty: true,
transaction,
lock: transaction.LOCK.UPDATE,
});
authorize(actor, "update", user);
await Team.findByPk(user.teamId, {
transaction,
lock: transaction.LOCK.UPDATE,