📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
added allowedToView & allowedToManage helpers support for shared projects
Blue Mouse1924235c3725
diff --git a/src/analytics/analytics.service.ts b/src/analytics/analytics.service.tsindex 2717cf48a..10b455a6d 100644--- a/src/analytics/analytics.service.ts+++ b/src/analytics/analytics.service.ts@@ -122,12 +122,27 @@ export class AnalyticsService {if (isSelfhosted) {project = await getProjectsClickhouse(pid)} else {+ // todo: optimise the relations - select+ // select only required columns+ // https://stackoverflow.com/questions/59645009/how-to-return-only-some-columns-of-a-relations-with-typeormproject = await this.projectService.findOne(pid, {relations: ['admin'],- select: ['origins', 'active', 'admin', 'public']+ select: ['origins', 'active', 'admin', 'public'],})}if (_isEmpty(project)) throw new BadRequestException('The provided Project ID (pid) is incorrect')++ if (!isSelfhosted) {+ const share = await this.projectService.findShare({+ where: {+ project: pid,+ },+ relations: ['user'],+ })+ // @ts-ignore+ project = { ...project, share }+ }+await redis.set(pidKey, JSON.stringify(project), 'EX', redisProjectCacheTimeout)} else {try {diff --git a/src/project/project.service.ts b/src/project/project.service.tsindex 0ed3b122f..78170ad06 100644--- a/src/project/project.service.ts+++ b/src/project/project.service.ts@@ -8,6 +8,7 @@ import * as _size from 'lodash/size'import * as _join from 'lodash/join'import * as _find from 'lodash/find'import * as _map from 'lodash/map'+import * as _findIndex from 'lodash/findIndex'import * as _includes from 'lodash/includes'import * as dayjs from 'dayjs'import * as utc from 'dayjs/plugin/utc'@@ -16,7 +17,8 @@ import { Pagination, PaginationOptionsInterface } from '../common/pagination'import { Project } from './entity/project.entity'import { ProjectShare } from './entity/project-share.entity'import { ProjectDTO } from './dto/project.dto'-import { UserType } from './../user/entities/user.entity'+import { UserType } from '../user/entities/user.entity'+import { Role } from '../project/entity/project-share.entity'import {isValidPID, redisProjectCountCacheTimeout, getRedisUserCountKey, redis, clickhouse, isSelfhosted,} from '../common/constants'@@ -108,7 +110,7 @@ export class ProjectService {}allowedToView(project: Project, uid: string | null): void {- if (project.public || uid === project.admin.id) {+ if (project.public || uid === project.admin.id || _findIndex(project.share, ({ user }) => user?.id === uid) !== -1) {return} else {throw new ForbiddenException('You are not allowed to access this project')@@ -116,7 +118,7 @@ export class ProjectService {}allowedToManage(project: Project, uid: string, roles: Array<UserType>): void {- if (uid === project.admin.id || _includes(roles, UserType.ADMIN)) {+ if (uid === project.admin.id || _includes(roles, UserType.ADMIN) || _findIndex(project.share, (share) => share.user?.id === uid && share.role === Role.admin) !== -1) {return} else {throw new ForbiddenException('You are not allowed to access this project')