mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Feat/um 114 roles and permissions (#1683)
* Auth checkpoint. * Merge branch 'dev' into feat/um-114-roles-and-permissions
This commit is contained in:
parent
a4e80ca3e5
commit
06bebadbb9
27 changed files with 331 additions and 482 deletions
|
|
@ -1,83 +0,0 @@
|
|||
import { Prisma, Permission } from '@prisma/client';
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function createPermission(data: Prisma.PermissionCreateInput): Promise<Permission> {
|
||||
return prisma.client.permission.create({
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPermission(where: Prisma.PermissionWhereUniqueInput): Promise<Permission> {
|
||||
return prisma.client.permission.findUnique({
|
||||
where,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPermissions(where: Prisma.PermissionWhereInput): Promise<Permission[]> {
|
||||
return prisma.client.permission.findMany({
|
||||
where,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPermissionsByUserId(userId, name?: string): Promise<Permission[]> {
|
||||
return prisma.client.permission.findMany({
|
||||
where: {
|
||||
...(name ? { name } : {}),
|
||||
RolePermission: {
|
||||
every: {
|
||||
role: {
|
||||
is: {
|
||||
userRoles: {
|
||||
every: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPermissionsByTeamId(teamId, name?: string): Promise<Permission[]> {
|
||||
return prisma.client.permission.findMany({
|
||||
where: {
|
||||
...(name ? { name } : {}),
|
||||
RolePermission: {
|
||||
every: {
|
||||
role: {
|
||||
is: {
|
||||
TeamUser: {
|
||||
every: {
|
||||
teamId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function updatePermission(
|
||||
data: Prisma.PermissionUpdateInput,
|
||||
where: Prisma.PermissionWhereUniqueInput,
|
||||
): Promise<Permission> {
|
||||
return prisma.client.permission.update({
|
||||
data,
|
||||
where,
|
||||
});
|
||||
}
|
||||
|
||||
export async function deletePermission(permissionId: string): Promise<Permission> {
|
||||
return prisma.client.permission.update({
|
||||
data: {
|
||||
isDeleted: true,
|
||||
},
|
||||
where: {
|
||||
id: permissionId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
import { Prisma, Role } from '@prisma/client';
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function createRole(data: {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
}): Promise<Role> {
|
||||
return prisma.client.role.create({
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getRole(where: Prisma.RoleWhereUniqueInput): Promise<Role> {
|
||||
return prisma.client.role.findUnique({
|
||||
where,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getRoles(where: Prisma.RoleWhereInput): Promise<Role[]> {
|
||||
return prisma.client.role.findMany({
|
||||
where,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getRolesByUserId(userId: string): Promise<Role[]> {
|
||||
return prisma.client.role.findMany({
|
||||
where: {
|
||||
userRoles: {
|
||||
every: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateRole(
|
||||
data: Prisma.RoleUpdateInput,
|
||||
where: Prisma.RoleWhereUniqueInput,
|
||||
): Promise<Role> {
|
||||
return prisma.client.role.update({
|
||||
data,
|
||||
where,
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteRole(roleId: string): Promise<Role> {
|
||||
return prisma.client.role.update({
|
||||
data: {
|
||||
isDeleted: true,
|
||||
},
|
||||
where: {
|
||||
id: roleId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
@ -5,14 +5,14 @@ import prisma from 'lib/prisma';
|
|||
export async function createTeamUser(
|
||||
userId: string,
|
||||
teamId: string,
|
||||
roleId: string,
|
||||
role: string,
|
||||
): Promise<TeamUser> {
|
||||
return prisma.client.teamUser.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
userId,
|
||||
teamId,
|
||||
roleId,
|
||||
role,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,9 +36,7 @@ export async function getUser(
|
|||
id: true,
|
||||
username: true,
|
||||
userRole: {
|
||||
include: {
|
||||
role: true,
|
||||
},
|
||||
select: { role: true },
|
||||
},
|
||||
password: includePassword,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -19,7 +19,10 @@ export async function createWebsite(
|
|||
});
|
||||
}
|
||||
|
||||
export async function updateWebsite(websiteId, data: Prisma.WebsiteUpdateInput): Promise<Website> {
|
||||
export async function updateWebsite(
|
||||
websiteId,
|
||||
data: Prisma.WebsiteUpdateInput | Prisma.WebsiteUncheckedUpdateInput,
|
||||
): Promise<Website> {
|
||||
return prisma.client.website.update({
|
||||
where: {
|
||||
id: websiteId,
|
||||
|
|
@ -97,7 +100,9 @@ export async function deleteWebsite(websiteId: string) {
|
|||
});
|
||||
}
|
||||
|
||||
async function deleteWebsiteRelationalQuery(websiteId,): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
|
||||
async function deleteWebsiteRelationalQuery(
|
||||
websiteId,
|
||||
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
|
||||
const { client, transaction } = prisma;
|
||||
|
||||
return transaction([
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue