mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Allow user to change admin username.
This commit is contained in:
parent
e31181c676
commit
faf6438852
5 changed files with 21 additions and 14 deletions
26
pages/api/websites/index.js
Normal file
26
pages/api/websites/index.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { getAllWebsites, getUserWebsites } from 'lib/queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { ok, methodNotAllowed, unauthorized } from 'lib/response';
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { user_id: current_user_id, is_admin } = req.auth;
|
||||
const { user_id, include_all } = req.query;
|
||||
const userId = +user_id;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (userId && userId !== current_user_id && !is_admin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const websites =
|
||||
is_admin && include_all
|
||||
? await getAllWebsites()
|
||||
: await getUserWebsites(userId || current_user_id);
|
||||
|
||||
return ok(res, websites);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue