Loading initial platform data
Some initial data is necessary for the Management API to be functional.
For instance, you need a first user to start calling the API endpoints. Some other data such as the Roles and Permissions should also be available for this first user to make API calls.
All this data that is necessary for the platform to work should always be loaded when the platform starts up.
Which data
The data that will always be loaded if it is not present includes:
- The default set of Permissions
- The default set of Roles
- One user which has a high enough Role assigned to start administrating the platform
How the data is loaded
The data that should always be present will be loaded in management-api/src/main.ts
whenever it is missing on application startup.
You can edit this initial data in management-api/src/fixtures/initial-data.ts
.
The only User that will always be reloaded is a User having a high enough Role assigned to start administrating the platform. For this User to be authenticated in API calls, its identityProviderId
should match the one contained in its valid Bearer token.
Therefore, whenever the platform is set up initially, there must be at least this one User already registered in your identity provider service.
Development fixtures
For development purposes, a script is available to load example data into several new tenants. It includes users, user groups, devices, etc... To load the data, start by initializing your instance, and run the command npm run fixtures:more
in the management-api folder
Adding new initial or development data
When adding new objects to be loaded for initial or development data, there are some things to keep in mind:
- generate a new UUID for each new object. If you don't set the UUID, the API will try to recreate the objects during each new startup, potentially running into uniqueness issues.
> You can generate one using
uuidgen
, supported on most linux systems. - do not forget to add your new object to the array to be saved in the database (for example, for
Permission
objects there is an arrayconst permissions = [...]
where you can add your new permission variable)
Adding new roles and permissions
Currently, it is not possible to add new roles and permissions through the API.
For now you can add it manually in the initial data. To do this, please have a look at the authorization model too.
Adding a permission or an entity type
In the API's fixtures/initial-data.ts
, you can add a new Permission
or EntityType
object following the examples of the existing ones.
For Permission
objects, do not forget to set the relevantTypes
.
If you intend to use the new EntityType
or Permission
objects in code, you should update the EntityTypes
and PermissionAssignments
enums in core/shared/models/authorization/enums.ts
.
Adding a role
To add a role, you can also simply follow the existing examples in the setup files. Keep in mind that each role requires its own new PermissionAssignment
objects.