mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Add Role to TeamUser.
This commit is contained in:
parent
502facd426
commit
d5437c895e
4 changed files with 38 additions and 29 deletions
|
|
@ -40,6 +40,27 @@ export async function getPermissionsByUserId(userId, name?: string): Promise<Per
|
|||
});
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Prisma, TeamUser, UserRole } from '@prisma/client';
|
||||
import { Prisma, TeamUser } from '@prisma/client';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
|
|
@ -6,26 +6,15 @@ export async function createTeamUser(
|
|||
userId: string,
|
||||
teamId: string,
|
||||
roleId: string,
|
||||
): Promise<[TeamUser, UserRole]> {
|
||||
const { client } = prisma;
|
||||
|
||||
return client.$transaction([
|
||||
client.teamUser.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
userId,
|
||||
teamId,
|
||||
},
|
||||
}),
|
||||
client.userRole.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
userId,
|
||||
teamId,
|
||||
roleId,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
): Promise<TeamUser> {
|
||||
return prisma.client.teamUser.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
userId,
|
||||
teamId,
|
||||
roleId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getTeamUser(where: Prisma.TeamUserWhereInput): Promise<TeamUser> {
|
||||
|
|
|
|||
|
|
@ -21,11 +21,10 @@ export async function getUserRoles(where: Prisma.UserRoleWhereInput): Promise<Us
|
|||
});
|
||||
}
|
||||
|
||||
export async function getUserRolesByUserId(userId: string, teamId?: string): Promise<UserRole[]> {
|
||||
export async function getUserRolesByUserId(userId: string): Promise<UserRole[]> {
|
||||
return prisma.client.userRole.findMany({
|
||||
where: {
|
||||
userId,
|
||||
teamId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue