Skip to content

Commit

Permalink
Merge pull request #16 from fabmob/1.21.2
Browse files Browse the repository at this point in the history
Programme Mon Compte Mobilité - Version 1.21.2
  • Loading branch information
TTalex authored Mar 28, 2023
2 parents 722fdad + 9662c0a commit 2aeeb1a
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 9 deletions.
2 changes: 1 addition & 1 deletion administration/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "administration",
"version": "1.21.0",
"version": "1.21.2",
"author": "Mon Compte Mobilité",
"private": true,
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mcm/mcm-api",
"version": "1.21.0",
"version": "1.21.2",
"description": "",
"keywords": [
"loopback-application",
Expand Down
6 changes: 3 additions & 3 deletions api/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import {MongoDsDataSource} from './datasources';
import {LoggerProvider} from './providers';
import {Logger} from './utils';
import {LoggerBindings} from './keys';
import {MigrationScript1210} from './migrations/1.21.0.migration';
import {
RabbitmqCronJob,
SubscriptionCronJob,
NonActivatedAccountDeletionCronJob,
InactiveAccountNotificationCronJob,
InactiveAccountDeletionCronJob,
} from './cronjob';
import {MigrationScript1212} from './migrations/1.21.2.migration';

export class App extends BootMixin(ServiceMixin(RepositoryMixin(RestApplication))) {
constructor(options: ApplicationConfig = {}) {
Expand Down Expand Up @@ -69,10 +69,10 @@ export class App extends BootMixin(ServiceMixin(RepositoryMixin(RestApplication)
this.static('/', path.join(__dirname, '../public'));
// Configure migration componentcd
this.bind(MigrationBindings.CONFIG).to({
appVersion: '1.21.0',
appVersion: '1.21.2',
dataSourceName: MongoDsDataSource.dataSourceName,
modelName: 'Migration',
migrationScripts: [MigrationScript1210],
migrationScripts: [MigrationScript1212],
});
// Bind migration component related elements
this.component(MigrationComponent);
Expand Down
85 changes: 85 additions & 0 deletions api/src/migrations/1.21.2.migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {MigrationScript, migrationScript} from 'loopback4-migration';
import {repository} from '@loopback/repository';
import {GROUPS, Logger} from '../utils';
import {service} from '@loopback/core';
import {KeycloakService} from '../services';
import {UserEntityRepository} from '../repositories';
import {Citizen, UserEntity} from '../models';

@migrationScript()
export class MigrationScript1212 implements MigrationScript {
version = '1.21.2';
scriptName = MigrationScript1212.name;
description = 'Update Citizen with lastLoginAt, tos1 & tos2 timestamp';

constructor(
@repository(UserEntityRepository)
public userEntityRepository: UserEntityRepository,
@service(KeycloakService)
public keycloakService: KeycloakService,
) {}

sliceIntoChunks = (array: any[], chunkSize: number): any[][] => {
const res = [];
for (let i = 0; i < array.length; i += chunkSize) {
const chunk = array.slice(i, i + chunkSize);
res.push(chunk);
}
return res;
};

async up(): Promise<void> {
Logger.info(MigrationScript1212.name, this.up.name, 'Started');

const citizenToUpdateList: UserEntity[] =
await this.userEntityRepository.searchUserWithAttributesByFilter({}, GROUPS.citizens);

Logger.info(
MigrationScript1212.name,
this.up.name,
'Number of citizen to update',
citizenToUpdateList.length,
);

const citizenToUpdateChunkList: UserEntity[][] = this.sliceIntoChunks(citizenToUpdateList, 10);

for (const citizenToUpdateChunk of citizenToUpdateChunkList) {
await Promise.allSettled(
citizenToUpdateChunk.map(async (citizenToUpdate: UserEntity) => {
try {
Logger.info(MigrationScript1212.name, this.up.name, `Start update citizen`, citizenToUpdate.id);

const citizen: Citizen = citizenToUpdate.toCitizen();
if (!citizen.lastLoginAt || !citizen.tos1 || !citizen.tos2) {
if (!citizen.lastLoginAt) {
citizen.lastLoginAt = citizen.updatedAt;
}
if (!citizen.tos1 || !citizen.tos2) {
citizen.tos1 = true;
citizen.tos2 = true;
}
await this.keycloakService.updateUserKC(citizen.id, citizen);
Logger.info(MigrationScript1212.name, this.up.name, `Citizen Updated`, citizenToUpdate.id);
} else {
Logger.info(
MigrationScript1212.name,
this.up.name,
`Citizen has lastLoginAt, tos1 & tos2 property`,
citizenToUpdate.id,
);
}
} catch (err) {
Logger.error(
MigrationScript1212.name,
this.up.name,
`Error while updating citizen`,
citizenToUpdate.id,
);
}
}),
);
}

Logger.info(MigrationScript1212.name, this.up.name, `Completed`);
}
}
2 changes: 1 addition & 1 deletion commons/.gitlab-ci/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ mongo_testing_clean_data:
fi
echo "---------"
echo "GET GROUPS"
GROUP_LIST_ID=$(kubectl exec $IDP_POD_NAME -n $IDP_NAMESPACE -c idp -- sh -c "/opt/jboss/keycloak/bin/kcadm.sh get groups -r mcm" | jq -r '.[] | select( .name == "entreprises" or .name == "collectivités") | .subGroups | .[] | .id')
GROUP_LIST_ID=$(kubectl exec $IDP_POD_NAME -n $IDP_NAMESPACE -c idp -- sh -c "/opt/jboss/keycloak/bin/kcadm.sh get groups -r mcm" | jq -r '.[] | select( .name == "entreprises" or .name == "collectivités" or .name == "administrations_nationales") | .subGroups | .[] | .id')
echo $GROUP_LIST_ID
if [ -z "$GROUP_LIST_ID" ]
then
Expand Down
1 change: 1 addition & 0 deletions helm-chart/antivirus-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ autoscaling:
policies:
- type: Pods
value: 1
periodSeconds: 300

deployments:
- metadata:
Expand Down
2 changes: 1 addition & 1 deletion simulation-maas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simulation-maas",
"version": "1.21.0",
"version": "1.21.2",
"description": "here is a maas simulator",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cypress-mcm",
"version": "1.21.0",
"version": "1.21.2",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mcm/mcm-website",
"description": "JAMstack project based on Gatsby and Netlify CMS",
"version": "1.21.0",
"version": "1.21.2",
"author": "Capgemini",
"dependencies": {
"@datapunt/matomo-tracker-react": "0.5.1",
Expand Down

0 comments on commit 2aeeb1a

Please sign in to comment.