Repository: fossasia/open-event-server

Issue:
Add API for create, edit, delete and get system roles
**Describe the bug**
The existing roles API is meant only for the event roles. 

**Expected behavior**
Add API for creating, editing, deleting and getting system roles. The corresponding POST, PATCH and DELETE roles API can be removed as the event roles are fixed and shouldn't be modified.


Discussion:

Resolving patch:
diff --git a/app/api/__init__.py b/app/api/__init__.py
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -37,6 +37,7 @@
 from app.api.event_image_sizes import EventImageSizeDetail
 from app.api.speaker_image_sizes import SpeakerImageSizeDetail
 from app.api.roles import RoleList, RoleDetail
+from app.api.custom_system_roles import CustomSystemRoleList, CustomSystemRoleDetail
 from app.api.session_types import SessionTypeList, SessionTypeListPost, SessionTypeDetail, \
     SessionTypeRelationshipRequired, SessionTypeRelationshipOptional
 from app.api.event_copyright import EventCopyrightListPost, EventCopyrightDetail, EventCopyrightRelationshipRequired
@@ -190,6 +191,10 @@
 api.route(RoleList, 'role_list', '/roles')
 api.route(RoleDetail, 'role_detail', '/roles/<int:id>', '/role-invites/<int:role_invite_id>/role')
 
+# custom system roles
+api.route(CustomSystemRoleList, 'custom_system_role_list', '/custom-system-roles')
+api.route(CustomSystemRoleDetail, 'custom_system_role_detail', '/custom-system-roles/<int:id>')
+
 # role_invites
 api.route(RoleInviteListPost, 'role_invite_list_post', '/role-invites')
 api.route(RoleInviteList, 'role_invite_list', '/events/<int:event_id>/role-invites',
diff --git a/app/api/custom_system_roles.py b/app/api/custom_system_roles.py
new file mode 100644
--- /dev/null
+++ b/app/api/custom_system_roles.py
@@ -0,0 +1,27 @@
+from flask_rest_jsonapi import ResourceDetail, ResourceList
+
+from app.api.bootstrap import api
+from app.api.schema.custom_system_roles import CustomSystemRoleSchema
+from app.models import db
+from app.models.custom_system_role import CustomSysRole
+
+
+class CustomSystemRoleList(ResourceList):
+    """
+    List and create Custom System Role
+    """
+    decorators = (api.has_permission('is_admin', methods="POST"),)
+    schema = CustomSystemRoleSchema
+    data_layer = {'session': db.session,
+                  'model': CustomSysRole}
+
+
+class CustomSystemRoleDetail(ResourceDetail):
+    """
+    Custom System Role detail by id
+    """
+
+    decorators = (api.has_permission('is_admin', methods="PATCH,DELETE"),)
+    schema = CustomSystemRoleSchema
+    data_layer = {'session': db.session,
+                  'model': CustomSysRole}
diff --git a/app/api/schema/custom_system_roles.py b/app/api/schema/custom_system_roles.py
new file mode 100644
--- /dev/null
+++ b/app/api/schema/custom_system_roles.py
@@ -0,0 +1,21 @@
+from marshmallow_jsonapi import fields
+from marshmallow_jsonapi.flask import Schema
+
+from app.api.helpers.utilities import dasherize
+
+
+class CustomSystemRoleSchema(Schema):
+    """
+    Api schema for Custom System Role Model
+    """
+    class Meta:
+        """
+        Meta class for Custom System Role Api Schema
+        """
+        type_ = 'custom-system-role'
+        self_view = 'v1.custom_system_role_detail'
+        self_view_kwargs = {'id': '<id>'}
+        inflect = dasherize
+
+    id = fields.Str(dump_only=True)
+    name = fields.Str(required=True)


Test patch: