Skip to content

Commit

Permalink
Merge pull request #380 from chaynHQ/develop
Browse files Browse the repository at this point in the history
Merge Develop onto Main
  • Loading branch information
annarhughes authored Jan 9, 2024
2 parents d06b9ba + d9ec88d commit b294322
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Bloom Backend CI Pipeline

on:
pull_request:
branches: [develop, main]
branches: [develop]
push:
branches: [develop]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
push:
branches: [develop, main]
pull_request:
branches: [develop, main]
branches: [develop]
schedule:
- cron: '25 5 * * 5'

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: Create release PR

on:
push:
branches:
- develop
branches: [develop]

jobs:
create-pr-to-main:
Expand Down
22 changes: 22 additions & 0 deletions src/api/crisp/crisp-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,25 @@ export const deleteCrispProfile = async (email: string) => {
throw error;
}
};

export const deleteCypressCrispProfiles = async () => {
try {
const profiles = await apiCall({
url: `${baseUrl}/people/profiles/1?search_text=cypresstestemail+`,
type: 'get',
headers,
});

profiles.data.data.forEach(async (profile) => {
await apiCall({
url: `${baseUrl}/people/profile/${profile.email}`,
type: 'delete',
headers,
});
});

return 'ok';
} catch (error) {
throw error;
}
};
2 changes: 1 addition & 1 deletion src/partner-access/partner-access.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class PartnerAccessService {
const partnerAccessRecords = await this.partnerAccessRepository //get partner access instances where user is a cypress user
.createQueryBuilder('partnerAccess')
.leftJoinAndSelect('partnerAccess.user', 'user')
.where('user.name LIKE :searchTerm', { searchTerm: `%Cypress test user%` })
.where('user.name LIKE :searchTerm', { searchTerm: `%Cypress test%` })
.getMany();
await Promise.all(
partnerAccessRecords.map(async (access) => {
Expand Down
7 changes: 7 additions & 0 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ export class UserController {
return await this.userService.deleteCypressTestUsers();
}

@ApiBearerAuth('access-token')
@Delete('/cypress-clean')
@UseGuards(SuperAdminAuthGuard)
async cleanCypressUsers(): Promise<UserEntity[]> {
return await this.userService.deleteCypressTestUsers(true);
}

@ApiBearerAuth()
@Delete(':id')
@ApiParam({ name: 'id', description: 'User id to delete' })
Expand Down
28 changes: 22 additions & 6 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import {
addCrispProfile,
deleteCrispProfile,
deleteCypressCrispProfiles,
updateCrispProfileData,
} from '../api/crisp/crisp-api';
import { AuthService } from '../auth/auth.service';
Expand Down Expand Up @@ -353,7 +354,8 @@ export class UserService {

return user;
}
public async deleteCypressTestUsers(): Promise<UserEntity[]> {

public async deleteCypressTestUsers(clean = false): Promise<UserEntity[]> {
try {
const queryResult = await this.userRepository
.createQueryBuilder('user')
Expand All @@ -364,6 +366,7 @@ export class UserService {
const deletedUsers = await Promise.all(
queryResult.map(async (user) => {
try {
await deleteCrispProfile(user.email);
await this.authService.deleteFirebaseUser(user.firebaseUid);
await this.userRepository.delete(user);
return user;
Expand All @@ -373,15 +376,28 @@ export class UserService {
}),
);

// Delete all remaining cypress firebase users (e.g. from failed user creations)
this.authService.deleteCypressFirebaseUsers();

return deletedUsers;
} catch (error) {
// If this fails we don't want to break cypress tests
this.logger.error(`deleteCypressTestAccessCodes - Unable to delete all cypress users`, error);
// If this fails we don't want to break cypress tests but we want to be alerted
this.logger.error(`deleteCypressTestUsers - Unable to delete all cypress users`, error);
}

try {
// Clean remaining user accounts in firebase and crisp that do not have a user record in the db
// These rogue accounts may be left over from incomplete signups or errors
if (clean) {
// Delete all remaining cypress firebase users (e.g. from failed user creations)
await this.authService.deleteCypressFirebaseUsers();

// Delete all remaining crisp accounts
await deleteCypressCrispProfiles();
}
} catch (error) {
// If this fails we don't want to break cypress tests but we want to be alerted
this.logger.error(`deleteCypressTestUsers - Unable to clean all cypress users`, error);
}
}

public async getUsers(
filters: {
email?: string;
Expand Down

0 comments on commit b294322

Please sign in to comment.