mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Feat/um 114 roles and permissions (#1683)
* Auth checkpoint. * Merge branch 'dev' into feat/um-114-roles-and-permissions
This commit is contained in:
parent
a4e80ca3e5
commit
06bebadbb9
27 changed files with 331 additions and 482 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { Website } from 'interface/api/models';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { canViewWebsite, canUpdateWebsite } from 'lib/auth';
|
||||
import { canViewWebsite, canUpdateWebsite, canDeleteWebsite } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, serverError, unauthorized } from 'next-basics';
|
||||
|
|
@ -23,10 +23,13 @@ export default async (
|
|||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
const {
|
||||
user: { id: userId },
|
||||
} = req.auth;
|
||||
const { id: websiteId } = req.query;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (!(await canViewWebsite(req.auth.user.id, websiteId))) {
|
||||
if (!(await canViewWebsite(userId, websiteId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +39,7 @@ export default async (
|
|||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
if (!(await canUpdateWebsite(req.auth.user.id, websiteId))) {
|
||||
if (!(await canUpdateWebsite(userId, websiteId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +57,10 @@ export default async (
|
|||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
if (!(await canDeleteWebsite(userId, websiteId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
await deleteWebsite(websiteId);
|
||||
|
||||
return ok(res);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue