mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Fixed team website create.
This commit is contained in:
parent
e971f2533d
commit
d9670f10a4
8
src/app/(main)/websites/Websites.tsx
Normal file
8
src/app/(main)/websites/Websites.tsx
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
'use client';
|
||||||
|
import WebsitesDataTable from '../settings/websites/WebsitesDataTable';
|
||||||
|
|
||||||
|
export function Websites({ teamId, userId }: { teamId: string; userId: string }) {
|
||||||
|
return <WebsitesDataTable teamId={teamId} userId={userId} allowEdit={false} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Websites;
|
@ -1,12 +0,0 @@
|
|||||||
'use client';
|
|
||||||
import WebsitesDataTable from '../settings/websites/WebsitesDataTable';
|
|
||||||
import { useLogin } from 'components/hooks';
|
|
||||||
|
|
||||||
export function WebsitesBrowse({ teamId, userId }: { teamId: string; userId: string }) {
|
|
||||||
const { user } = useLogin();
|
|
||||||
const allowEdit = !process.env.cloudMode;
|
|
||||||
|
|
||||||
return <WebsitesDataTable teamId={teamId} userId={userId || user.id} allowEdit={allowEdit} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default WebsitesBrowse;
|
|
@ -1,12 +1,12 @@
|
|||||||
import WebsitesHeader from 'app/(main)/settings/websites/WebsitesHeader';
|
import WebsitesHeader from 'app/(main)/settings/websites/WebsitesHeader';
|
||||||
import WebsitesBrowse from './WebsitesBrowse';
|
import Websites from './Websites';
|
||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
|
|
||||||
export default function WebsitesPage({ params: { teamId, userId } }) {
|
export default function WebsitesPage({ params: { teamId, userId } }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WebsitesHeader teamId={teamId} showActions={false} />
|
<WebsitesHeader teamId={teamId} />
|
||||||
<WebsitesBrowse teamId={teamId} userId={userId} />
|
<Websites teamId={teamId} userId={userId} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { ok } from 'next-basics';
|
import { ok } from 'next-basics';
|
||||||
import { CURRENT_VERSION, TELEMETRY_PIXEL } from 'lib/constants';
|
import { CURRENT_VERSION, TELEMETRY_PIXEL } from 'lib/constants';
|
||||||
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
|
||||||
export default function handler(req, res) {
|
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
res.setHeader('content-type', 'text/javascript');
|
res.setHeader('content-type', 'text/javascript');
|
||||||
|
|
@ -1,12 +1,11 @@
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
import { canCreateTeamWebsite, canViewTeam } from 'lib/auth';
|
import { canViewTeam } from 'lib/auth';
|
||||||
import { useAuth, useValidate } from 'lib/middleware';
|
import { useAuth, useValidate } from 'lib/middleware';
|
||||||
import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';
|
import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';
|
||||||
import { pageInfo } from 'lib/schema';
|
import { pageInfo } from 'lib/schema';
|
||||||
import { NextApiResponse } from 'next';
|
import { NextApiResponse } from 'next';
|
||||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
import { ok, unauthorized } from 'next-basics';
|
||||||
import { createWebsite, getTeamWebsites } from 'queries';
|
import { getTeamWebsites } from 'queries';
|
||||||
import { uuid } from 'lib/crypto';
|
|
||||||
|
|
||||||
export interface TeamWebsiteRequestQuery extends SearchFilter {
|
export interface TeamWebsiteRequestQuery extends SearchFilter {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
@ -54,18 +53,4 @@ export default async (
|
|||||||
|
|
||||||
return ok(res, websites);
|
return ok(res, websites);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.method === 'POST') {
|
|
||||||
if (!(await canCreateTeamWebsite(req.auth, teamId))) {
|
|
||||||
return unauthorized(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { name, domain, shareId } = req.body;
|
|
||||||
|
|
||||||
const website = await createWebsite({ id: uuid(), name, domain, shareId });
|
|
||||||
|
|
||||||
return ok(res, website);
|
|
||||||
}
|
|
||||||
|
|
||||||
return methodNotAllowed(res);
|
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { canCreateWebsite } from 'lib/auth';
|
import { canCreateTeamWebsite, canCreateWebsite } from 'lib/auth';
|
||||||
import { uuid } from 'lib/crypto';
|
import { uuid } from 'lib/crypto';
|
||||||
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
||||||
import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';
|
import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';
|
||||||
@ -15,6 +15,7 @@ export interface WebsitesRequestBody {
|
|||||||
name: string;
|
name: string;
|
||||||
domain: string;
|
domain: string;
|
||||||
shareId: string;
|
shareId: string;
|
||||||
|
teamId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
@ -25,6 +26,7 @@ const schema = {
|
|||||||
name: yup.string().max(100).required(),
|
name: yup.string().max(100).required(),
|
||||||
domain: yup.string().max(500).required(),
|
domain: yup.string().max(500).required(),
|
||||||
shareId: yup.string().max(50).nullable(),
|
shareId: yup.string().max(50).nullable(),
|
||||||
|
teamId: yup.string().nullable(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -49,9 +51,12 @@ export default async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
const { name, domain, shareId } = req.body;
|
const { name, domain, shareId, teamId } = req.body;
|
||||||
|
|
||||||
if (!(await canCreateWebsite(req.auth))) {
|
if (
|
||||||
|
(teamId && !(await canCreateTeamWebsite(req.auth, teamId))) ||
|
||||||
|
!(await canCreateWebsite(req.auth))
|
||||||
|
) {
|
||||||
return unauthorized(res);
|
return unauthorized(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,9 +65,12 @@ export default async (
|
|||||||
name,
|
name,
|
||||||
domain,
|
domain,
|
||||||
shareId,
|
shareId,
|
||||||
|
teamId,
|
||||||
};
|
};
|
||||||
|
|
||||||
data.userId = userId;
|
if (!teamId) {
|
||||||
|
data.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
const website = await createWebsite(data);
|
const website = await createWebsite(data);
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ export async function createWebsite(
|
|||||||
.create({
|
.create({
|
||||||
data,
|
data,
|
||||||
})
|
})
|
||||||
.then(async data => {
|
.then(async (data: { id: any }) => {
|
||||||
if (cache.enabled) {
|
if (cache.enabled) {
|
||||||
await cache.storeWebsite(data);
|
await cache.storeWebsite(data);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user