📈 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
sending email
Blue Mouse5280d4ad4eed
diff --git a/src/action-tokens/action-token.entity.ts b/src/action-tokens/action-token.entity.tsindex 16f188548..30daed747 100644--- a/src/action-tokens/action-token.entity.ts+++ b/src/action-tokens/action-token.entity.ts@@ -5,6 +5,7 @@ export enum ActionTokenType {EMAIL_VERIFICATION,PASSWORD_RESET,EMAIL_CHANGE,+ PROJECT_SHARE,}@Entity()diff --git a/src/auth/auth.module.ts b/src/auth/auth.module.tsindex fcd2dd6b0..6efa7013e 100644--- a/src/auth/auth.module.ts+++ b/src/auth/auth.module.ts@@ -11,7 +11,7 @@ import { AppLoggerModule } from '../logger/logger.module'forwardRef(() => UserModule),MailerModule,ActionTokensModule,- AppLoggerModule+ AppLoggerModule,],controllers: [AuthController],providers: [AuthService],diff --git a/src/common/constants.ts b/src/common/constants.tsindex 29473c11e..7b20acc95 100644--- a/src/common/constants.ts+++ b/src/common/constants.ts@@ -161,11 +161,13 @@ const GDPR_EXPORT_TIMEFRAME = 14// send email warning when 85% of events in tier are usedconst SEND_WARNING_AT_PERC = 85+const PROJECT_INVITE_EXPIRE = 48+export {clickhouse, JWT_LIFE_TIME, HISTORY_LIFE_TIME_DAYS, redis, isValidPID, getRedisProjectKey,redisProjectCacheTimeout, getPercentageChange, UNIQUE_SESSION_LIFE_TIME, REDIS_LOG_DATA_CACHE_KEY,GDPR_EXPORT_TIMEFRAME, getRedisUserCountKey, redisProjectCountCacheTimeout, REDIS_LOG_CUSTOM_CACHE_KEY,REDIS_SESSION_SALT_KEY, HEARTBEAT_SID_LIFE_TIME, isSelfhosted, UUIDV5_NAMESPACE, SELFHOSTED_EMAIL,SELFHOSTED_PASSWORD, SELFHOSTED_UUID, CLICKHOUSE_INIT_QUERIES, REDIS_USERS_COUNT_KEY, REDIS_PROJECTS_COUNT_KEY,- REDIS_PAGEVIEWS_COUNT_KEY, SEND_WARNING_AT_PERC,+ REDIS_PAGEVIEWS_COUNT_KEY, SEND_WARNING_AT_PERC, PROJECT_INVITE_EXPIRE,}diff --git a/src/project/project.controller.ts b/src/project/project.controller.tsindex 94f3e3ee4..e0745a677 100644--- a/src/project/project.controller.ts+++ b/src/project/project.controller.ts@@ -12,6 +12,7 @@ import {HttpCode,NotFoundException,ForbiddenException,+ Headers,} from '@nestjs/common'import { ApiTags, ApiQuery, ApiResponse } from '@nestjs/swagger'import * as _isEmpty from 'lodash/isEmpty'@@ -23,6 +24,10 @@ import * as _includes from 'lodash/includes'import { ProjectService } from './project.service'import { UserType, ACCOUNT_PLANS, PlanCode } from '../user/entities/user.entity'+import { ActionTokenType } from '../action-tokens/action-token.entity'+import { ActionTokensService } from '../action-tokens/action-tokens.service'+import { MailerService } from '../mailer/mailer.service'+import { LetterTemplate } from '../mailer/letter'import { Roles } from '../common/decorators/roles.decorator'import { SelfhostedGuard } from 'src/common/guards/selfhosted.guard'import { RolesGuard } from '../common/guards/roles.guard'@@ -41,6 +46,7 @@ import {redisProjectCacheTimeout,clickhouse,isSelfhosted,+ PROJECT_INVITE_EXPIRE,} from '../common/constants'import {getProjectsClickhouse,@@ -65,6 +71,8 @@ export class ProjectController {private readonly projectService: ProjectService,private readonly userService: UserService,private readonly logger: AppLoggerService,+ private readonly actionTokensService: ActionTokensService,+ private readonly mailerService: MailerService,) {}@Get('/')@@ -492,6 +500,7 @@ export class ProjectController {@Param('pid') pid: string,@Body() shareDTO: ShareDTO,@CurrentUserId() uid: string,+ @Headers() headers,): Promise<Project> {this.logger.log({ uid, pid, shareDTO }, 'POST /project/:pid/share')@@ -535,7 +544,6 @@ export class ProjectController {}// TODO: Check if the invitee already has the project- // TODO: Send an email to the invitee with a link to confirm the share (the email is valid for 48 hours)try {const share = new ProjectShare()@@ -553,6 +561,13 @@ export class ProjectController {invitee.sharedProjects.push(share)await this.userService.create(invitee)+ // TODO: Implement link expiration+ const actionToken = await this.actionTokensService.createForUser(user, ActionTokenType.PROJECT_SHARE)+ const url = `${headers.origin}/verify/${actionToken.id}`+ await this.mailerService.sendEmail(invitee.email, LetterTemplate.ProjectInvitation, {+ url, email: user.email, name: project.name, role: share.role, expiration: PROJECT_INVITE_EXPIRE,+ })+return await this.projectService.findOne(pid, {relations: ['share'],})diff --git a/src/project/project.module.ts b/src/project/project.module.tsindex 54d1bab49..dba1cb34d 100644--- a/src/project/project.module.ts+++ b/src/project/project.module.ts@@ -6,6 +6,8 @@ import { ProjectShare } from './entity/project-share.entity'import { ProjectService } from './project.service'import { ProjectController } from './project.controller'import { UserModule } from '../user/user.module'+import { ActionTokensModule } from '../action-tokens/action-tokens.module'+import { MailerModule } from '../mailer/mailer.module'import { AppLoggerModule } from '../logger/logger.module'@Module({@@ -14,6 +16,8 @@ import { AppLoggerModule } from '../logger/logger.module'TypeOrmModule.forFeature([ProjectShare]),forwardRef(() => UserModule),AppLoggerModule,+ ActionTokensModule,+ MailerModule,],providers: [ProjectService],exports: [ProjectService],