mirror of
https://github.com/umami-software/umami.git
synced 2026-02-16 18:45:36 +01:00
Add permission checks.
This commit is contained in:
parent
51e2331315
commit
78225691df
20 changed files with 225 additions and 333 deletions
|
|
@ -1,8 +1,10 @@
|
|||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { UmamiApi } from 'lib/constants';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok } from 'next-basics';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { createTeamUser, deleteTeamUser, getUsersByTeamId } from 'queries';
|
||||
|
||||
export interface TeamUserRequestQuery {
|
||||
|
|
@ -23,12 +25,20 @@ export default async (
|
|||
const { id: teamId } = req.query;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (!(await allowQuery(req, UmamiApi.AuthType.Team))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const user = await getUsersByTeamId({ teamId });
|
||||
|
||||
return ok(res, user);
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
if (!(await allowQuery(req, UmamiApi.AuthType.TeamOwner))) {
|
||||
return unauthorized(res, 'You must be the owner of this team.');
|
||||
}
|
||||
|
||||
const { user_id: userId } = req.body;
|
||||
|
||||
const updated = await createTeamUser({ id: uuid(), userId, teamId });
|
||||
|
|
@ -37,6 +47,10 @@ export default async (
|
|||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
if (!(await allowQuery(req, UmamiApi.AuthType.TeamOwner))) {
|
||||
return unauthorized(res, 'You must be the owner of this team.');
|
||||
}
|
||||
|
||||
const { team_user_id } = req.body;
|
||||
|
||||
await deleteTeamUser(team_user_id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue