mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Api work for remove user.
This commit is contained in:
parent
f4f657b666
commit
7b07de7a98
4 changed files with 15 additions and 45 deletions
|
|
@ -1,28 +0,0 @@
|
|||
import { canDeleteTeamUser } from 'lib/auth';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { NextApiRequestQueryBody } from 'lib/types';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { deleteTeamUser } from 'queries/admin/teamUser';
|
||||
|
||||
export interface TeamUserRequestQuery {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export default async (req: NextApiRequestQueryBody<TeamUserRequestQuery>, res: NextApiResponse) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { id: teamUserId } = req.query;
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
if (!(await canDeleteTeamUser(req.auth, teamUserId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const websites = await deleteTeamUser(teamUserId);
|
||||
|
||||
return ok(res, websites);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { NextApiRequestQueryBody } from 'lib/types';
|
||||
import { canUpdateTeam, canViewTeam } from 'lib/auth';
|
||||
import { canDeleteTeamUser, canUpdateTeam, canViewTeam } from 'lib/auth';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
|
|
@ -12,7 +12,7 @@ export interface TeamUserRequestQuery {
|
|||
export interface TeamUserRequestBody {
|
||||
email: string;
|
||||
roleId: string;
|
||||
teamUserId?: string;
|
||||
userId?: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
|
|
@ -53,12 +53,13 @@ export default async (
|
|||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
if (await canUpdateTeam(req.auth, teamId)) {
|
||||
const { userId } = req.body;
|
||||
|
||||
if (await canDeleteTeamUser(req.auth, teamId, userId)) {
|
||||
return unauthorized(res, 'You must be the owner of this team.');
|
||||
}
|
||||
const { teamUserId } = req.body;
|
||||
|
||||
await deleteTeamUser(teamUserId);
|
||||
await deleteTeamUser(teamId, userId);
|
||||
|
||||
return ok(res);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue