Repository: fossasia/open-event-server

Issue:
Ticket-tag: remove GET for /ticket-tags 
Parent issue #4101.
Related issue: #4119.

Make `/ticket-tags` POST only.


Discussion:

Resolving patch:
diff --git a/app/api/ticket_tags.py b/app/api/ticket_tags.py
--- a/app/api/ticket_tags.py
+++ b/app/api/ticket_tags.py
@@ -1,8 +1,6 @@
 from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship
 from marshmallow_jsonapi.flask import Schema, Relationship
 from marshmallow_jsonapi import fields
-from sqlalchemy.orm.exc import NoResultFound
-from flask_rest_jsonapi.exceptions import ObjectNotFound
 
 from app.api.helpers.utilities import dasherize
 from app.api.helpers.permissions import jwt_required
@@ -65,32 +63,10 @@ def before_post(self, args, kwargs, data):
         if not has_access('is_coorganizer', event_id=data['event']):
             raise ForbiddenException({'source': ''}, 'Co-organizer access is required.')
 
-    def after_create_object(self, obj, data, view_kwargs):
-        """
-        method to add ticket tags and ticket in association table
-        :param obj:
-        :param data:
-        :param view_kwargs:
-        :return:
-        """
-        if 'tickets' in data:
-            ticket_ids = data['tickets']
-            for ticket_id in ticket_ids:
-                try:
-                    ticket = Ticket.query.filter_by(id=ticket_id).one()
-                except NoResultFound:
-                    raise ObjectNotFound({'parameter': 'ticket_id'},
-                                         "Ticket: {} not found".format(ticket_id))
-                else:
-                    ticket.tags.append(obj)
-                    self.session.commit()
-
     schema = TicketTagSchema
+    methods = ['POST', ]
     data_layer = {'session': db.session,
-                  'model': TicketTag,
-                  'methods': {
-                    'after_create_object': after_create_object
-                  }}
+                  'model': TicketTag}
 
 
 class TicketTagList(ResourceList):


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -1040,19 +1040,6 @@ def ticket_fees_delete(transaction):
 
 
 # ------------------------- Ticket Tags -------------------------
-@hooks.before("Ticket Tags > Ticket Tags Collection > List All Ticket Tags")
-def ticket_tag_get_list(transaction):
-    """
-    GET /ticket-tags
-    :param transaction:
-    :return:
-    """
-    with stash['app'].app_context():
-        ticket_tag = TicketTagFactory()
-        db.session.add(ticket_tag)
-        db.session.commit()
-
-
 @hooks.before("Ticket Tags > Ticket Tags Collection > Create Ticket Tag")
 def ticket_tag_post(transaction):
     """
@@ -1105,6 +1092,32 @@ def ticket_tag_delete(transaction):
         db.session.commit()
 
 
+@hooks.before("Ticket Tags > List Ticket Tags under an Event > List all Ticket Tags")
+def ticket_tag_event(transaction):
+    """
+    GET /events/1/ticket-tags
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        ticket_tag = TicketTagFactory()
+        db.session.add(ticket_tag)
+        db.session.commit()
+
+
+@hooks.before("Ticket Tags > List Ticket Tags for a Ticket > List all Ticket Tags")
+def ticket_tag_ticket(transaction):
+    """
+    GET /tickets/1/ticket-tags
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        ticket_tag = TicketTagFactory()
+        db.session.add(ticket_tag)
+        db.session.commit()
+
+
 # ---------------------- Attendees (Ticket Holder) ---------------------
 @hooks.before("Attendees > Attendees Collection > List All Attendees")
 def attendee_get_list(transaction):