mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-03 15:47:30 +01:00
Get account by uuid for cloud operations.
This commit is contained in:
parent
d784b2a8db
commit
f3135ee867
@ -19,13 +19,7 @@ export default async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
await useAuth(req, res);
|
const { username, password, account_uuid } = req.body;
|
||||||
|
|
||||||
if (!req.auth.is_admin) {
|
|
||||||
return unauthorized(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { username, password } = req.body;
|
|
||||||
|
|
||||||
const accountByUsername = await getAccountByUsername(username);
|
const accountByUsername = await getAccountByUsername(username);
|
||||||
|
|
||||||
@ -36,7 +30,7 @@ export default async (req, res) => {
|
|||||||
const created = await createAccount({
|
const created = await createAccount({
|
||||||
username,
|
username,
|
||||||
password: hashPassword(password),
|
password: hashPassword(password),
|
||||||
account_uuid: uuid(),
|
account_uuid: account_uuid || uuid(),
|
||||||
});
|
});
|
||||||
|
|
||||||
return ok(res, created);
|
return ok(res, created);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { createWebsite, getAllWebsites, getUserWebsites } from 'queries';
|
import { createWebsite, getAccount, getAllWebsites, getUserWebsites } from 'queries';
|
||||||
import { ok, methodNotAllowed, unauthorized, getRandomChars } from 'next-basics';
|
import { ok, methodNotAllowed, unauthorized, getRandomChars } from 'next-basics';
|
||||||
import { useAuth } from 'lib/middleware';
|
import { useAuth } from 'lib/middleware';
|
||||||
import { uuid } from 'lib/crypto';
|
import { uuid } from 'lib/crypto';
|
||||||
@ -6,9 +6,15 @@ import { uuid } from 'lib/crypto';
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
|
|
||||||
const { user_id: current_user_id, is_admin } = req.auth;
|
const { user_id: current_user_id, is_admin, account_uuid } = req.auth;
|
||||||
const { user_id, include_all } = req.query;
|
const { user_id, include_all } = req.query;
|
||||||
const userId = +user_id;
|
let account;
|
||||||
|
|
||||||
|
if (account_uuid) {
|
||||||
|
account = await getAccount({ account_uuid });
|
||||||
|
}
|
||||||
|
|
||||||
|
const userId = account ? account.user_id : +user_id;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (userId && userId !== current_user_id && !is_admin) {
|
if (userId && userId !== current_user_id && !is_admin) {
|
||||||
@ -29,7 +35,7 @@ export default async (req, res) => {
|
|||||||
const { is_admin: currentUserIsAdmin, user_id: currentUserId } = req.auth;
|
const { is_admin: currentUserIsAdmin, user_id: currentUserId } = req.auth;
|
||||||
const { name, domain, owner, enable_share_url } = req.body;
|
const { name, domain, owner, enable_share_url } = req.body;
|
||||||
|
|
||||||
const website_owner = +owner;
|
const website_owner = account ? account.user_id : +owner;
|
||||||
|
|
||||||
if (website_owner !== currentUserId && !currentUserIsAdmin) {
|
if (website_owner !== currentUserId && !currentUserIsAdmin) {
|
||||||
return unauthorized(res);
|
return unauthorized(res);
|
||||||
|
7
queries/admin/account/getAccount.js
Normal file
7
queries/admin/account/getAccount.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import prisma from 'lib/prisma';
|
||||||
|
|
||||||
|
export async function getAccount(where) {
|
||||||
|
return prisma.client.account.findUnique({
|
||||||
|
where,
|
||||||
|
});
|
||||||
|
}
|
@ -1,63 +1,31 @@
|
|||||||
import { createAccount } from './admin/account/createAccount';
|
export * from './admin/account/createAccount';
|
||||||
import { deleteAccount } from './admin/account/deleteAccount';
|
export * from './admin/account/deleteAccount';
|
||||||
import { getAccountById } from './admin/account/getAccountById';
|
export * from './admin/account/getAccount';
|
||||||
import { getAccountByUsername } from './admin/account/getAccountByUsername';
|
export * from './admin/account/getAccountById';
|
||||||
import { getAccounts } from './admin/account/getAccounts';
|
export * from './admin/account/getAccountByUsername';
|
||||||
import { updateAccount } from './admin/account/updateAccount';
|
export * from './admin/account/getAccounts';
|
||||||
import { createWebsite } from './admin/website/createWebsite';
|
export * from './admin/account/updateAccount';
|
||||||
import { deleteWebsite } from './admin/website/deleteWebsite';
|
export * from './admin/website/createWebsite';
|
||||||
import { getAllWebsites } from './admin/website/getAllWebsites';
|
export * from './admin/website/deleteWebsite';
|
||||||
import { getUserWebsites } from './admin/website/getUserWebsites';
|
export * from './admin/website/getAllWebsites';
|
||||||
import { getWebsiteById } from './admin/website/getWebsiteById';
|
export * from './admin/website/getUserWebsites';
|
||||||
import { getWebsiteByShareId } from './admin/website/getWebsiteByShareId';
|
export * from './admin/website/getWebsiteById';
|
||||||
import { getWebsiteByUuid } from './admin/website/getWebsiteByUuid';
|
export * from './admin/website/getWebsiteByShareId';
|
||||||
import { resetWebsite } from './admin/website/resetWebsite';
|
export * from './admin/website/getWebsiteByUuid';
|
||||||
import { updateWebsite } from './admin/website/updateWebsite';
|
export * from './admin/website/resetWebsite';
|
||||||
import { getEventMetrics } from './analytics/event/getEventMetrics';
|
export * from './admin/website/updateWebsite';
|
||||||
import { getEvents } from './analytics/event/getEvents';
|
export * from './analytics/event/getEventMetrics';
|
||||||
import { saveEvent } from './analytics/event/saveEvent';
|
export * from './analytics/event/getEvents';
|
||||||
import { getPageviewMetrics } from './analytics/pageview/getPageviewMetrics';
|
export * from './analytics/event/saveEvent';
|
||||||
import { getPageviewParams } from './analytics/pageview/getPageviewParams';
|
export * from './analytics/pageview/getPageviewMetrics';
|
||||||
import { getPageviews } from './analytics/pageview/getPageviews';
|
export * from './analytics/pageview/getPageviewParams';
|
||||||
import { getPageviewStats } from './analytics/pageview/getPageviewStats';
|
export * from './analytics/pageview/getPageviews';
|
||||||
import { savePageView } from './analytics/pageview/savePageView';
|
export * from './analytics/pageview/getPageviewStats';
|
||||||
import { createSession } from './analytics/session/createSession';
|
export * from './analytics/pageview/savePageView';
|
||||||
import { getSessionByUuid } from './analytics/session/getSessionByUuid';
|
export * from './analytics/session/createSession';
|
||||||
import { getSessionMetrics } from './analytics/session/getSessionMetrics';
|
export * from './analytics/session/getSessionByUuid';
|
||||||
import { getSessions } from './analytics/session/getSessions';
|
export * from './analytics/session/getSessionMetrics';
|
||||||
import { getActiveVisitors } from './analytics/stats/getActiveVisitors';
|
export * from './analytics/session/getSessions';
|
||||||
import { getRealtimeData } from './analytics/stats/getRealtimeData';
|
export * from './analytics/stats/getActiveVisitors';
|
||||||
import { getWebsiteStats } from './analytics/stats/getWebsiteStats';
|
export * from './analytics/stats/getRealtimeData';
|
||||||
|
export * from './analytics/stats/getWebsiteStats';
|
||||||
export {
|
|
||||||
createWebsite,
|
|
||||||
deleteWebsite,
|
|
||||||
getAllWebsites,
|
|
||||||
getUserWebsites,
|
|
||||||
getWebsiteById,
|
|
||||||
getWebsiteByShareId,
|
|
||||||
getWebsiteByUuid,
|
|
||||||
resetWebsite,
|
|
||||||
updateWebsite,
|
|
||||||
createAccount,
|
|
||||||
deleteAccount,
|
|
||||||
getAccountById,
|
|
||||||
getAccountByUsername,
|
|
||||||
getAccounts,
|
|
||||||
updateAccount,
|
|
||||||
getEventMetrics,
|
|
||||||
getEvents,
|
|
||||||
saveEvent,
|
|
||||||
getPageviewMetrics,
|
|
||||||
getPageviewParams,
|
|
||||||
getPageviews,
|
|
||||||
getPageviewStats,
|
|
||||||
savePageView,
|
|
||||||
createSession,
|
|
||||||
getSessionByUuid,
|
|
||||||
getSessionMetrics,
|
|
||||||
getSessions,
|
|
||||||
getActiveVisitors,
|
|
||||||
getRealtimeData,
|
|
||||||
getWebsiteStats,
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user