In this blog, we will talk about how to add API for accessing the Custom System Roles on Open Event Server. The focus is on Schema creation and it’s API creation.
Schema Creation
For the CustomSystemRoleSchema, we’ll make our Schema as follows
Now, let’s try to understand this Schema.
In this feature, we are providing Admin the rights to get and create more system roles.
- First of all, we are provide the two fields in this Schema, which are id and name.
- The very first attribute id should be of type string as it would have the identity which will auto increment when a new system role is created. Here dump_only means that this value can’t be changed after the record is created.
- Next attribute name should be of string type and it will contain the name of new custom system role. This attribute is required in a custom_system_roles table.
API Creation
For the Custom System Roles, we’ll make our API as follows
Now, let’s try to understand this Schema.
In this API, we are providing Admin the rights to set Custom System roles.
- CustomSystemRoleList inherits ResourceList which will give us list of all the custom system roles in the whole system.
- CustomSystemRoleList has a decorators attribute which gives the permission of POST request to only admins of the system.
- CustomSystemRoleDetail inherits ResourceDetail which will give the details of a CustomSystemRole object by id.
- CustomSystemRoleDetail has a decorators attribute which gives the permission of PATCH and DELETE requests to only admins of the system.
So, we saw how Custom System Role Schema and API is created to allow users to get it’s values and Admin users to update and delete it’s record.
Resources
- Documentation | Marshmallow : https://marshmallow-jsonapi.readthedocs.io/en/latest/
- Documentation | Flask Rest JSONAPI : http://flask-rest-jsonapi.readthedocs.io/en/latest/
- Documentation | Roles in Open Event Server: https://github.com/fossasia/open-event-server/blob/development/docs/general/roles.md
You must log in to post a comment.