mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 06:07:17 +01:00
Website transfer.
This commit is contained in:
parent
b6a900c5a4
commit
d99fb09c37
9 changed files with 249 additions and 16 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { Report } from '@prisma/client';
|
||||
import redis from '@umami/redis-client';
|
||||
import debug from 'debug';
|
||||
import { PERMISSIONS, ROLE_PERMISSIONS, SHARE_TOKEN_HEADER } from 'lib/constants';
|
||||
import { PERMISSIONS, ROLE_PERMISSIONS, SHARE_TOKEN_HEADER, ROLES } from 'lib/constants';
|
||||
import { secret } from 'lib/crypto';
|
||||
import { NextApiRequest } from 'next';
|
||||
import { createSecureToken, ensureArray, getRandomChars, parseToken } from 'next-basics';
|
||||
|
|
@ -101,6 +101,38 @@ export async function canUpdateWebsite({ user }: Auth, websiteId: string) {
|
|||
return false;
|
||||
}
|
||||
|
||||
export async function canTransferWebsiteToUser({ user }: Auth, websiteId: string, userId: string) {
|
||||
if (user.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const website = await loadWebsite(websiteId);
|
||||
|
||||
if (website.teamId && user.id === userId) {
|
||||
const teamUser = await getTeamUser(website.teamId, userId);
|
||||
|
||||
return teamUser?.role === ROLES.teamOwner;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function canTransferWebsiteToTeam({ user }: Auth, websiteId: string, teamId: string) {
|
||||
if (user.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const website = await loadWebsite(websiteId);
|
||||
|
||||
if (website.userId === user.id) {
|
||||
const teamUser = await getTeamUser(teamId, user.id);
|
||||
|
||||
return teamUser?.role === ROLES.teamOwner;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function canDeleteWebsite({ user }: Auth, websiteId: string) {
|
||||
if (user.isAdmin) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import {
|
|||
} from './constants';
|
||||
import * as yup from 'yup';
|
||||
import { TIME_UNIT } from './date';
|
||||
import { Dispatch, SetStateAction } from 'react';
|
||||
|
||||
type ObjectValues<T> = T[keyof T];
|
||||
|
||||
|
|
@ -64,6 +65,13 @@ export interface FilterResult<T> {
|
|||
sortDescending?: boolean;
|
||||
}
|
||||
|
||||
export interface FilterQueryResult<T> {
|
||||
result: FilterResult<T>;
|
||||
query: any;
|
||||
params: SearchFilter;
|
||||
setParams: Dispatch<SetStateAction<T | SearchFilter>>;
|
||||
}
|
||||
|
||||
export interface DynamicData {
|
||||
[key: string]: number | string | DynamicData | number[] | string[] | DynamicData[];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue