mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-02 10:12:15 +00:00
Enhance impersonation functionality and user management
- Updated the ImpersonationBar component to fetch users dynamically and handle impersonation actions more efficiently. - Refactored the ProfileForm to set the allowImpersonation value directly, improving form handling. - Modified the DashboardLayout to conditionally render the ImpersonationBar based on user permissions and cloud settings. - Added a new role column to the user_temp table to support user role management. - Updated API routes to include checks for root access and improved user listing functionality.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
IS_CLOUD,
|
||||
auth,
|
||||
createApiKey,
|
||||
findOrganizationById,
|
||||
findUserById,
|
||||
@@ -92,42 +91,18 @@ export const userRouter = createTRPCRouter({
|
||||
|
||||
return memberResult;
|
||||
}),
|
||||
listUsers: adminProcedure
|
||||
.input(
|
||||
z.object({
|
||||
search: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.query(async ({ ctx, input }) => {
|
||||
try {
|
||||
console.log(process.env.USER_ADMIN_ID, ctx.user.id);
|
||||
if (process.env.USER_ADMIN_ID !== ctx.user.id) {
|
||||
return [];
|
||||
}
|
||||
const users = await auth.listUsers({
|
||||
query: {
|
||||
limit: 100,
|
||||
filterField: "allowImpersonation",
|
||||
filterOperator: "eq",
|
||||
filterValue: true,
|
||||
...(input.search && {
|
||||
searchField: "email",
|
||||
searchOperator: "contains",
|
||||
searchValue: input.search,
|
||||
}),
|
||||
},
|
||||
// @ts-ignore
|
||||
headers: {
|
||||
cookie: ctx.req.headers.cookie,
|
||||
},
|
||||
});
|
||||
console.log(users);
|
||||
return users;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
throw error;
|
||||
}
|
||||
}),
|
||||
haveRootAccess: protectedProcedure.query(async ({ ctx }) => {
|
||||
if (!IS_CLOUD) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
process.env.USER_ADMIN_ID === ctx.user.id ||
|
||||
ctx.session?.impersonatedBy === process.env.USER_ADMIN_ID
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}),
|
||||
getBackups: adminProcedure.query(async ({ ctx }) => {
|
||||
const memberResult = await db.query.member.findFirst({
|
||||
where: and(
|
||||
|
||||
@@ -31,7 +31,9 @@ import { ZodError } from "zod";
|
||||
|
||||
interface CreateContextOptions {
|
||||
user: (User & { role: "member" | "admin" | "owner"; ownerId: string }) | null;
|
||||
session: (Session & { activeOrganizationId: string }) | null;
|
||||
session:
|
||||
| (Session & { activeOrganizationId: string; impersonatedBy?: string })
|
||||
| null;
|
||||
req: CreateNextContextOptions["req"];
|
||||
res: CreateNextContextOptions["res"];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user