mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-24 18:26:20 +01:00
Merge branch 'dev' into feat/um-76-turn-off-ui
This commit is contained in:
commit
1d808f1b1f
@ -1,6 +1,5 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { defineMessages, useIntl } from 'react-intl';
|
import { defineMessages, useIntl } from 'react-intl';
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import Page from 'components/layout/Page';
|
import Page from 'components/layout/Page';
|
||||||
import PageHeader from 'components/layout/PageHeader';
|
import PageHeader from 'components/layout/PageHeader';
|
||||||
import WebsiteList from 'components/pages/WebsiteList';
|
import WebsiteList from 'components/pages/WebsiteList';
|
||||||
@ -16,10 +15,7 @@ const messages = defineMessages({
|
|||||||
more: { id: 'label.more', defaultMessage: 'More' },
|
more: { id: 'label.more', defaultMessage: 'More' },
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function Dashboard() {
|
export default function Dashboard({ userId }) {
|
||||||
const router = useRouter();
|
|
||||||
const { id } = router.query;
|
|
||||||
const userId = id?.[0];
|
|
||||||
const dashboard = useDashboard();
|
const dashboard = useDashboard();
|
||||||
const { showCharts, limit, editing } = dashboard;
|
const { showCharts, limit, editing } = dashboard;
|
||||||
const [max, setMax] = useState(limit);
|
const [max, setMax] = useState(limit);
|
||||||
|
@ -29,13 +29,15 @@ export default function AccountSettings() {
|
|||||||
|
|
||||||
const Checkmark = ({ isAdmin }) => (isAdmin ? <Icon icon={<Check />} size="medium" /> : null);
|
const Checkmark = ({ isAdmin }) => (isAdmin ? <Icon icon={<Check />} size="medium" /> : null);
|
||||||
|
|
||||||
const DashboardLink = row => (
|
const DashboardLink = row => {
|
||||||
<Link href={`/dashboard/${row.userId}/${row.username}`}>
|
return (
|
||||||
<a>
|
<Link href={`/dashboard/${row.accountUuid}/${row.username}`}>
|
||||||
<Icon icon={<LinkIcon />} />
|
<a>
|
||||||
</a>
|
<Icon icon={<LinkIcon />} />
|
||||||
</Link>
|
</a>
|
||||||
);
|
</Link>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const Buttons = row => (
|
const Buttons = row => (
|
||||||
<ButtonLayout align="right">
|
<ButtonLayout align="right">
|
||||||
|
@ -21,9 +21,9 @@ export default async (req, res) => {
|
|||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
const { username, password, account_uuid } = req.body;
|
const { username, password, account_uuid } = req.body;
|
||||||
|
|
||||||
const accountByUsername = await getAccount({ username });
|
const account = await getAccount({ username });
|
||||||
|
|
||||||
if (accountByUsername) {
|
if (account) {
|
||||||
return badRequest(res, 'Account already exists');
|
return badRequest(res, 'Account already exists');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ export default async (req, res) => {
|
|||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const { userId } = req.auth;
|
const { userId } = req.auth;
|
||||||
|
|
||||||
const websites = await getUserWebsites(userId);
|
const websites = await getUserWebsites({ userId });
|
||||||
const ids = websites.map(({ websiteUuid }) => websiteUuid);
|
const ids = websites.map(({ websiteUuid }) => websiteUuid);
|
||||||
const token = createToken({ websites: ids }, secret());
|
const token = createToken({ websites: ids }, secret());
|
||||||
const data = await getRealtimeData(ids, subMinutes(new Date(), 30));
|
const data = await getRealtimeData(ids, subMinutes(new Date(), 30));
|
||||||
|
@ -6,15 +6,16 @@ import { uuid } from 'lib/crypto';
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
|
|
||||||
const { userId: currentUserId, isAdmin, accountUuid } = req.auth;
|
|
||||||
const { user_id, include_all } = req.query;
|
const { user_id, include_all } = req.query;
|
||||||
|
const { userId: currentUserId, isAdmin } = req.auth;
|
||||||
|
const accountUuid = user_id || req.auth.accountUuid;
|
||||||
let account;
|
let account;
|
||||||
|
|
||||||
if (accountUuid) {
|
if (accountUuid) {
|
||||||
account = await getAccount({ accountUuid: accountUuid });
|
account = await getAccount({ accountUuid });
|
||||||
}
|
}
|
||||||
|
|
||||||
const userId = account ? account.id : +user_id;
|
const userId = account ? account.id : user_id;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
if (userId && userId !== currentUserId && !isAdmin) {
|
if (userId && userId !== currentUserId && !isAdmin) {
|
||||||
@ -24,7 +25,7 @@ export default async (req, res) => {
|
|||||||
const websites =
|
const websites =
|
||||||
isAdmin && include_all
|
isAdmin && include_all
|
||||||
? await getAllWebsites()
|
? await getAllWebsites()
|
||||||
: await getUserWebsites(userId || currentUserId);
|
: await getUserWebsites({ userId: account.id });
|
||||||
|
|
||||||
return ok(res, websites);
|
return ok(res, websites);
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,27 @@ import React from 'react';
|
|||||||
import Layout from 'components/layout/Layout';
|
import Layout from 'components/layout/Layout';
|
||||||
import Dashboard from 'components/pages/Dashboard';
|
import Dashboard from 'components/pages/Dashboard';
|
||||||
import useRequireLogin from 'hooks/useRequireLogin';
|
import useRequireLogin from 'hooks/useRequireLogin';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
|
import useUser from 'hooks/useUser';
|
||||||
|
|
||||||
export default function DashboardPage() {
|
export default function DashboardPage() {
|
||||||
|
const {
|
||||||
|
query: { id },
|
||||||
|
isReady,
|
||||||
|
asPath,
|
||||||
|
} = useRouter();
|
||||||
const { loading } = useRequireLogin();
|
const { loading } = useRequireLogin();
|
||||||
|
const user = useUser();
|
||||||
|
|
||||||
if (loading) {
|
if (!user || !isReady || loading) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const userId = id?.[0];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<Dashboard />
|
<Dashboard key={asPath} userId={user.id || userId} />
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ export async function getAccounts() {
|
|||||||
isAdmin: true,
|
isAdmin: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
updatedAt: true,
|
updatedAt: true,
|
||||||
|
accountUuid: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
import prisma from 'lib/prisma';
|
import prisma from 'lib/prisma';
|
||||||
|
|
||||||
export async function getUserWebsites(userId) {
|
export async function getUserWebsites(where) {
|
||||||
return prisma.client.website.findMany({
|
return prisma.client.website.findMany({
|
||||||
where: {
|
where,
|
||||||
userId,
|
|
||||||
},
|
|
||||||
orderBy: {
|
orderBy: {
|
||||||
name: 'asc',
|
name: 'asc',
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user