mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-18 15:23:38 +01:00
Merge pull request #872 from cywio/admin-websites-table
Add owner column to admin website settings table
This commit is contained in:
commit
d8b732026e
@ -1,5 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
import { useSelector } from 'react-redux';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import Link from 'components/common/Link';
|
import Link from 'components/common/Link';
|
||||||
import Table from 'components/common/Table';
|
import Table from 'components/common/Table';
|
||||||
@ -25,6 +26,7 @@ import useFetch from 'hooks/useFetch';
|
|||||||
import styles from './WebsiteSettings.module.css';
|
import styles from './WebsiteSettings.module.css';
|
||||||
|
|
||||||
export default function WebsiteSettings() {
|
export default function WebsiteSettings() {
|
||||||
|
const user = useSelector(state => state.user);
|
||||||
const [editWebsite, setEditWebsite] = useState();
|
const [editWebsite, setEditWebsite] = useState();
|
||||||
const [resetWebsite, setResetWebsite] = useState();
|
const [resetWebsite, setResetWebsite] = useState();
|
||||||
const [deleteWebsite, setDeleteWebsite] = useState();
|
const [deleteWebsite, setDeleteWebsite] = useState();
|
||||||
@ -33,7 +35,9 @@ export default function WebsiteSettings() {
|
|||||||
const [showUrl, setShowUrl] = useState();
|
const [showUrl, setShowUrl] = useState();
|
||||||
const [saved, setSaved] = useState(0);
|
const [saved, setSaved] = useState(0);
|
||||||
const [message, setMessage] = useState();
|
const [message, setMessage] = useState();
|
||||||
const { data } = useFetch(`/api/websites`, {}, [saved]);
|
const { data } = useFetch(`/api/websites` + (user.is_admin ? '?include_all=true' : ''), {}, [
|
||||||
|
saved,
|
||||||
|
]);
|
||||||
|
|
||||||
const Buttons = row => (
|
const Buttons = row => (
|
||||||
<ButtonLayout align="right">
|
<ButtonLayout align="right">
|
||||||
@ -55,15 +59,27 @@ export default function WebsiteSettings() {
|
|||||||
tooltipId={`button-code-${row.website_id}`}
|
tooltipId={`button-code-${row.website_id}`}
|
||||||
onClick={() => setShowCode(row)}
|
onClick={() => setShowCode(row)}
|
||||||
/>
|
/>
|
||||||
<Button icon={<Pen />} size="small" onClick={() => setEditWebsite(row)}>
|
<Button
|
||||||
<FormattedMessage id="label.edit" defaultMessage="Edit" />
|
icon={<Pen />}
|
||||||
</Button>
|
size="small"
|
||||||
<Button icon={<Reset />} size="small" onClick={() => setResetWebsite(row)}>
|
tooltip={<FormattedMessage id="label.edit" defaultMessage="Edit" />}
|
||||||
<FormattedMessage id="label.reset" defaultMessage="Reset" />
|
tooltipId={`button-edit-${row.website_id}`}
|
||||||
</Button>
|
onClick={() => setEditWebsite(row)}
|
||||||
<Button icon={<Trash />} size="small" onClick={() => setDeleteWebsite(row)}>
|
/>
|
||||||
<FormattedMessage id="label.delete" defaultMessage="Delete" />
|
<Button
|
||||||
</Button>
|
icon={<Reset />}
|
||||||
|
size="small"
|
||||||
|
tooltip={<FormattedMessage id="label.reset" defaultMessage="Reset" />}
|
||||||
|
tooltipId={`button-reset-${row.website_id}`}
|
||||||
|
onClick={() => setResetWebsite(row)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
icon={<Trash />}
|
||||||
|
size="small"
|
||||||
|
tooltip={<FormattedMessage id="label.delete" defaultMessage="Delete" />}
|
||||||
|
tooltipId={`button-delete-${row.website_id}`}
|
||||||
|
onClick={() => setDeleteWebsite(row)}
|
||||||
|
/>
|
||||||
</ButtonLayout>
|
</ButtonLayout>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -74,6 +90,30 @@ export default function WebsiteSettings() {
|
|||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const adminColumns = [
|
||||||
|
{
|
||||||
|
key: 'name',
|
||||||
|
label: <FormattedMessage id="label.name" defaultMessage="Name" />,
|
||||||
|
className: 'col-4 col-xl-3',
|
||||||
|
render: DetailsLink,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'domain',
|
||||||
|
label: <FormattedMessage id="label.domain" defaultMessage="Domain" />,
|
||||||
|
className: 'col-4 col-xl-3',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'account',
|
||||||
|
label: <FormattedMessage id="label.owner" defaultMessage="Owner" />,
|
||||||
|
className: 'col-4 col-xl-1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'action',
|
||||||
|
className: classNames(styles.buttons, 'col-12 col-xl-5 pt-2 pt-xl-0'),
|
||||||
|
render: Buttons,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
key: 'name',
|
key: 'name',
|
||||||
@ -137,7 +177,7 @@ export default function WebsiteSettings() {
|
|||||||
<FormattedMessage id="label.add-website" defaultMessage="Add website" />
|
<FormattedMessage id="label.add-website" defaultMessage="Add website" />
|
||||||
</Button>
|
</Button>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<Table columns={columns} rows={data} empty={empty} />
|
<Table columns={user.is_admin ? adminColumns : columns} rows={data} empty={empty} />
|
||||||
{editWebsite && (
|
{editWebsite && (
|
||||||
<Modal title={<FormattedMessage id="label.edit-website" defaultMessage="Edit website" />}>
|
<Modal title={<FormattedMessage id="label.edit-website" defaultMessage="Edit website" />}>
|
||||||
<WebsiteEditForm values={editWebsite} onSave={handleSave} onClose={handleClose} />
|
<WebsiteEditForm values={editWebsite} onSave={handleSave} onClose={handleClose} />
|
||||||
|
@ -115,6 +115,29 @@ export async function getUserWebsites(user_id) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getAllWebsites() {
|
||||||
|
let data = await runQuery(
|
||||||
|
prisma.website.findMany({
|
||||||
|
orderBy: [
|
||||||
|
{
|
||||||
|
user_id: 'asc',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'asc',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
include: {
|
||||||
|
account: {
|
||||||
|
select: {
|
||||||
|
username: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return data.map(i => ({ ...i, account: i.account.username }));
|
||||||
|
}
|
||||||
|
|
||||||
export async function createWebsite(user_id, data) {
|
export async function createWebsite(user_id, data) {
|
||||||
return runQuery(
|
return runQuery(
|
||||||
prisma.website.create({
|
prisma.website.create({
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { getUserWebsites } from 'lib/queries';
|
import { getAllWebsites, getUserWebsites } from 'lib/queries';
|
||||||
import { useAuth } from 'lib/middleware';
|
import { useAuth } from 'lib/middleware';
|
||||||
import { ok, methodNotAllowed, unauthorized } from 'lib/response';
|
import { ok, methodNotAllowed, unauthorized } from 'lib/response';
|
||||||
|
|
||||||
@ -6,7 +6,7 @@ export default async (req, res) => {
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
|
|
||||||
const { user_id: current_user_id, is_admin } = req.auth;
|
const { user_id: current_user_id, is_admin } = req.auth;
|
||||||
const { user_id } = req.query;
|
const { user_id, include_all } = req.query;
|
||||||
const userId = +user_id;
|
const userId = +user_id;
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
@ -14,7 +14,10 @@ export default async (req, res) => {
|
|||||||
return unauthorized(res);
|
return unauthorized(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
const websites = await getUserWebsites(userId || current_user_id);
|
const websites =
|
||||||
|
is_admin && include_all
|
||||||
|
? await getAllWebsites()
|
||||||
|
: await getUserWebsites(userId || current_user_id);
|
||||||
|
|
||||||
return ok(res, websites);
|
return ok(res, websites);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user