mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Clean up teams on user delete.
This commit is contained in:
parent
82f0bc3d2b
commit
8684781624
8 changed files with 90 additions and 14 deletions
|
|
@ -67,10 +67,26 @@ export async function updateTeam(
|
|||
});
|
||||
}
|
||||
|
||||
export async function deleteTeam(teamId: string): Promise<Team> {
|
||||
return prisma.client.team.delete({
|
||||
where: {
|
||||
id: teamId,
|
||||
},
|
||||
});
|
||||
export async function deleteTeam(
|
||||
teamId: string,
|
||||
): Promise<Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Team]>> {
|
||||
const { client } = prisma;
|
||||
|
||||
return prisma.transaction([
|
||||
client.teamWebsite.deleteMany({
|
||||
where: {
|
||||
id: teamId,
|
||||
},
|
||||
}),
|
||||
client.teamUser.deleteMany({
|
||||
where: {
|
||||
id: teamId,
|
||||
},
|
||||
}),
|
||||
client.team.delete({
|
||||
where: {
|
||||
id: teamId,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,3 +54,15 @@ export async function deleteTeamUser(teamUserId: string): Promise<TeamUser> {
|
|||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteTeamUserByUserId(
|
||||
userId: string,
|
||||
teamId: string,
|
||||
): Promise<Prisma.BatchPayload> {
|
||||
return prisma.client.teamUser.deleteMany({
|
||||
where: {
|
||||
userId,
|
||||
teamId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,3 +37,11 @@ export async function createTeamWebsite(
|
|||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteTeamWebsite(teamWebsiteId: string): Promise<TeamWebsite> {
|
||||
return prisma.client.teamWebsite.delete({
|
||||
where: {
|
||||
id: teamWebsiteId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Prisma, Team } from '@prisma/client';
|
||||
import cache from 'lib/cache';
|
||||
import prisma from 'lib/prisma';
|
||||
import { Website, User } from 'lib/types';
|
||||
import { Website, User, Roles } from 'lib/types';
|
||||
|
||||
export async function getUser(
|
||||
where: Prisma.UserWhereInput | Prisma.UserWhereUniqueInput,
|
||||
|
|
@ -76,7 +76,7 @@ export async function createUser(data: {
|
|||
id: string;
|
||||
username: string;
|
||||
password: string;
|
||||
role: string;
|
||||
role: Roles;
|
||||
}): Promise<{
|
||||
id: string;
|
||||
username: string;
|
||||
|
|
@ -110,7 +110,17 @@ export async function updateUser(
|
|||
|
||||
export async function deleteUser(
|
||||
userId: string,
|
||||
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Prisma.BatchPayload, User]> {
|
||||
): Promise<
|
||||
[
|
||||
Prisma.BatchPayload,
|
||||
Prisma.BatchPayload,
|
||||
Prisma.BatchPayload,
|
||||
Prisma.BatchPayload,
|
||||
Prisma.BatchPayload,
|
||||
Prisma.BatchPayload,
|
||||
User,
|
||||
]
|
||||
> {
|
||||
const { client } = prisma;
|
||||
const cloudMode = process.env.CLOUD_MODE;
|
||||
|
||||
|
|
@ -132,6 +142,25 @@ export async function deleteUser(
|
|||
client.session.deleteMany({
|
||||
where: { websiteId: { in: websiteIds } },
|
||||
}),
|
||||
client.teamWebsite.deleteMany({
|
||||
where: {
|
||||
website: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
}),
|
||||
client.teamUser.deleteMany({
|
||||
where: {
|
||||
team: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
}),
|
||||
client.team.deleteMany({
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
}),
|
||||
cloudMode
|
||||
? client.website.updateMany({
|
||||
data: {
|
||||
|
|
|
|||
|
|
@ -81,6 +81,11 @@ export async function deleteWebsite(
|
|||
client.session.deleteMany({
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.teamWebsite.deleteMany({
|
||||
where: {
|
||||
websiteId,
|
||||
},
|
||||
}),
|
||||
cloudMode
|
||||
? prisma.client.website.update({
|
||||
data: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue