Skip to content

Commit 19fb2fa

Browse files
authored
Merge pull request #10047 from opencrvs/allow-apostrophes-in-scopes
Update migrations to remove special characters from role ids on generation
2 parents 6bde658 + 0665b61 commit 19fb2fa

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Bug fixes
66

77
- Fixed historical roles displaying incorrectly in task history after migration to v1.7 [#9989](https://github.com/opencrvs/opencrvs-core/issues/9989)
8+
- Remove special characters from role ids on generation [#10049](https://github.com/opencrvs/opencrvs-core/issues/10049)
89

910
## [1.7.3](https://github.com/opencrvs/opencrvs-core/compare/v1.7.2...v1.7.3)
1011

packages/migration/src/migrations/user-mgnt/20240628124653-remove-userroles.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,16 @@ export const up = async (db: Db, client: MongoClient) => {
3939
$addFields: {
4040
role: {
4141
$toUpper: {
42-
$replaceAll: {
43-
input: { $arrayElemAt: ['$roleDetails.labels.label', 0] },
44-
find: ' ',
45-
replacement: '_'
42+
$function: {
43+
body: `
44+
function(label) {
45+
return label
46+
.replace(/[^a-zA-Z0-9 ]/g, '')
47+
.replace(/ /g, '_');
48+
}
49+
`,
50+
args: [{ $arrayElemAt: ['$roleDetails.labels.label', 0] }],
51+
lang: 'js'
4652
}
4753
}
4854
}

packages/migration/src/utils/role-helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export const transformRoleCodes = (doc: any) => {
171171

172172
if (englishLabel?.label) {
173173
const transformedLabel = englishLabel.label
174+
.replace(/[^a-zA-Z0-9 ]/g, '')
174175
.toUpperCase()
175176
.replace(/ /g, '_')
176177

0 commit comments

Comments
 (0)