prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Preset roles deletion is allowed
  **Describe the bug**
  Currently the preset roles like "organizer, coorganizer etc" should not be deleted from the db. But right now it is possible to delete these entries.
  
  **To Reproduce**
  Steps to reproduce the behavior:
  1. Hit the delete endpoint for role 
  2. Choose any of the ids pointing to any of the 7 preset roles
  3. You can find deletion to be successful
  
  **Expected behavior**
  <!-- A clear and concise description of what you expected to happen. -->
  
  **Stacktrace**
  <!-- If applicable, add stacktrace to help explain your problem. -->
  
  **Additional details (please complete the following information):**
   - OS: [e.g. MacOS, Ubuntu, CentOS]
   - Python Version [e.g. `3.5`, `3.6`]
   - `HEAD` Commit hash [e.g. `4629c62`]
  
  **Additional context**
  <!-- Add any other context about the problem here. -->
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `app/api/roles.py`
  Content:
  ```
  1 from flask_rest_jsonapi import ResourceDetail, ResourceList
  2 
  3 from app.api.bootstrap import api
  4 from app.api.helpers.db import safe_query_kwargs
  5 from app.api.helpers.errors import UnprocessableEntityError
  6 from app.api.schema.roles import RoleSchema
  7 from app.models import db
  8 from app.models.role import Role
  9 from app.models.role_invite import RoleInvite
  10 from app.models.users_events_role import UsersEventsRoles
  11 
  12 
  13 class RoleList(ResourceList):
  14     """
  15     List and create role
  16     """
  17 
  18     decorators = (api.has_permission('is_admin', methods="POST"),)
  19     schema = RoleSchema
  20     data_layer = {'session': db.session, 'model': Role}
  21 
  22 
  23 class RoleDetail(ResourceDetail):
  24     """
  25     Role detail by id
  26     """
  27 
  28     def before_get_object(self, view_kwargs):
  29         """
  30         before get method to get the resource id for fetching details
  31         :param view_kwargs:
  32         :return:
  33         """
  34         if view_kwargs.get('role_invite_id') is not None:
  35             role_invite = safe_query_kwargs(RoleInvite, view_kwargs, 'role_invite_id')
  36             if role_invite.role_id is not None:
  37                 view_kwargs['id'] = role_invite.role_id
  38             else:
  39                 view_kwargs['id'] = None
  40 
  41         if view_kwargs.get('users_events_roles_id') is not None:
  42             users_events_role = safe_query_kwargs(
  43                 UsersEventsRoles,
  44                 view_kwargs,
  45                 'users_events_roles_id',
  46             )
  47 
  48             if users_events_role.role_id is not None:
  49                 view_kwargs['id'] = users_events_role.role_id
  50             else:
  51                 view_kwargs['id'] = None
  52 
  53     def before_update_object(self, role, data, view_kwargs):
  54         """
  55         Method to edit object
  56         :param role:
  57         :param data:
  58         :param view_kwargs:
  59         :return:
  60         """
  61         if data.get('name'):
  62             if data['name'] in [
  63                 'owner',
  64                 'organizer',
  65                 'coorganizer',
  66                 'registrar',
  67                 'moderator',
  68                 'attendee',
  69                 'track_organizer',
  70             ]:
  71                 raise UnprocessableEntityError(
  72                     {'data': 'name'}, "The given name cannot be updated"
  73                 )
  74 
  75     def before_delete_object(self, obj, kwargs):
  76         """
  77         method to check proper resource name before deleting
  78         :param obj:
  79         :param kwargs:
  80         :return:
  81         """
  82         if obj.name in [
  83             'owner',
  84             'organizer',
  85             'coorganizer',
  86             'registrar',
  87             'moderator',
  88             'attendee',
  89             'track_organizer',
  90         ]:
  91             raise UnprocessableEntityError(
  92                 {'data': 'name'}, "The resource with given name cannot be deleted"
  93             )
  94 
  95     decorators = (api.has_permission('is_admin', methods="PATCH,DELETE"),)
  96     schema = RoleSchema
  97     data_layer = {
  98         'session': db.session,
  99         'model': Role,
  100         'methods': {'before_get_object': before_get_object},
  101     }
  102
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/app/api/roles.py b/app/api/roles.py
  --- a/app/api/roles.py
  +++ b/app/api/roles.py
  @@ -97,5 +97,8 @@
       data_layer = {
           'session': db.session,
           'model': Role,
  -        'methods': {'before_get_object': before_get_object},
  +        'methods': {
  +            'before_get_object': before_get_object,
  +            'before_delete_object': before_delete_object,
  +        },
       }
  
verification_info: {"golden_diff": "diff --git a/app/api/roles.py b/app/api/roles.py\n--- a/app/api/roles.py\n+++ b/app/api/roles.py\n@@ -97,5 +97,8 @@\n     data_layer = {\n         'session': db.session,\n         'model': Role,\n-        'methods': {'before_get_object': before_get_object},\n+        'methods': {\n+            'before_get_object': before_get_object,\n+            'before_delete_object': before_delete_object,\n+        },\n     }\n", "issue": "Preset roles deletion is allowed\n**Describe the bug**\r\nCurrently the preset roles like \"organizer, coorganizer etc\" should not be deleted from the db. But right now it is possible to delete these entries.\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. Hit the delete endpoint for role \r\n2. Choose any of the ids pointing to any of the 7 preset roles\r\n3. You can find deletion to be successful\r\n\r\n**Expected behavior**\r\n<!-- A clear and concise description of what you expected to happen. -->\r\n\r\n**Stacktrace**\r\n<!-- If applicable, add stacktrace to help explain your problem. -->\r\n\r\n**Additional details (please complete the following information):**\r\n - OS: [e.g. MacOS, Ubuntu, CentOS]\r\n - Python Version [e.g. `3.5`, `3.6`]\r\n - `HEAD` Commit hash [e.g. `4629c62`]\r\n\r\n**Additional context**\r\n<!-- Add any other context about the problem here. -->\r\n\n", "before_files": [{"content": "from flask_rest_jsonapi import ResourceDetail, ResourceList\n\nfrom app.api.bootstrap import api\nfrom app.api.helpers.db import safe_query_kwargs\nfrom app.api.helpers.errors import UnprocessableEntityError\nfrom app.api.schema.roles import RoleSchema\nfrom app.models import db\nfrom app.models.role import Role\nfrom app.models.role_invite import RoleInvite\nfrom app.models.users_events_role import UsersEventsRoles\n\n\nclass RoleList(ResourceList):\n    \"\"\"\n    List and create role\n    \"\"\"\n\n    decorators = (api.has_permission('is_admin', methods=\"POST\"),)\n    schema = RoleSchema\n    data_layer = {'session': db.session, 'model': Role}\n\n\nclass RoleDetail(ResourceDetail):\n    \"\"\"\n    Role detail by id\n    \"\"\"\n\n    def before_get_object(self, view_kwargs):\n        \"\"\"\n        before get method to get the resource id for fetching details\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if view_kwargs.get('role_invite_id') is not None:\n            role_invite = safe_query_kwargs(RoleInvite, view_kwargs, 'role_invite_id')\n            if role_invite.role_id is not None:\n                view_kwargs['id'] = role_invite.role_id\n            else:\n                view_kwargs['id'] = None\n\n        if view_kwargs.get('users_events_roles_id') is not None:\n            users_events_role = safe_query_kwargs(\n                UsersEventsRoles,\n                view_kwargs,\n                'users_events_roles_id',\n            )\n\n            if users_events_role.role_id is not None:\n                view_kwargs['id'] = users_events_role.role_id\n            else:\n                view_kwargs['id'] = None\n\n    def before_update_object(self, role, data, view_kwargs):\n        \"\"\"\n        Method to edit object\n        :param role:\n        :param data:\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if data.get('name'):\n            if data['name'] in [\n                'owner',\n                'organizer',\n                'coorganizer',\n                'registrar',\n                'moderator',\n                'attendee',\n                'track_organizer',\n            ]:\n                raise UnprocessableEntityError(\n                    {'data': 'name'}, \"The given name cannot be updated\"\n                )\n\n    def before_delete_object(self, obj, kwargs):\n        \"\"\"\n        method to check proper resource name before deleting\n        :param obj:\n        :param kwargs:\n        :return:\n        \"\"\"\n        if obj.name in [\n            'owner',\n            'organizer',\n            'coorganizer',\n            'registrar',\n            'moderator',\n            'attendee',\n            'track_organizer',\n        ]:\n            raise UnprocessableEntityError(\n                {'data': 'name'}, \"The resource with given name cannot be deleted\"\n            )\n\n    decorators = (api.has_permission('is_admin', methods=\"PATCH,DELETE\"),)\n    schema = RoleSchema\n    data_layer = {\n        'session': db.session,\n        'model': Role,\n        'methods': {'before_get_object': before_get_object},\n    }\n", "path": "app/api/roles.py"}], "after_files": [{"content": "from flask_rest_jsonapi import ResourceDetail, ResourceList\n\nfrom app.api.bootstrap import api\nfrom app.api.helpers.db import safe_query_kwargs\nfrom app.api.helpers.errors import UnprocessableEntityError\nfrom app.api.schema.roles import RoleSchema\nfrom app.models import db\nfrom app.models.role import Role\nfrom app.models.role_invite import RoleInvite\nfrom app.models.users_events_role import UsersEventsRoles\n\n\nclass RoleList(ResourceList):\n    \"\"\"\n    List and create role\n    \"\"\"\n\n    decorators = (api.has_permission('is_admin', methods=\"POST\"),)\n    schema = RoleSchema\n    data_layer = {'session': db.session, 'model': Role}\n\n\nclass RoleDetail(ResourceDetail):\n    \"\"\"\n    Role detail by id\n    \"\"\"\n\n    def before_get_object(self, view_kwargs):\n        \"\"\"\n        before get method to get the resource id for fetching details\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if view_kwargs.get('role_invite_id') is not None:\n            role_invite = safe_query_kwargs(RoleInvite, view_kwargs, 'role_invite_id')\n            if role_invite.role_id is not None:\n                view_kwargs['id'] = role_invite.role_id\n            else:\n                view_kwargs['id'] = None\n\n        if view_kwargs.get('users_events_roles_id') is not None:\n            users_events_role = safe_query_kwargs(\n                UsersEventsRoles,\n                view_kwargs,\n                'users_events_roles_id',\n            )\n\n            if users_events_role.role_id is not None:\n                view_kwargs['id'] = users_events_role.role_id\n            else:\n                view_kwargs['id'] = None\n\n    def before_update_object(self, role, data, view_kwargs):\n        \"\"\"\n        Method to edit object\n        :param role:\n        :param data:\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if data.get('name'):\n            if data['name'] in [\n                'owner',\n                'organizer',\n                'coorganizer',\n                'registrar',\n                'moderator',\n                'attendee',\n                'track_organizer',\n            ]:\n                raise UnprocessableEntityError(\n                    {'data': 'name'}, \"The given name cannot be updated\"\n                )\n\n    def before_delete_object(self, obj, kwargs):\n        \"\"\"\n        method to check proper resource name before deleting\n        :param obj:\n        :param kwargs:\n        :return:\n        \"\"\"\n        if obj.name in [\n            'owner',\n            'organizer',\n            'coorganizer',\n            'registrar',\n            'moderator',\n            'attendee',\n            'track_organizer',\n        ]:\n            raise UnprocessableEntityError(\n                {'data': 'name'}, \"The resource with given name cannot be deleted\"\n            )\n\n    decorators = (api.has_permission('is_admin', methods=\"PATCH,DELETE\"),)\n    schema = RoleSchema\n    data_layer = {\n        'session': db.session,\n        'model': Role,\n        'methods': {\n            'before_get_object': before_get_object,\n            'before_delete_object': before_delete_object,\n        },\n    }\n", "path": "app/api/roles.py"}]}