mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
6ef1f2e9f9
22 changed files with 411 additions and 93 deletions
|
|
@ -4,7 +4,7 @@ import { useAuth, useCors } from 'lib/middleware';
|
|||
import { NextApiRequestQueryBody, ReportSearchFilterType, SearchFilter } from 'lib/types';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { createReport, getReportsByWebsiteId } from 'queries';
|
||||
import { createReport, getReportsByUserId, getReportsByWebsiteId } from 'queries';
|
||||
|
||||
export interface ReportsRequestQuery extends SearchFilter<ReportSearchFilterType> {}
|
||||
|
||||
|
|
@ -26,20 +26,14 @@ export default async (
|
|||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
const { websiteId } = req.query;
|
||||
|
||||
const {
|
||||
user: { id: userId },
|
||||
} = req.auth;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (!(websiteId && (await canViewWebsite(req.auth, websiteId)))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { page, filter, pageSize } = req.query;
|
||||
|
||||
const data = await getReportsByWebsiteId(websiteId, {
|
||||
const data = await getReportsByUserId(userId, {
|
||||
page,
|
||||
filter,
|
||||
pageSize: +pageSize || null,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export default async (
|
|||
await useAuth(req, res);
|
||||
|
||||
const { user } = req.auth;
|
||||
const { id: userId, page, filter, pageSize, includeTeams } = req.query;
|
||||
const { id: userId, page, filter, pageSize, includeTeams, onlyTeams } = req.query;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (!user.isAdmin && user.id !== userId) {
|
||||
|
|
@ -33,6 +33,7 @@ export default async (
|
|||
filter,
|
||||
pageSize: +pageSize || null,
|
||||
includeTeams,
|
||||
onlyTeams,
|
||||
});
|
||||
|
||||
return ok(res, websites);
|
||||
|
|
|
|||
38
pages/api/websites/[id]/reports.ts
Normal file
38
pages/api/websites/[id]/reports.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { canViewWebsite } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { NextApiRequestQueryBody, ReportSearchFilterType, SearchFilter } from 'lib/types';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getReportsByWebsiteId } from 'queries';
|
||||
|
||||
export interface ReportsRequestQuery extends SearchFilter<ReportSearchFilterType> {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<ReportsRequestQuery, any>,
|
||||
res: NextApiResponse,
|
||||
) => {
|
||||
await useCors(req, res);
|
||||
await useAuth(req, res);
|
||||
|
||||
const { id: websiteId } = req.query;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (!(websiteId && (await canViewWebsite(req.auth, websiteId)))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { page, filter, pageSize } = req.query;
|
||||
|
||||
const data = await getReportsByWebsiteId(websiteId, {
|
||||
page,
|
||||
filter,
|
||||
pageSize: +pageSize || null,
|
||||
});
|
||||
|
||||
return ok(res, data);
|
||||
}
|
||||
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
13
pages/reports/index.js
Normal file
13
pages/reports/index.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import AppLayout from 'components/layout/AppLayout';
|
||||
import ReportsPage from 'components/pages/reports/ReportsPage';
|
||||
import { useMessages } from 'hooks';
|
||||
|
||||
export default function () {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<AppLayout title={formatMessage(labels.reports)}>
|
||||
<ReportsPage />
|
||||
</AppLayout>
|
||||
);
|
||||
}
|
||||
13
pages/websites/index.js
Normal file
13
pages/websites/index.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import AppLayout from 'components/layout/AppLayout';
|
||||
import WebsitesPage from 'components/pages/websites/WebsitesPage';
|
||||
import useMessages from 'hooks/useMessages';
|
||||
|
||||
export default function () {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<AppLayout title={formatMessage(labels.websites)}>
|
||||
<WebsitesPage />
|
||||
</AppLayout>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue