mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 08:12:40 +10:00
feat: user page & $dropFetch util
This commit is contained in:
14
server/api/v1/admin/auth/index.get.ts
Normal file
14
server/api/v1/admin/auth/index.get.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { AuthMec } from "@prisma/client";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import { applicationSettings } from "~/server/internal/config/application-configuration";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["auth:read"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const enabledMechanisms: AuthMec[] = await applicationSettings.get(
|
||||
"enabledAuthencationMechanisms"
|
||||
);
|
||||
|
||||
return enabledMechanisms;
|
||||
});
|
||||
26
server/api/v1/admin/users/[id]/index.get.ts
Normal file
26
server/api/v1/admin/users/[id]/index.get.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["user:read"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const userId = getRouterParam(h3, "id");
|
||||
if (!userId)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "No userId in route.",
|
||||
});
|
||||
|
||||
if (userId == "system")
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Cannot delete system user.",
|
||||
});
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user)
|
||||
throw createError({ statusCode: 404, statusMessage: "User not found." });
|
||||
|
||||
return user;
|
||||
});
|
||||
@ -5,7 +5,18 @@ export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["user:read"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const users = await prisma.user.findMany({});
|
||||
const users = await prisma.user.findMany({
|
||||
where: {
|
||||
id: { not: "system" },
|
||||
},
|
||||
include: {
|
||||
authMecs: {
|
||||
select: {
|
||||
mec: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return users;
|
||||
});
|
||||
Reference in New Issue
Block a user