mirror of
https://github.com/outline/outline.git
synced 2026-12-05 02:44:34 +03:00
fix: Check permissions earlier in users.update_role (#14156)
This commit is contained in:
1 parent
d249b34e8e
commit
584e27ad10
2 files changed
+30
-1
No files matched your search
@@ -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", () => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user