Skip to content

📈 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!

clear organisation projects cache on new member join

Blue Mouse9880f286e786
diff --git a/backend/apps/cloud/src/organisation/organisation.service.ts b/backend/apps/cloud/src/organisation/organisation.service.ts
index badb4c63f..c40551ce9 100644
--- a/backend/apps/cloud/src/organisation/organisation.service.ts
+++ b/backend/apps/cloud/src/organisation/organisation.service.ts
@@ -14,6 +14,7 @@ import {
OrganisationRole,
} from './entity/organisation-member.entity'
import { Pagination, PaginationOptionsInterface } from '../common/pagination'
+import { getRedisProjectKey, redis } from '../common/constants'
@Injectable()
export class OrganisationService {
@@ -71,6 +72,39 @@ export class OrganisationService {
await this.membershipRepository.delete(id)
}
+ async deleteOrganisationProjectsFromRedis(organisationId: string) {
+ const organisation = await this.findOne({
+ where: { id: organisationId },
+ relations: ['projects'],
+ select: {
+ id: true,
+ projects: {
+ id: true,
+ },
+ },
+ })
+
+ if (!organisation?.projects?.length) {
+ return
+ }
+
+ for (const project of organisation.projects) {
+ if (!project?.id) {
+ continue
+ }
+
+ const key = getRedisProjectKey(project.id)
+
+ try {
+ await redis.del(key)
+ } catch (reason) {
+ console.error(
+ `Error deleting project ${project.id} from redis: ${reason}`,
+ )
+ }
+ }
+ }
+
validateManageAccess(organisation: Organisation, userId: string) {
const membership = _find(
organisation.members,
diff --git a/backend/apps/cloud/src/user/user.controller.ts b/backend/apps/cloud/src/user/user.controller.ts
index c979ffb3e..b8963b96b 100644
--- a/backend/apps/cloud/src/user/user.controller.ts
+++ b/backend/apps/cloud/src/user/user.controller.ts
@@ -568,6 +568,12 @@ export class UserController {
const membership = await this.organisationService.findOneMembership({
where: { id: actionToken?.newValue || actionId },
relations: ['user'],
+ select: {
+ id: true,
+ user: {
+ id: true,
+ },
+ },
})
if (_isEmpty(membership)) {
@@ -611,7 +617,16 @@ export class UserController {
const membership = await this.organisationService.findOneMembership({
where: { id: actionToken?.newValue || actionId },
- relations: ['user'],
+ relations: ['user', 'organisation'],
+ select: {
+ id: true,
+ user: {
+ id: true,
+ },
+ organisation: {
+ id: true,
+ },
+ },
})
if (_isEmpty(membership)) {
@@ -633,6 +648,10 @@ export class UserController {
if (isActionToken) {
await this.actionTokensService.delete(actionId)
}
+
+ await this.organisationService.deleteOrganisationProjectsFromRedis(
+ membership.organisation.id,
+ )
}
@ApiBearerAuth()