fix: protect demo users from deletion and password changes
This commit is contained in:
1 parent
7c00c18a42
commit
1f65eab0d9
2 files changed
+17
No files matched your search
@@ -18,6 +18,9 @@ password. Decimal units are the default. Change them from the user form or **Com
|
|||||||
Preferences → Data size units**. Byte rates follow the same preference; bit rates stay decimal and use labels such as
|
Preferences → Data size units**. Byte rates follow the same preference; bit rates stay decimal and use labels such as
|
||||||
Mb/s. Deleting a user does not delete boards they created.
|
Mb/s. Deleting a user does not delete boards they created.
|
||||||
|
|
||||||
|
In demo mode (`DEMO_MODE=true`), user deletion and password changes are disabled for everyone, including administrators,
|
||||||
|
even when `DEMO_READ_ONLY=false` allows other changes. This applies to the UI and API.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Groups
|
## Groups
|
||||||
|
|||||||
@@ -497,6 +497,13 @@ export const userRouter = createTRPCRouter({
|
|||||||
mcp: { enabled: true, description: "Delete a user by ID. REQUIRED: userId (string)" },
|
mcp: { enabled: true, description: "Delete a user by ID. REQUIRED: userId (string)" },
|
||||||
})
|
})
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
if (isDemoMode) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "FORBIDDEN",
|
||||||
|
message: "User deletion is disabled in demo mode",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Only admins and user itself can delete a user
|
// Only admins and user itself can delete a user
|
||||||
if (ctx.session.user.id !== input.userId && !ctx.session.user.permissions.includes("admin")) {
|
if (ctx.session.user.id !== input.userId && !ctx.session.user.permissions.includes("admin")) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -519,6 +526,13 @@ export const userRouter = createTRPCRouter({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
if (isDemoMode) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "FORBIDDEN",
|
||||||
|
message: "Password changes are disabled in demo mode",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const user = ctx.session.user;
|
const user = ctx.session.user;
|
||||||
// Only admins can change other users' passwords
|
// Only admins can change other users' passwords
|
||||||
if (!user.permissions.includes("admin") && user.id !== input.userId) {
|
if (!user.permissions.includes("admin") && user.id !== input.userId) {
|
||||||
|
|||||||
Reference in new issue
Block a user