mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 08:07:12 +01:00
Updated roles and permissions logic.
This commit is contained in:
parent
4eb3140e43
commit
b57ecf33e6
63 changed files with 432 additions and 546 deletions
|
|
@ -1,14 +1,14 @@
|
|||
import { Team } from '@prisma/client';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { NextApiRequestQueryBody } from 'lib/types';
|
||||
import { canCreateTeam } from 'lib/auth';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { createTeam, getTeam, getTeamsByUserId } from 'queries';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { createTeam, getUserTeams } from 'queries';
|
||||
|
||||
export interface TeamsRequestBody {
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
|
|
@ -22,27 +22,22 @@ export default async (
|
|||
} = req.auth;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
const teams = await getTeamsByUserId(userId);
|
||||
const teams = await getUserTeams(userId);
|
||||
|
||||
return ok(res, teams);
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
if (await canCreateTeam(userId)) {
|
||||
if (!(await canCreateTeam(userId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { name } = req.body;
|
||||
|
||||
const team = await getTeam({ name });
|
||||
|
||||
if (team) {
|
||||
return badRequest(res, 'Team already exists');
|
||||
}
|
||||
|
||||
const created = await createTeam({
|
||||
id: uuid(),
|
||||
name,
|
||||
userId,
|
||||
});
|
||||
|
||||
return ok(res, created);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue