prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Change is-ticketing-enabled field of Event to dump_only
  **I'm submitting a ...**  (check one with "x")
  - [ ] bug report
  - [x] feature request
  - [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-server
  
  **Current behavior:**
  It is possible to create tickets for an event in which is-ticketing-enabled field is set to false.
  
  **Expected behavior:**
  Either the field should be made dump_only or appropiate constraints must be imposed to ckeck this behaviour.
  
  **Steps to reproduce:**
  1. Create an event with is-ticketing-enabled attribute to false.
  2. Create Ticket for that Event.
  
  
  --- 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/tickets.py`
  Content:
  ```
  1 from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship
  2 from flask_rest_jsonapi.exceptions import ObjectNotFound
  3 
  4 from app.api.bootstrap import api
  5 from app.api.helpers.db import safe_query
  6 from app.api.helpers.permission_manager import has_access
  7 from app.api.helpers.query import event_query
  8 from app.api.helpers.utilities import require_relationship
  9 from app.api.schema.tickets import TicketSchema, TicketSchemaPublic
  10 from app.models import db
  11 from app.models.access_code import AccessCode
  12 from app.models.order import Order
  13 from app.models.ticket import Ticket, TicketTag, ticket_tags_table
  14 from app.models.ticket_holder import TicketHolder
  15 from app.api.helpers.exceptions import ConflictException
  16 from app.api.helpers.db import get_count
  17 
  18 
  19 class TicketListPost(ResourceList):
  20     """
  21     Create and List Tickets
  22     """
  23     def before_post(self, args, kwargs, data):
  24         """
  25         before post method to check for required relationship and proper permission
  26         :param args:
  27         :param kwargs:
  28         :param data:
  29         :return:
  30         """
  31         require_relationship(['event'], data)
  32         if not has_access('is_coorganizer', event_id=data['event']):
  33             raise ObjectNotFound({'parameter': 'event_id'},
  34                                  "Event: {} not found".format(data['event_id']))
  35 
  36         if get_count(db.session.query(Ticket.id).filter_by(name=data['name'], event_id=int(data['event']))) > 0:
  37             raise ConflictException({'pointer': '/data/attributes/name'}, "Ticket already exists")
  38 
  39     schema = TicketSchema
  40     methods = ['POST', ]
  41     data_layer = {'session': db.session,
  42                   'model': Ticket}
  43 
  44 
  45 class TicketList(ResourceList):
  46     """
  47     List Tickets based on different params
  48     """
  49     def before_get(self, args, view_kwargs):
  50         """
  51         before get method to get the resource id for assigning schema
  52         :param args:
  53         :param view_kwargs:
  54         :return:
  55         """
  56         if view_kwargs.get('ticket_tag_id') or view_kwargs.get('access_code_id') or view_kwargs.get('order_identifier'):
  57             self.schema = TicketSchemaPublic
  58 
  59     def query(self, view_kwargs):
  60         """
  61         query method for resource list
  62         :param view_kwargs:
  63         :return:
  64         """
  65         query_ = self.session.query(Ticket).filter_by(is_hidden=False)
  66         if view_kwargs.get('ticket_tag_id'):
  67             ticket_tag = safe_query(self, TicketTag, 'id', view_kwargs['ticket_tag_id'], 'ticket_tag_id')
  68             query_ = query_.join(ticket_tags_table).filter_by(ticket_tag_id=ticket_tag.id)
  69         query_ = event_query(self, query_, view_kwargs)
  70         if view_kwargs.get('access_code_id'):
  71             access_code = safe_query(self, AccessCode, 'id', view_kwargs['access_code_id'], 'access_code_id')
  72             # access_code - ticket :: many-to-many relationship
  73             query_ = Ticket.query.filter(Ticket.access_codes.any(id=access_code.id))
  74 
  75         if view_kwargs.get('order_identifier'):
  76             order = safe_query(self, Order, 'identifier', view_kwargs['order_identifier'], 'order_identifier')
  77             ticket_ids = []
  78             for ticket in order.tickets:
  79                 ticket_ids.append(ticket.id)
  80             query_ = query_.filter(Ticket.id.in_(tuple(ticket_ids)))
  81 
  82         return query_
  83 
  84     view_kwargs = True
  85     methods = ['GET', ]
  86     decorators = (api.has_permission('is_coorganizer', fetch='event_id',
  87                   fetch_as="event_id", model=Ticket, methods="POST",
  88                   check=lambda a: a.get('event_id') or a.get('event_identifier')),)
  89     schema = TicketSchema
  90     data_layer = {'session': db.session,
  91                   'model': Ticket,
  92                   'methods': {
  93                       'query': query,
  94                   }}
  95 
  96 
  97 class TicketDetail(ResourceDetail):
  98     """
  99     Ticket Resource
  100     """
  101     def before_get(self, args, view_kwargs):
  102         """
  103         before get method to get the resource id for assigning schema
  104         :param args:
  105         :param view_kwargs:
  106         :return:
  107         """
  108         if view_kwargs.get('attendee_id'):
  109             self.schema = TicketSchemaPublic
  110 
  111     def before_get_object(self, view_kwargs):
  112         """
  113         before get object method to get the resource id for fetching details
  114         :param view_kwargs:
  115         :return:
  116         """
  117         if view_kwargs.get('attendee_id') is not None:
  118             attendee = safe_query(self, TicketHolder, 'id', view_kwargs['attendee_id'], 'attendee_id')
  119             if attendee.ticket_id is not None:
  120                 view_kwargs['id'] = attendee.ticket_id
  121             else:
  122                 view_kwargs['id'] = None
  123 
  124     decorators = (api.has_permission('is_coorganizer', fetch='event_id',
  125                   fetch_as="event_id", model=Ticket, methods="PATCH,DELETE"),)
  126     schema = TicketSchema
  127     data_layer = {'session': db.session,
  128                   'model': Ticket,
  129                   'methods': {
  130                       'before_get_object': before_get_object
  131                   }}
  132 
  133 
  134 class TicketRelationshipRequired(ResourceRelationship):
  135     """
  136     Tickets Relationship (Required)
  137     """
  138     decorators = (api.has_permission('is_coorganizer', fetch='event_id',
  139                                      fetch_as="event_id", model=Ticket, methods="PATCH"),)
  140     methods = ['GET', 'PATCH']
  141     schema = TicketSchema
  142     data_layer = {'session': db.session,
  143                   'model': Ticket}
  144 
  145 
  146 class TicketRelationshipOptional(ResourceRelationship):
  147     """
  148     Tickets Relationship (Optional)
  149     """
  150     decorators = (api.has_permission('is_coorganizer', fetch='event_id',
  151                                      fetch_as="event_id", model=Ticket, methods="PATCH,DELETE"),)
  152     schema = TicketSchema
  153     data_layer = {'session': db.session,
  154                   'model': Ticket}
  155
  ```
  --- 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/tickets.py b/app/api/tickets.py
  --- a/app/api/tickets.py
  +++ b/app/api/tickets.py
  @@ -11,8 +11,9 @@
   from app.models.access_code import AccessCode
   from app.models.order import Order
   from app.models.ticket import Ticket, TicketTag, ticket_tags_table
  +from app.models.event import Event
   from app.models.ticket_holder import TicketHolder
  -from app.api.helpers.exceptions import ConflictException
  +from app.api.helpers.exceptions import ConflictException, MethodNotAllowed
   from app.api.helpers.db import get_count
   
   
  @@ -36,6 +37,9 @@
           if get_count(db.session.query(Ticket.id).filter_by(name=data['name'], event_id=int(data['event']))) > 0:
               raise ConflictException({'pointer': '/data/attributes/name'}, "Ticket already exists")
   
  +        if get_count(db.session.query(Event).filter_by(id=int(data['event']), is_ticketing_enabled=False)) > 0:
  +            raise MethodNotAllowed({'parameter': 'event_id'}, "Ticketing is disabled for this Event")
  +
       schema = TicketSchema
       methods = ['POST', ]
       data_layer = {'session': db.session,
  
verification_info: {"golden_diff": "diff --git a/app/api/tickets.py b/app/api/tickets.py\n--- a/app/api/tickets.py\n+++ b/app/api/tickets.py\n@@ -11,8 +11,9 @@\n from app.models.access_code import AccessCode\n from app.models.order import Order\n from app.models.ticket import Ticket, TicketTag, ticket_tags_table\n+from app.models.event import Event\n from app.models.ticket_holder import TicketHolder\n-from app.api.helpers.exceptions import ConflictException\n+from app.api.helpers.exceptions import ConflictException, MethodNotAllowed\n from app.api.helpers.db import get_count\n \n \n@@ -36,6 +37,9 @@\n         if get_count(db.session.query(Ticket.id).filter_by(name=data['name'], event_id=int(data['event']))) > 0:\n             raise ConflictException({'pointer': '/data/attributes/name'}, \"Ticket already exists\")\n \n+        if get_count(db.session.query(Event).filter_by(id=int(data['event']), is_ticketing_enabled=False)) > 0:\n+            raise MethodNotAllowed({'parameter': 'event_id'}, \"Ticketing is disabled for this Event\")\n+\n     schema = TicketSchema\n     methods = ['POST', ]\n     data_layer = {'session': db.session,\n", "issue": "Change is-ticketing-enabled field of Event to dump_only\n**I'm submitting a ...**  (check one with \"x\")\r\n- [ ] bug report\r\n- [x] feature request\r\n- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-server\r\n\r\n**Current behavior:**\r\nIt is possible to create tickets for an event in which is-ticketing-enabled field is set to false.\r\n\r\n**Expected behavior:**\r\nEither the field should be made dump_only or appropiate constraints must be imposed to ckeck this behaviour.\r\n\r\n**Steps to reproduce:**\r\n1. Create an event with is-ticketing-enabled attribute to false.\r\n2. Create Ticket for that Event.\r\n\n", "before_files": [{"content": "from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship\nfrom flask_rest_jsonapi.exceptions import ObjectNotFound\n\nfrom app.api.bootstrap import api\nfrom app.api.helpers.db import safe_query\nfrom app.api.helpers.permission_manager import has_access\nfrom app.api.helpers.query import event_query\nfrom app.api.helpers.utilities import require_relationship\nfrom app.api.schema.tickets import TicketSchema, TicketSchemaPublic\nfrom app.models import db\nfrom app.models.access_code import AccessCode\nfrom app.models.order import Order\nfrom app.models.ticket import Ticket, TicketTag, ticket_tags_table\nfrom app.models.ticket_holder import TicketHolder\nfrom app.api.helpers.exceptions import ConflictException\nfrom app.api.helpers.db import get_count\n\n\nclass TicketListPost(ResourceList):\n    \"\"\"\n    Create and List Tickets\n    \"\"\"\n    def before_post(self, args, kwargs, data):\n        \"\"\"\n        before post method to check for required relationship and proper permission\n        :param args:\n        :param kwargs:\n        :param data:\n        :return:\n        \"\"\"\n        require_relationship(['event'], data)\n        if not has_access('is_coorganizer', event_id=data['event']):\n            raise ObjectNotFound({'parameter': 'event_id'},\n                                 \"Event: {} not found\".format(data['event_id']))\n\n        if get_count(db.session.query(Ticket.id).filter_by(name=data['name'], event_id=int(data['event']))) > 0:\n            raise ConflictException({'pointer': '/data/attributes/name'}, \"Ticket already exists\")\n\n    schema = TicketSchema\n    methods = ['POST', ]\n    data_layer = {'session': db.session,\n                  'model': Ticket}\n\n\nclass TicketList(ResourceList):\n    \"\"\"\n    List Tickets based on different params\n    \"\"\"\n    def before_get(self, args, view_kwargs):\n        \"\"\"\n        before get method to get the resource id for assigning schema\n        :param args:\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if view_kwargs.get('ticket_tag_id') or view_kwargs.get('access_code_id') or view_kwargs.get('order_identifier'):\n            self.schema = TicketSchemaPublic\n\n    def query(self, view_kwargs):\n        \"\"\"\n        query method for resource list\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        query_ = self.session.query(Ticket).filter_by(is_hidden=False)\n        if view_kwargs.get('ticket_tag_id'):\n            ticket_tag = safe_query(self, TicketTag, 'id', view_kwargs['ticket_tag_id'], 'ticket_tag_id')\n            query_ = query_.join(ticket_tags_table).filter_by(ticket_tag_id=ticket_tag.id)\n        query_ = event_query(self, query_, view_kwargs)\n        if view_kwargs.get('access_code_id'):\n            access_code = safe_query(self, AccessCode, 'id', view_kwargs['access_code_id'], 'access_code_id')\n            # access_code - ticket :: many-to-many relationship\n            query_ = Ticket.query.filter(Ticket.access_codes.any(id=access_code.id))\n\n        if view_kwargs.get('order_identifier'):\n            order = safe_query(self, Order, 'identifier', view_kwargs['order_identifier'], 'order_identifier')\n            ticket_ids = []\n            for ticket in order.tickets:\n                ticket_ids.append(ticket.id)\n            query_ = query_.filter(Ticket.id.in_(tuple(ticket_ids)))\n\n        return query_\n\n    view_kwargs = True\n    methods = ['GET', ]\n    decorators = (api.has_permission('is_coorganizer', fetch='event_id',\n                  fetch_as=\"event_id\", model=Ticket, methods=\"POST\",\n                  check=lambda a: a.get('event_id') or a.get('event_identifier')),)\n    schema = TicketSchema\n    data_layer = {'session': db.session,\n                  'model': Ticket,\n                  'methods': {\n                      'query': query,\n                  }}\n\n\nclass TicketDetail(ResourceDetail):\n    \"\"\"\n    Ticket Resource\n    \"\"\"\n    def before_get(self, args, view_kwargs):\n        \"\"\"\n        before get method to get the resource id for assigning schema\n        :param args:\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if view_kwargs.get('attendee_id'):\n            self.schema = TicketSchemaPublic\n\n    def before_get_object(self, view_kwargs):\n        \"\"\"\n        before get object method to get the resource id for fetching details\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if view_kwargs.get('attendee_id') is not None:\n            attendee = safe_query(self, TicketHolder, 'id', view_kwargs['attendee_id'], 'attendee_id')\n            if attendee.ticket_id is not None:\n                view_kwargs['id'] = attendee.ticket_id\n            else:\n                view_kwargs['id'] = None\n\n    decorators = (api.has_permission('is_coorganizer', fetch='event_id',\n                  fetch_as=\"event_id\", model=Ticket, methods=\"PATCH,DELETE\"),)\n    schema = TicketSchema\n    data_layer = {'session': db.session,\n                  'model': Ticket,\n                  'methods': {\n                      'before_get_object': before_get_object\n                  }}\n\n\nclass TicketRelationshipRequired(ResourceRelationship):\n    \"\"\"\n    Tickets Relationship (Required)\n    \"\"\"\n    decorators = (api.has_permission('is_coorganizer', fetch='event_id',\n                                     fetch_as=\"event_id\", model=Ticket, methods=\"PATCH\"),)\n    methods = ['GET', 'PATCH']\n    schema = TicketSchema\n    data_layer = {'session': db.session,\n                  'model': Ticket}\n\n\nclass TicketRelationshipOptional(ResourceRelationship):\n    \"\"\"\n    Tickets Relationship (Optional)\n    \"\"\"\n    decorators = (api.has_permission('is_coorganizer', fetch='event_id',\n                                     fetch_as=\"event_id\", model=Ticket, methods=\"PATCH,DELETE\"),)\n    schema = TicketSchema\n    data_layer = {'session': db.session,\n                  'model': Ticket}\n", "path": "app/api/tickets.py"}], "after_files": [{"content": "from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship\nfrom flask_rest_jsonapi.exceptions import ObjectNotFound\n\nfrom app.api.bootstrap import api\nfrom app.api.helpers.db import safe_query\nfrom app.api.helpers.permission_manager import has_access\nfrom app.api.helpers.query import event_query\nfrom app.api.helpers.utilities import require_relationship\nfrom app.api.schema.tickets import TicketSchema, TicketSchemaPublic\nfrom app.models import db\nfrom app.models.access_code import AccessCode\nfrom app.models.order import Order\nfrom app.models.ticket import Ticket, TicketTag, ticket_tags_table\nfrom app.models.event import Event\nfrom app.models.ticket_holder import TicketHolder\nfrom app.api.helpers.exceptions import ConflictException, MethodNotAllowed\nfrom app.api.helpers.db import get_count\n\n\nclass TicketListPost(ResourceList):\n    \"\"\"\n    Create and List Tickets\n    \"\"\"\n    def before_post(self, args, kwargs, data):\n        \"\"\"\n        before post method to check for required relationship and proper permission\n        :param args:\n        :param kwargs:\n        :param data:\n        :return:\n        \"\"\"\n        require_relationship(['event'], data)\n        if not has_access('is_coorganizer', event_id=data['event']):\n            raise ObjectNotFound({'parameter': 'event_id'},\n                                 \"Event: {} not found\".format(data['event_id']))\n\n        if get_count(db.session.query(Ticket.id).filter_by(name=data['name'], event_id=int(data['event']))) > 0:\n            raise ConflictException({'pointer': '/data/attributes/name'}, \"Ticket already exists\")\n\n        if get_count(db.session.query(Event).filter_by(id=int(data['event']), is_ticketing_enabled=False)) > 0:\n            raise MethodNotAllowed({'parameter': 'event_id'}, \"Ticketing is disabled for this Event\")\n\n    schema = TicketSchema\n    methods = ['POST', ]\n    data_layer = {'session': db.session,\n                  'model': Ticket}\n\n\nclass TicketList(ResourceList):\n    \"\"\"\n    List Tickets based on different params\n    \"\"\"\n    def before_get(self, args, view_kwargs):\n        \"\"\"\n        before get method to get the resource id for assigning schema\n        :param args:\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if view_kwargs.get('ticket_tag_id') or view_kwargs.get('access_code_id') or view_kwargs.get('order_identifier'):\n            self.schema = TicketSchemaPublic\n\n    def query(self, view_kwargs):\n        \"\"\"\n        query method for resource list\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        query_ = self.session.query(Ticket).filter_by(is_hidden=False)\n        if view_kwargs.get('ticket_tag_id'):\n            ticket_tag = safe_query(self, TicketTag, 'id', view_kwargs['ticket_tag_id'], 'ticket_tag_id')\n            query_ = query_.join(ticket_tags_table).filter_by(ticket_tag_id=ticket_tag.id)\n        query_ = event_query(self, query_, view_kwargs)\n        if view_kwargs.get('access_code_id'):\n            access_code = safe_query(self, AccessCode, 'id', view_kwargs['access_code_id'], 'access_code_id')\n            # access_code - ticket :: many-to-many relationship\n            query_ = Ticket.query.filter(Ticket.access_codes.any(id=access_code.id))\n\n        if view_kwargs.get('order_identifier'):\n            order = safe_query(self, Order, 'identifier', view_kwargs['order_identifier'], 'order_identifier')\n            ticket_ids = []\n            for ticket in order.tickets:\n                ticket_ids.append(ticket.id)\n            query_ = query_.filter(Ticket.id.in_(tuple(ticket_ids)))\n\n        return query_\n\n    view_kwargs = True\n    methods = ['GET', ]\n    decorators = (api.has_permission('is_coorganizer', fetch='event_id',\n                  fetch_as=\"event_id\", model=Ticket, methods=\"POST\",\n                  check=lambda a: a.get('event_id') or a.get('event_identifier')),)\n    schema = TicketSchema\n    data_layer = {'session': db.session,\n                  'model': Ticket,\n                  'methods': {\n                      'query': query,\n                  }}\n\n\nclass TicketDetail(ResourceDetail):\n    \"\"\"\n    Ticket Resource\n    \"\"\"\n    def before_get(self, args, view_kwargs):\n        \"\"\"\n        before get method to get the resource id for assigning schema\n        :param args:\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if view_kwargs.get('attendee_id'):\n            self.schema = TicketSchemaPublic\n\n    def before_get_object(self, view_kwargs):\n        \"\"\"\n        before get object method to get the resource id for fetching details\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if view_kwargs.get('attendee_id') is not None:\n            attendee = safe_query(self, TicketHolder, 'id', view_kwargs['attendee_id'], 'attendee_id')\n            if attendee.ticket_id is not None:\n                view_kwargs['id'] = attendee.ticket_id\n            else:\n                view_kwargs['id'] = None\n\n    decorators = (api.has_permission('is_coorganizer', fetch='event_id',\n                  fetch_as=\"event_id\", model=Ticket, methods=\"PATCH,DELETE\"),)\n    schema = TicketSchema\n    data_layer = {'session': db.session,\n                  'model': Ticket,\n                  'methods': {\n                      'before_get_object': before_get_object\n                  }}\n\n\nclass TicketRelationshipRequired(ResourceRelationship):\n    \"\"\"\n    Tickets Relationship (Required)\n    \"\"\"\n    decorators = (api.has_permission('is_coorganizer', fetch='event_id',\n                                     fetch_as=\"event_id\", model=Ticket, methods=\"PATCH\"),)\n    methods = ['GET', 'PATCH']\n    schema = TicketSchema\n    data_layer = {'session': db.session,\n                  'model': Ticket}\n\n\nclass TicketRelationshipOptional(ResourceRelationship):\n    \"\"\"\n    Tickets Relationship (Optional)\n    \"\"\"\n    decorators = (api.has_permission('is_coorganizer', fetch='event_id',\n                                     fetch_as=\"event_id\", model=Ticket, methods=\"PATCH,DELETE\"),)\n    schema = TicketSchema\n    data_layer = {'session': db.session,\n                  'model': Ticket}\n", "path": "app/api/tickets.py"}]}