Processing Roles
Processing Roles in build_solution.py
Overview
The build_solution.py
script processes multiple JSON module files to generate a consolidated roles file:generated-roles.json
– Contains merged roles with unique permissions.
How Roles Are Processed
Extract roles from each module's JSON file.
Merge duplicate role names, ensuring unique permissions are combined.
Map permissions using
permissions_map.json
to include bothcode
andname
fields.Sort permissions within each role for better readability.
Save results to
generated-roles.json
.
Input JSON Structure (Example Module File)
Each module file should contain a roles
section like this:
{
"roles": [
{
"roleName": "Admin",
"code": "admin",
"permissions": [
"individual.read_individual",
"individual.create_individual",
"individual.update_individual",
"individual.delete_individual"
]
}
]
}
Role Merging Logic
If multiple modules define the same
roleName
, their permissions are merged (no duplicates).Roles retain the same
code
from their original definitions.The final output consolidates all role definitions into a single
generated-roles.json
file.Permissions are mapped to include
code
andname
usingpermissions_map.json
.
Example:
Input from Module 1:
{
"roles": [
{
"roleName": "Admin",
"code": "admin",
"permissions": [
"grievance.create_grievance",
"grievance.update_grievance"
]
}
]
}
Input from Module 2:
{
"roles": [
{
"roleName": "Admin",
"code": "admin",
"permissions": [
"grievance.delete_grievance",
"grievance.read_grievance"
]
}
]
}
Final Output (generated-roles.json):
{
"roles": [
{
"roleName": "Admin",
"code": "admin",
"permissions": [
{
"name": "grievance.create_grievance",
"code": "127001"
},
{
"name": "grievance.update_grievance",
"code": "127002"
},
{
"name": "grievance.delete_grievance",
"code": "127003"
},
{
"name": "grievance.read_grievance",
"code": "127000"
}
]
}
]
}
Processing Steps
Load Modules
Extract roles from each module’s JSON file.
Each module contains a list of roles with
roleName
,code
, and associatedpermissions
.
Merge Roles
If the same
roleName
appears in multiple modules, their permissions are combined.Duplicates within the permission lists are removed.
The
code
remains the same as defined in the original modules.
Map Permissions
Each permission string is replaced with a dictionary containing:
"name"
: The original permission string."code"
: The mapped value frompermissions_map.json
.
If no mapping exists, the permission remains unchanged.
Generate Output
The final list of merged roles is structured into a single JSON object.
The processed roles are saved in
generated-roles.json
.
Output File
The processed roles are saved in:
generated-roles.json
This file consolidates all roles across modules, ensuring a structured and non-duplicated set of permissions. Each role in the final output contains:
roleName
: The name of the role.code
: The unique code identifier for the role.permissions
: A merged list of permissions from all modules, each containing:name
: The permission name.code
: The mapped permission code frompermissions_map.json
.
Did you encounter a problem or do you have a suggestion?
Please contact our Service Desk
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. https://creativecommons.org/licenses/by-sa/4.0/