mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Feat/um 62 prisma property names (#1562)
* checkpoint * fix pg schema * fix mysql schema * change property names
This commit is contained in:
parent
36edbe2f4c
commit
78338205a3
65 changed files with 431 additions and 433 deletions
|
|
@ -37,7 +37,7 @@ export default async (req, res) => {
|
|||
// Only admin can change these fields
|
||||
if (currentUserIsAdmin) {
|
||||
data.username = username;
|
||||
data.is_admin = is_admin;
|
||||
data.isAdmin = is_admin;
|
||||
}
|
||||
|
||||
// Check when username changes
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import {
|
|||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { user_id: currentUserId, is_admin: currentUserIsAdmin } = req.auth;
|
||||
const { userId: currentUserId, isAdmin: currentUserIsAdmin } = req.auth;
|
||||
const { current_password, new_password } = req.body;
|
||||
const { id } = req.query;
|
||||
const userId = +id;
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ import { createAccount, getAccountByUsername, getAccounts } from 'queries';
|
|||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { is_admin } = req.auth;
|
||||
const { isAdmin } = req.auth;
|
||||
|
||||
if (!is_admin) {
|
||||
if (!isAdmin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ export default async (req, res) => {
|
|||
const created = await createAccount({
|
||||
username,
|
||||
password: hashPassword(password),
|
||||
account_uuid: account_uuid || uuid(),
|
||||
accountUuid: account_uuid || uuid(),
|
||||
});
|
||||
|
||||
return ok(res, created);
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ export default async (req, res) => {
|
|||
const account = await getAccountByUsername(username);
|
||||
|
||||
if (account && checkPassword(password, account.password)) {
|
||||
const { user_id, username, is_admin } = account;
|
||||
const user = { user_id, username, is_admin };
|
||||
const { id, username, isAdmin, accountUuid } = account;
|
||||
const user = { userId: id, username, isAdmin, accountUuid };
|
||||
const token = createSecureToken(user, secret());
|
||||
|
||||
return ok(res, { token, user });
|
||||
|
|
|
|||
|
|
@ -59,35 +59,35 @@ export default async (req, res) => {
|
|||
await useSession(req, res);
|
||||
|
||||
const {
|
||||
session: { website_id, session },
|
||||
session: { websiteId, session },
|
||||
} = req;
|
||||
|
||||
const { type, payload } = getJsonBody(req);
|
||||
|
||||
let { url, referrer, event_name, event_data } = payload;
|
||||
let { url, referrer, eventName, eventData } = payload;
|
||||
|
||||
if (process.env.REMOVE_TRAILING_SLASH) {
|
||||
url = url.replace(/\/$/, '');
|
||||
}
|
||||
|
||||
const event_uuid = uuid();
|
||||
const eventUuid = uuid();
|
||||
|
||||
if (type === 'pageview') {
|
||||
await savePageView(website_id, { session, url, referrer });
|
||||
await savePageView(websiteId, { session, url, referrer });
|
||||
} else if (type === 'event') {
|
||||
await saveEvent(website_id, {
|
||||
await saveEvent(websiteId, {
|
||||
session,
|
||||
event_uuid,
|
||||
eventUuid,
|
||||
url,
|
||||
event_name,
|
||||
event_data,
|
||||
eventName,
|
||||
eventData,
|
||||
});
|
||||
} else {
|
||||
return badRequest(res);
|
||||
}
|
||||
|
||||
const token = createToken(
|
||||
{ website_id, session_id: session.session_id, session_uuid: session.session_uuid },
|
||||
{ websiteId, sessionId: session.sessionId, sessionUuid: session.sessionUuid },
|
||||
secret(),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ export default async (req, res) => {
|
|||
await useAuth(req, res);
|
||||
|
||||
if (req.method === 'GET') {
|
||||
const { user_id } = req.auth;
|
||||
const { userId } = req.auth;
|
||||
|
||||
const websites = await getUserWebsites(user_id);
|
||||
const ids = websites.map(({ website_id }) => website_id);
|
||||
const websites = await getUserWebsites(userId);
|
||||
const ids = websites.map(({ id }) => id);
|
||||
const token = createToken({ websites: ids }, secret());
|
||||
const data = await getRealtimeData(ids, subMinutes(new Date(), 30));
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ export default async (req, res) => {
|
|||
const website = await getWebsiteByShareId(id);
|
||||
|
||||
if (website) {
|
||||
const websiteId = website.website_id;
|
||||
const token = createToken({ website_id: websiteId }, secret());
|
||||
const websiteId = website.websiteId;
|
||||
const token = createToken({ websiteId: websiteId }, secret());
|
||||
|
||||
return ok(res, { websiteId, token });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ export default async (req, res) => {
|
|||
|
||||
const events = await getEventMetrics(websiteId, startDate, endDate, tz, unit, {
|
||||
url,
|
||||
event_name,
|
||||
eventName: event_name,
|
||||
});
|
||||
|
||||
return ok(res, events);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { methodNotAllowed, ok, unauthorized, getRandomChars } from 'next-basics';
|
||||
import { deleteWebsite, getAccount, getWebsite, updateWebsite } from 'queries';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
|
|
@ -8,7 +8,7 @@ export default async (req, res) => {
|
|||
const { id } = req.query;
|
||||
|
||||
const websiteId = +id;
|
||||
const where = validate(id) ? { website_uuid: id } : { website_id: +id };
|
||||
const where = validate(id) ? { websiteUuid: id } : { id: +id };
|
||||
|
||||
if (req.method === 'GET') {
|
||||
await useCors(req, res);
|
||||
|
|
@ -25,17 +25,19 @@ export default async (req, res) => {
|
|||
if (req.method === 'POST') {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { is_admin: currentUserIsAdmin, user_id: currentUserId, account_uuid } = req.auth;
|
||||
const { name, domain, owner, share_id } = req.body;
|
||||
const { isAdmin: currentUserIsAdmin, userId: currentUserId, accountUuid } = req.auth;
|
||||
const { name, domain, owner, enable_share_url } = req.body;
|
||||
let account;
|
||||
|
||||
if (account_uuid) {
|
||||
account = await getAccount({ account_uuid });
|
||||
if (accountUuid) {
|
||||
account = await getAccount({ accountUuid });
|
||||
}
|
||||
|
||||
const website = await getWebsite(where);
|
||||
|
||||
if (website.user_id !== currentUserId && !currentUserIsAdmin) {
|
||||
const shareId = enable_share_url ? website.shareId || getRandomChars(8) : null;
|
||||
|
||||
if (website.userId !== currentUserId && !currentUserIsAdmin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
|
|
@ -43,8 +45,8 @@ export default async (req, res) => {
|
|||
{
|
||||
name,
|
||||
domain,
|
||||
share_id: share_id || null,
|
||||
user_id: account ? account.id : +owner,
|
||||
shareId: shareId,
|
||||
userId: account ? account.id : +owner,
|
||||
},
|
||||
where,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ export default async (req, res) => {
|
|||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { id, start_at, end_at, url, referrer, os, browser, device, country } = req.query;
|
||||
const { website_id, start_at, end_at, url, referrer, os, browser, device, country } = req.query;
|
||||
|
||||
const websiteId = +id;
|
||||
const websiteId = +website_id;
|
||||
const startDate = new Date(+start_at);
|
||||
const endDate = new Date(+end_at);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,44 +6,41 @@ import { uuid } from 'lib/crypto';
|
|||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { user_id: current_user_id, is_admin, account_uuid } = req.auth;
|
||||
const { userId: currentUserId, isAdmin, accountUuid } = req.auth;
|
||||
const { user_id, include_all } = req.query;
|
||||
let account;
|
||||
|
||||
if (account_uuid) {
|
||||
account = await getAccount({ account_uuid });
|
||||
if (accountUuid) {
|
||||
account = await getAccount({ accountUuid: accountUuid });
|
||||
}
|
||||
|
||||
const userId = account ? account.user_id : +user_id;
|
||||
const userId = account ? account.id : +user_id;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (userId && userId !== current_user_id && !is_admin) {
|
||||
if (userId && userId !== currentUserId && !isAdmin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const websites =
|
||||
is_admin && include_all
|
||||
isAdmin && include_all
|
||||
? await getAllWebsites()
|
||||
: await getUserWebsites(userId || current_user_id);
|
||||
: await getUserWebsites(userId || currentUserId);
|
||||
|
||||
return ok(res, websites);
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { is_admin: currentUserIsAdmin, user_id: currentUserId } = req.auth;
|
||||
const { name, domain, owner, enable_share_url } = req.body;
|
||||
|
||||
const website_owner = account ? account.user_id : +owner;
|
||||
const website_owner = account ? account.id : +owner;
|
||||
|
||||
if (website_owner !== currentUserId && !currentUserIsAdmin) {
|
||||
if (website_owner !== currentUserId && !isAdmin) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const website_uuid = uuid();
|
||||
const share_id = enable_share_url ? getRandomChars(8) : null;
|
||||
const website = await createWebsite(website_owner, { website_uuid, name, domain, share_id });
|
||||
const websiteUuid = uuid();
|
||||
const shareId = enable_share_url ? getRandomChars(8) : null;
|
||||
const website = await createWebsite(website_owner, { websiteUuid, name, domain, shareId });
|
||||
|
||||
return ok(res, website);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export default function ConsolePage({ enabled }) {
|
|||
const { loading } = useRequireLogin();
|
||||
const { user } = useUser();
|
||||
|
||||
if (loading || !enabled || !user?.is_admin) {
|
||||
if (loading || !enabled || !user?.isAdmin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue