mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-22 18:00:17 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
0c910f2abd
@ -1,20 +1,25 @@
|
||||
import PageHeader from 'components/layout/PageHeader';
|
||||
import { Icon, Icons, Text } from 'react-basics';
|
||||
import { useMessages, useTeamUrl } from 'components/hooks';
|
||||
import { useLogin, useMessages, useTeamUrl } from 'components/hooks';
|
||||
import LinkButton from 'components/common/LinkButton';
|
||||
import { ROLES } from 'lib/constants';
|
||||
|
||||
export function ReportsHeader() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { renderTeamUrl } = useTeamUrl();
|
||||
const { user } = useLogin();
|
||||
const canEdit = user.role !== ROLES.viewOnly;
|
||||
|
||||
return (
|
||||
<PageHeader title={formatMessage(labels.reports)}>
|
||||
{canEdit && (
|
||||
<LinkButton href={renderTeamUrl('/reports/create')} variant="primary">
|
||||
<Icon>
|
||||
<Icons.Plus />
|
||||
</Icon>
|
||||
<Text>{formatMessage(labels.createReport)}</Text>
|
||||
</LinkButton>
|
||||
)}
|
||||
</PageHeader>
|
||||
);
|
||||
}
|
||||
|
@ -11,9 +11,9 @@ export function TeamMembersPage({ teamId }: { teamId: string }) {
|
||||
const { user } = useLogin();
|
||||
const { formatMessage, labels } = useMessages();
|
||||
|
||||
const canEdit = team?.teamUser?.find(
|
||||
({ userId, role }) => role === ROLES.teamOwner && userId === user.id,
|
||||
);
|
||||
const canEdit =
|
||||
team?.teamUser?.find(({ userId, role }) => role === ROLES.teamOwner && userId === user.id) &&
|
||||
user.role !== ROLES.viewOnly;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -15,9 +15,9 @@ export function TeamDetails({ teamId }: { teamId: string }) {
|
||||
const { user } = useLogin();
|
||||
const [tab, setTab] = useState('details');
|
||||
|
||||
const canEdit = !!team?.teamUser?.find(
|
||||
({ userId, role }) => role === ROLES.teamOwner && userId === user.id,
|
||||
);
|
||||
const canEdit =
|
||||
!!team?.teamUser?.find(({ userId, role }) => role === ROLES.teamOwner && userId === user.id) &&
|
||||
user.role !== ROLES.viewOnly;
|
||||
|
||||
return (
|
||||
<Flexbox direction="column">
|
||||
|
@ -12,16 +12,17 @@ export function TeamWebsitesPage({ teamId }: { teamId: string }) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { user } = useLogin();
|
||||
|
||||
const allowEdit = !!team?.teamUser?.find(
|
||||
const canEdit =
|
||||
!!team?.teamUser?.find(
|
||||
({ userId, role }) => userId === user.id && role !== ROLES.teamViewOnly,
|
||||
);
|
||||
) && user.role !== ROLES.viewOnly;
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={formatMessage(labels.websites)}>
|
||||
{allowEdit && <WebsiteAddButton teamId={teamId} />}
|
||||
{canEdit && <WebsiteAddButton teamId={teamId} />}
|
||||
</PageHeader>
|
||||
<TeamWebsitesDataTable teamId={teamId} allowEdit={allowEdit} />
|
||||
<TeamWebsitesDataTable teamId={teamId} allowEdit={canEdit} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -13,12 +13,15 @@ export function TeamWebsitesTable({
|
||||
allowEdit?: boolean;
|
||||
}) {
|
||||
const { user } = useLogin();
|
||||
|
||||
const { formatMessage, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<GridTable data={data}>
|
||||
<GridColumn name="name" label={formatMessage(labels.name)} />
|
||||
<GridColumn name="domain" label={formatMessage(labels.domain)} />
|
||||
<GridColumn name="createdBy" label={formatMessage(labels.createdBy)}>
|
||||
{row => row?.createUser?.username}
|
||||
</GridColumn>
|
||||
<GridColumn name="action" label=" " alignment="end">
|
||||
{row => {
|
||||
const { id: websiteId } = row;
|
||||
|
@ -1,11 +1,16 @@
|
||||
'use client';
|
||||
import { useLogin } from 'components/hooks';
|
||||
import WebsitesDataTable from './WebsitesDataTable';
|
||||
import WebsitesHeader from './WebsitesHeader';
|
||||
import { ROLES } from 'lib/constants';
|
||||
|
||||
export default function WebsitesSettingsPage({ teamId }: { teamId: string }) {
|
||||
const { user } = useLogin();
|
||||
const canCreate = user.role !== ROLES.viewOnly;
|
||||
|
||||
return (
|
||||
<>
|
||||
<WebsitesHeader teamId={teamId} />
|
||||
<WebsitesHeader teamId={teamId} allowCreate={canCreate} />
|
||||
<WebsitesDataTable teamId={teamId} />
|
||||
</>
|
||||
);
|
||||
|
@ -1,14 +1,11 @@
|
||||
'use client';
|
||||
import WebsitesHeader from 'app/(main)/settings/websites/WebsitesHeader';
|
||||
import WebsitesDataTable from 'app/(main)/settings/websites/WebsitesDataTable';
|
||||
import { useLogin } from 'components/hooks';
|
||||
|
||||
export default function WebsitesPage({ teamId }: { teamId: string; userId: string }) {
|
||||
const { user } = useLogin();
|
||||
|
||||
export default function WebsitesPage({ teamId }: { teamId: string }) {
|
||||
return (
|
||||
<>
|
||||
<WebsitesHeader teamId={teamId} allowCreate={user.role !== 'view-only'} />
|
||||
<WebsitesHeader teamId={teamId} allowCreate={false} />
|
||||
<WebsitesDataTable teamId={teamId} allowEdit={false} />
|
||||
</>
|
||||
);
|
||||
|
@ -26,6 +26,7 @@ export const labels = defineMessages({
|
||||
myWebsites: { id: 'label.my-websites', defaultMessage: 'My websites' },
|
||||
teamWebsites: { id: 'label.team-websites', defaultMessage: 'Team websites' },
|
||||
created: { id: 'label.created', defaultMessage: 'Created' },
|
||||
createdBy: { id: 'label.created-by', defaultMessage: 'Created By' },
|
||||
edit: { id: 'label.edit', defaultMessage: 'Edit' },
|
||||
name: { id: 'label.name', defaultMessage: 'Name' },
|
||||
member: { id: 'label.member', defaultMessage: 'Member' },
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { isValid, parseISO } from 'date-fns';
|
||||
import { isValid } from 'date-fns';
|
||||
import { DATA_TYPE } from './constants';
|
||||
import { DynamicDataType } from './types';
|
||||
|
||||
@ -28,7 +28,7 @@ export function flattenJSON(
|
||||
export function getDataType(value: any): string {
|
||||
let type: string = typeof value;
|
||||
|
||||
if ((type === 'string' && isValid(value)) || isValid(parseISO(value))) {
|
||||
if ((type === 'string' && isValid(value)) || isValid(new Date(value))) {
|
||||
type = 'date';
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { createReport, getReports } from 'queries';
|
||||
import * as yup from 'yup';
|
||||
import { canViewTeam, canViewWebsite } from 'lib/auth';
|
||||
import { canUpdateWebsite, canViewTeam, canViewWebsite } from 'lib/auth';
|
||||
|
||||
export interface ReportRequestBody {
|
||||
websiteId: string;
|
||||
@ -89,6 +89,10 @@ export default async (
|
||||
if (req.method === 'POST') {
|
||||
const { websiteId, type, name, description, parameters } = req.body;
|
||||
|
||||
if (!(await canUpdateWebsite(req.auth, websiteId))) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const result = await createReport({
|
||||
id: uuid(),
|
||||
userId,
|
||||
|
@ -62,6 +62,7 @@ export default async (
|
||||
|
||||
const data: any = {
|
||||
id: uuid(),
|
||||
createdBy: userId,
|
||||
name,
|
||||
domain,
|
||||
shareId,
|
||||
|
@ -87,7 +87,7 @@ export async function getTeamWebsites(
|
||||
teamId,
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
createUser: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
|
Loading…
Reference in New Issue
Block a user