mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Removed grant checks.
This commit is contained in:
parent
48c7028a3a
commit
5c9f97182e
4 changed files with 9 additions and 32 deletions
|
|
@ -21,7 +21,7 @@ export async function checkAuth(request: Request) {
|
||||||
const shareToken = await parseShareToken(request);
|
const shareToken = await parseShareToken(request);
|
||||||
|
|
||||||
let user = null;
|
let user = null;
|
||||||
const { userId, authKey, grant } = payload || {};
|
const { userId, authKey } = payload || {};
|
||||||
|
|
||||||
if (userId) {
|
if (userId) {
|
||||||
user = await getUser(userId);
|
user = await getUser(userId);
|
||||||
|
|
@ -33,7 +33,7 @@ export async function checkAuth(request: Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log({ token, shareToken, payload, user, grant });
|
log({ token, payload, authKey, shareToken, user });
|
||||||
|
|
||||||
if (!user?.id && !shareToken) {
|
if (!user?.id && !shareToken) {
|
||||||
log('User not authorized');
|
log('User not authorized');
|
||||||
|
|
@ -45,11 +45,10 @@ export async function checkAuth(request: Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user,
|
|
||||||
grant,
|
|
||||||
token,
|
token,
|
||||||
shareToken,
|
|
||||||
authKey,
|
authKey,
|
||||||
|
shareToken,
|
||||||
|
user,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { UseQueryOptions } from '@tanstack/react-query';
|
import { UseQueryOptions } from '@tanstack/react-query';
|
||||||
import { DATA_TYPE, PERMISSIONS, ROLES, OPERATORS } from './constants';
|
import { DATA_TYPE, ROLES, OPERATORS } from './constants';
|
||||||
import { TIME_UNIT } from './date';
|
import { TIME_UNIT } from './date';
|
||||||
|
|
||||||
export type ObjectValues<T> = T[keyof T];
|
export type ObjectValues<T> = T[keyof T];
|
||||||
|
|
@ -7,7 +7,6 @@ export type ObjectValues<T> = T[keyof T];
|
||||||
export type ReactQueryOptions<T = any> = Omit<UseQueryOptions<T, Error, T>, 'queryKey' | 'queryFn'>;
|
export type ReactQueryOptions<T = any> = Omit<UseQueryOptions<T, Error, T>, 'queryKey' | 'queryFn'>;
|
||||||
|
|
||||||
export type TimeUnit = ObjectValues<typeof TIME_UNIT>;
|
export type TimeUnit = ObjectValues<typeof TIME_UNIT>;
|
||||||
export type Permission = ObjectValues<typeof PERMISSIONS>;
|
|
||||||
export type Role = ObjectValues<typeof ROLES>;
|
export type Role = ObjectValues<typeof ROLES>;
|
||||||
export type DynamicDataType = ObjectValues<typeof DATA_TYPE>;
|
export type DynamicDataType = ObjectValues<typeof DATA_TYPE>;
|
||||||
export type Operator = (typeof OPERATORS)[keyof typeof OPERATORS];
|
export type Operator = (typeof OPERATORS)[keyof typeof OPERATORS];
|
||||||
|
|
@ -19,7 +18,6 @@ export interface Auth {
|
||||||
role: string;
|
role: string;
|
||||||
isAdmin: boolean;
|
isAdmin: boolean;
|
||||||
};
|
};
|
||||||
grant?: Permission[];
|
|
||||||
shareToken?: {
|
shareToken?: {
|
||||||
websiteId: string;
|
websiteId: string;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ import { PERMISSIONS } from '@/lib/constants';
|
||||||
import { getTeamUser } from '@/queries';
|
import { getTeamUser } from '@/queries';
|
||||||
import { hasPermission } from '@/lib/auth';
|
import { hasPermission } from '@/lib/auth';
|
||||||
|
|
||||||
const cloudMode = !!process.env.CLOUD_URL;
|
|
||||||
|
|
||||||
export async function canViewTeam({ user }: Auth, teamId: string) {
|
export async function canViewTeam({ user }: Auth, teamId: string) {
|
||||||
if (user.isAdmin) {
|
if (user.isAdmin) {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -13,11 +11,7 @@ export async function canViewTeam({ user }: Auth, teamId: string) {
|
||||||
return getTeamUser(teamId, user.id);
|
return getTeamUser(teamId, user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function canCreateTeam({ user, grant }: Auth) {
|
export async function canCreateTeam({ user }: Auth) {
|
||||||
if (cloudMode) {
|
|
||||||
return !!grant?.find(a => a === PERMISSIONS.teamCreate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user.isAdmin) {
|
if (user.isAdmin) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -25,15 +19,11 @@ export async function canCreateTeam({ user, grant }: Auth) {
|
||||||
return !!user;
|
return !!user;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function canUpdateTeam({ user, grant }: Auth, teamId: string) {
|
export async function canUpdateTeam({ user }: Auth, teamId: string) {
|
||||||
if (user.isAdmin) {
|
if (user.isAdmin) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cloudMode) {
|
|
||||||
return !!grant?.find(a => a === PERMISSIONS.teamUpdate);
|
|
||||||
}
|
|
||||||
|
|
||||||
const teamUser = await getTeamUser(teamId, user.id);
|
const teamUser = await getTeamUser(teamId, user.id);
|
||||||
|
|
||||||
return teamUser && hasPermission(teamUser.role, PERMISSIONS.teamUpdate);
|
return teamUser && hasPermission(teamUser.role, PERMISSIONS.teamUpdate);
|
||||||
|
|
@ -49,11 +39,7 @@ export async function canDeleteTeam({ user }: Auth, teamId: string) {
|
||||||
return teamUser && hasPermission(teamUser.role, PERMISSIONS.teamDelete);
|
return teamUser && hasPermission(teamUser.role, PERMISSIONS.teamDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function canAddUserToTeam({ user, grant }: Auth) {
|
export async function canAddUserToTeam({ user }: Auth) {
|
||||||
if (cloudMode) {
|
|
||||||
return !!grant?.find(a => a === PERMISSIONS.teamUpdate);
|
|
||||||
}
|
|
||||||
|
|
||||||
return user.isAdmin;
|
return user.isAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ import { PERMISSIONS } from '@/lib/constants';
|
||||||
import { hasPermission } from '@/lib/auth';
|
import { hasPermission } from '@/lib/auth';
|
||||||
import { getTeamUser, getWebsite } from '@/queries';
|
import { getTeamUser, getWebsite } from '@/queries';
|
||||||
|
|
||||||
const cloudMode = !!process.env.CLOUD_URL;
|
|
||||||
|
|
||||||
export async function canViewWebsite({ user, shareToken }: Auth, websiteId: string) {
|
export async function canViewWebsite({ user, shareToken }: Auth, websiteId: string) {
|
||||||
if (user?.isAdmin) {
|
if (user?.isAdmin) {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -33,11 +31,7 @@ export async function canViewAllWebsites({ user }: Auth) {
|
||||||
return user.isAdmin;
|
return user.isAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function canCreateWebsite({ user, grant }: Auth) {
|
export async function canCreateWebsite({ user }: Auth) {
|
||||||
if (cloudMode) {
|
|
||||||
return !!grant?.find(a => a === PERMISSIONS.websiteCreate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user.isAdmin) {
|
if (user.isAdmin) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue