internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: fossasia/open-event-server

Issue:
Microlocations : GET requests return ERROR 500
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] 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-orga-server

Endpoint 
```
GET v1/events/<event_id>/microlocations 
```

Response
```
{
   "errors":[
      {
         "detail":"Unknown error",
         "source":{
            "pointer":""
         },
         "status":500,
         "title":"Unknown error"
      }
   ],
   "jsonapi":{
      "version":"1.0"
   }
}
```

Example URL
```
https://open-event-api.herokuapp.com/v1/events/173/microlocations
```



Discussion:
@fossasia/open-event-server-devs  Can you guys take a look at this? The error message is :
`BuildError: Could not build url for endpoint 'v1.session_list'. Did you forget to specify values ['microlocation_id']` . 

`'v1.session_list'` and the relationships with microlocation and session look fine to me, seems I can't figure out the issue :sweat_smile: !
I'm having similar issue in Discount Code API's PR :P
I think `event_query` method might be causing this. @shubham-padia Can you please check this once?

Resolving patch:
diff --git a/app/api/microlocations.py b/app/api/microlocations.py
--- a/app/api/microlocations.py
+++ b/app/api/microlocations.py
@@ -26,7 +26,7 @@ class Meta:
         type_ = 'microlocation'
         self_view = 'v1.microlocation_detail'
         self_view_kwargs = {'id': '<id>'}
-        self_view_many = 'v1.session_list'
+        self_view_many = 'v1.microlocation_list_post'
         inflect = dasherize
 
     id = fields.Str(dump_only=True)
@@ -36,6 +36,7 @@ class Meta:
     floor = fields.Integer(allow_none=True)
     room = fields.Str(allow_none=True)
     sessions = Relationship(attribute='session',
+                            many=True,
                             self_view='v1.microlocation_session',
                             self_view_kwargs={'id': '<id>'},
                             related_view='v1.session_list',


Test patch:
Repository: fossasia/open-event-server

Issue:
Add event sub-topic related endpoint to docs and dredd tests
Parent issue : #4009.


Discussion:

Resolving patch:
diff --git a/app/factories/custom_placeholder.py b/app/factories/custom_placeholder.py
--- a/app/factories/custom_placeholder.py
+++ b/app/factories/custom_placeholder.py
@@ -12,3 +12,4 @@ class Meta:
     origin = common.string_
     copyright = common.string_
     original_image_url = common.imageUrl_
+    event_sub_topic_id = None
diff --git a/app/models/custom_placeholder.py b/app/models/custom_placeholder.py
--- a/app/models/custom_placeholder.py
+++ b/app/models/custom_placeholder.py
@@ -29,7 +29,8 @@ def __init__(self,
                  large_image_url=None,
                  icon_image_url=None,
                  copyright=None,
-                 origin=None):
+                 origin=None,
+                 event_sub_topic_id=None):
         self.name = name
         self.original_image_url = original_image_url
         self.thumbnail_image_url = thumbnail_image_url
@@ -37,6 +38,7 @@ def __init__(self,
         self.icon_image_url = icon_image_url
         self.copyright = copyright
         self.origin = origin
+        self.event_sub_topic_id = event_sub_topic_id
 
     def __str__(self):
         return 'Name:' + unicode(self.name).encode('utf-8')


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -2726,6 +2726,39 @@ def event_sub_topic_delete(transaction):
         db.session.commit()
 
 
+@hooks.before("Event Sub Topics > Event Sub Topic of an Event > Event Sub Topic Details of an Event")
+def event_event_sub_topic_get_detail(transaction):
+    """
+    GET /events/1/event-sub-topic
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        event_sub_topic = EventSubTopicFactory()
+        db.session.add(event_sub_topic)
+
+        event = EventFactoryBasic(event_sub_topic_id=1)
+        db.session.add(event)
+        db.session.commit()
+
+
+@hooks.before(
+    "Event Sub Topics > Event Sub Topic of Custom Placeholder > Event Sub Topic Details of Custom Placeholder")
+def custom_placeholder_sub_topic_get_detail(transaction):
+    """
+    GET /custom-placeholders/1/event-sub-topic
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        event_sub_topic = EventSubTopicFactory()
+        db.session.add(event_sub_topic)
+
+        custom_placeholder = CustomPlaceholderFactory(event_sub_topic_id=1)
+        db.session.add(custom_placeholder)
+        db.session.commit()
+
+
 # ------------------------- Custom Placeholders -------------------------
 @hooks.before("Custom Placeholders > Custom Placeholders Collection > List All Event Custom Placeholders")
 def custom_placeholder_get_list(transaction):
Repository: fossasia/open-event-server

Issue:
Implement User Emails
Parent Issue: #4196 

Requires #4210 to be merged

- [x] Email verification email - To the user who registered
- [x] A welcome email - After registration. Before email verification. - To the user who registered
- [x] Forgot password reset email - To the user who registered
- [x] Email change notification (#4210) - To both the old email address and the new email address
- [ ] Password change notification - To the user


Discussion:

Resolving patch:
diff --git a/app/api/auth.py b/app/api/auth.py
--- a/app/api/auth.py
+++ b/app/api/auth.py
@@ -1,11 +1,14 @@
 import base64
+from flask import request, jsonify, abort, make_response, Blueprint
+from sqlalchemy.orm.exc import NoResultFound
 
-from flask import Blueprint, abort, make_response
-from flask import request, jsonify
-
+from app import get_settings
 from app.api.helpers.db import save_to_db
+from app.api.helpers.files import make_frontend_url
+from app.api.helpers.mail import send_email_with_action
 
 from app.api.helpers.utilities import get_serializer
+from app.models.mail import PASSWORD_RESET
 from app.models.user import User
 
 auth_routes = Blueprint('auth', __name__, url_prefix='/v1/auth')
@@ -31,6 +34,38 @@ def verify_email():
         )
     else:
         user.is_verified = True
+
+
+@auth_routes.route('/reset-password', methods=['POST'])
+def reset_password_post():
+    email = request.json['data']['email']
+
+    try:
+        user = User.query.filter_by(email=email).one()
+    except NoResultFound:
+        return abort(
+            make_response(jsonify(error="User not found"), 404)
+        )
+    else:
+        link = make_frontend_url('/reset-password', {'token': user.reset_password})
+        send_email_with_action(user, PASSWORD_RESET, app_name=get_settings()['app_name'], link=link)
+
+    return make_response(jsonify(message="Email Sent"), 200)
+
+
+@auth_routes.route('/reset-password', methods=['PATCH'])
+def reset_password_patch():
+    token = request.json['data']['token']
+    password = request.json['data']['password']
+
+    try:
+        user = User.query.filter_by(reset_password=token).one()
+    except NoResultFound:
+        return abort(
+            make_response(jsonify(error="User not found"), 404)
+        )
+    else:
+        user.password = password
         save_to_db(user)
 
     return jsonify({


Test patch:
Repository: fossasia/open-event-server

Issue:
GET request to discount codes for an event doesn't work with event identifier
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] 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-orga-server

**Current behavior:**
<!-- Describe how the bug manifests. -->
**GET**  *https://open-event-api.herokuapp.com/v1/events/<event-identifier\>/discount-codes*
results in 500 error
**GET**  *https://open-event-api.herokuapp.com/v1/events/<event-id\>/discount-codes* works . 
**Expected behavior:**
<!-- Describe what the behavior would be without the bug. -->
It should work for both identifier and id.



Discussion:

Resolving patch:
diff --git a/app/api/discount_codes.py b/app/api/discount_codes.py
--- a/app/api/discount_codes.py
+++ b/app/api/discount_codes.py
@@ -198,7 +198,7 @@ def query(self, view_kwargs):
             query_ = query_.join(User).filter(User.id == user.id)
 
         if view_kwargs.get('event_identifier'):
-            event = safe_query(self, Event, 'id', view_kwargs['event_id'], 'event_id')
+            event = safe_query(self, Event, 'identifier', view_kwargs['event_identifier'], 'event_identifier')
             view_kwargs['event_id'] = event.id
 
         if view_kwargs.get('event_id') and has_access('is_coorganizer', event_id=view_kwargs['event_id']):


Test patch:
Repository: fossasia/open-event-server

Issue:
Set attendees as required relationship to Orders API



Discussion:
Hi @poush!

Looks like you're missing some information we'll need to replicate this issue.

The easier it is for us to decipher an issue with the info provided,
the more likely it is that we'll be able to help.

Please make sure you have the following information in this issue:

1. The current (incorrect) behavior you're seeing.
2. The behavior you expect.
3. The OS version, browser, app, device you use.
4. A [short, self-contained example](http://sscce.org/).

Resolving patch:
diff --git a/app/api/orders.py b/app/api/orders.py
--- a/app/api/orders.py
+++ b/app/api/orders.py
@@ -113,7 +113,7 @@ def initial_values(self, data):
 
 class OrdersListPost(ResourceList):
     def before_post(self, args, kwargs, data=None):
-        require_relationship(['event'], data)
+        require_relationship(['event', 'attendees'], data)
         if not has_access('is_coorganizer', event_id=data['event']):
             data['status'] = 'pending'
 


Test patch:
Repository: fossasia/open-event-server

Issue:
Custom-forms: Change data.type in custom-form
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] 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-orga-server

**Current behavior:**
The type attribute is `custom_form` which leads to error 409 while making a request after #4300 

**Expected behavior:**
The type attribute should be `custom-form` 

@enigmaeth Can you please check?


Discussion:

Resolving patch:
diff --git a/app/api/custom_forms.py b/app/api/custom_forms.py
--- a/app/api/custom_forms.py
+++ b/app/api/custom_forms.py
@@ -24,7 +24,7 @@ class Meta:
         """
         Meta class for CustomForm Schema
         """
-        type_ = 'custom_form'
+        type_ = 'custom-form'
         self_view = 'v1.custom_form_detail'
         self_view_kwargs = {'id': '<id>'}
         inflect = dasherize


Test patch:
Repository: fossasia/open-event-server

Issue:
Pages API: Only allow `footer` or `event` in `places` attribute



Discussion:

Resolving patch:
diff --git a/app/api/pages.py b/app/api/pages.py
--- a/app/api/pages.py
+++ b/app/api/pages.py
@@ -1,6 +1,7 @@
 from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship
 from marshmallow_jsonapi.flask import Schema, Relationship
 from marshmallow_jsonapi import fields
+import marshmallow.validate as validate
 
 from app.api.bootstrap import api
 from app.api.helpers.utilities import dasherize
@@ -26,7 +27,7 @@ class Meta:
     title = fields.Str(allow_none=True)
     url = fields.String(required=True)
     description = fields.Str(allow_none=True)
-    place = fields.Str(allow_none=True)
+    place = fields.Str(validate=validate.OneOf(choices=["footer", "event"]), allow_none=True)
     language = fields.Str(allow_none=True)
     index = fields.Integer(default=0)
 


Test patch:
Repository: fossasia/open-event-server

Issue:
Add email to valid types in custom-form
**Current**
Currently we are not able to set an email type to the custom-form which leads to `Error: 422`.

**Expected**
email should be a valid type for the custom-form


Discussion:

Resolving patch:
diff --git a/app/api/custom_forms.py b/app/api/custom_forms.py
--- a/app/api/custom_forms.py
+++ b/app/api/custom_forms.py
@@ -33,7 +33,7 @@ class Meta:
     field_identifier = fields.Str(required=True)
     form = fields.Str(required=True)
     type = fields.Str(default="text", validate=validate.OneOf(
-        choices=["text", "checkbox", "select", "file", "image"]))
+        choices=["text", "checkbox", "select", "file", "image", "email"]))
     is_required = fields.Boolean(default=False)
     is_included = fields.Boolean(default=False)
     is_fixed = fields.Boolean(default=False)


Test patch:
Repository: fossasia/open-event-server

Issue:
Use event identifier instead of event id for the POST request to Export API.
**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-orga-server

**Current behavior:**
Currently the event export API has endpoint ```/v1/events/{event_id}/export/json``` in which we are using the {event_id} in the request url.

Expected:
I think that should be changed to event identifier since it is the default one on the basis of which we are querying on the frontend.


Discussion:
@magdalenesuo Please take a look at this.
Also, even if I am getting a successful response, I am also getting an error in console:
```
Assertion Failed: normalizeResponse must return a valid JSON API document:
	* One or more of the following keys must be present: "data", "errors", "meta"."
```
@sumedh123 This is not JSON spec based endpoint so if it possible for you then execute this endpoint without JSON API spec check or this error will persist.

Resolving patch:
diff --git a/app/api/exports.py b/app/api/exports.py
--- a/app/api/exports.py
+++ b/app/api/exports.py
@@ -5,6 +5,8 @@
 
 from app.api.helpers.export_helpers import export_event_json, create_export_job
 from app.api.helpers.utilities import TASK_RESULTS
+from app.models.event import Event
+from app.models import db
 from flask_jwt import jwt_required, current_identity
 
 export_routes = Blueprint('exports', __name__, url_prefix='/v1')
@@ -17,9 +19,9 @@
 }
 
 
-@export_routes.route('/events/<string:event_id>/export/json', methods=['POST'])
+@export_routes.route('/events/<string:event_identifier>/export/json', methods=['POST'])
 @jwt_required()
-def export_event(event_id):
+def export_event(event_identifier):
     from helpers.tasks import export_event_task
 
     settings = EXPORT_SETTING
@@ -27,6 +29,12 @@ def export_event(event_id):
     settings['video'] = request.json.get('video', False)
     settings['document'] = request.json.get('document', False)
     settings['audio'] = request.json.get('audio', False)
+
+    if not event_identifier.isdigit():
+        event = db.session.query(Event).filter_by(identifier=event_identifier).first()
+        event_id = event.id
+    else:
+        event_id = event_identifier
     # queue task
     task = export_event_task.delay(
         current_identity.email, event_id, settings)


Test patch:
Repository: fossasia/open-event-server

Issue:
GET request to v1/orders results in Error 500
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] 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-orga-server

![image](https://user-images.githubusercontent.com/17252805/29205891-06043372-7e9d-11e7-8726-c01f66ee1748.png)



Discussion:
#4287 solves this.

Resolving patch:
diff --git a/app/api/schema/orders.py b/app/api/schema/orders.py
--- a/app/api/schema/orders.py
+++ b/app/api/schema/orders.py
@@ -57,7 +57,7 @@ def initial_values(self, data):
                              self_view='v1.order_attendee',
                              self_view_kwargs={'order_identifier': '<identifier>'},
                              related_view='v1.attendee_list',
-                             related_view_kwargs={'order_id': '<id>'},
+                             related_view_kwargs={'order_identifier': '<identifier>'},
                              schema='AttendeeSchema',
                              many=True,
                              type_='attendee')
@@ -65,7 +65,7 @@ def initial_values(self, data):
     tickets = Relationship(self_view='v1.order_ticket',
                            self_view_kwargs={'order_identifier': '<identifier>'},
                            related_view='v1.ticket_list',
-                           related_view_kwargs={'order_id': '<id>'},
+                           related_view_kwargs={'order_identifier': '<identifier>'},
                            schema='TicketSchema',
                            many=True,
                            type_="ticket")


Test patch:
Repository: fossasia/open-event-server

Issue:
Incorrect event - orders relationship
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] 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-orga-server

**Current behavior:**
<!-- Describe how the bug manifests. -->
```
"orders": {
                "links": {
                    "related": "/v1/orders",
                    "self": "/v1/events/200/relationships/orders"
                }
            }
```


Discussion:

Resolving patch:
diff --git a/app/api/orders.py b/app/api/orders.py
--- a/app/api/orders.py
+++ b/app/api/orders.py
@@ -13,6 +13,7 @@
 from app.api.helpers.mail import send_email_to_attendees
 from app.api.helpers.permission_manager import has_access
 from app.api.helpers.permissions import jwt_required
+from app.api.helpers.query import event_query
 from app.api.helpers.ticketing import TicketingManager
 from app.api.helpers.utilities import dasherize, require_relationship
 from app.api.schema.orders import OrderSchema
@@ -86,10 +87,20 @@ def before_get(self, args, kwargs):
         elif not has_access('is_coorganizer', event_id=kwargs['event_id']):
             raise ForbiddenException({'source': ''}, "Co-Organizer Access Required")
 
+    def query(self, view_kwargs):
+        query_ = self.session.query(Order)
+        query_ = event_query(self, query_, view_kwargs)
+
+        return query_
+
     decorators = (jwt_required,)
+    methods = ['GET', ]
     schema = OrderSchema
     data_layer = {'session': db.session,
-                  'model': Order}
+                  'model': Order,
+                  'methods': {
+                      'query': query
+                  }}
 
 
 class OrderDetail(ResourceDetail):
diff --git a/app/api/schema/events.py b/app/api/schema/events.py
--- a/app/api/schema/events.py
+++ b/app/api/schema/events.py
@@ -282,6 +282,7 @@ class Meta:
                           self_view='v1.event_orders',
                           self_view_kwargs={'id': '<id>'},
                           related_view='v1.orders_list',
+                          related_view_kwargs={'event_id': '<id>'},
                           schema='OrderSchema',
                           type_='order',
                           many=True)


Test patch:
Repository: fossasia/open-event-server

Issue:
Null fields in the Event GET
**I'm submitting a ...**  (check one with "x")
- [x] bug report

**Current behavior:**

Two issues with the Event GET request
1. image/icon url fields are null in the GET response although these are returned correctly in success response when an event is created. The fields are: `large-image-url`, `thumbnail-image-url`, `icon-image-url`
2.  the `original-image-url` has original value not created one in the GET response.


Discussion:

Resolving patch:
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -85,6 +85,7 @@ def after_create_object(self, event, data, view_kwargs):
         if data.get('original_image_url'):
             uploaded_images = create_save_image_sizes(data['original_image_url'], 'event', event.id)
             self.session.query(Event).filter_by(id=event.id).update(uploaded_images)
+            self.session.commit()
 
     # This permission decorator ensures, you are logged in to create an event
     # and have filter ?withRole to get events associated with logged in user


Test patch:
Repository: fossasia/open-event-server

Issue:
Create order API giving 500 response while creating orders.
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] 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-orga-server

**Current behavior:**
I created attendees successfully and I am passing the correct attendee and event id to the POST to create orders API. However, I am getting 500 response.

Request URL: ```https://open-event-api.herokuapp.com/v1/orders```
Request  body:
```
{
  "data": {
    "attributes": {
      "payment-mode": "paypal",
      "country": "India",
      "status": "pending",
      "amount": "10"
    },
    "type": "order",
    "relationships": {
      "attendees": {
        "data": [
          {
            "id": "113",
            "type": "attendee"
          }
        ]
      },
      "event": {
        "data": {
          "id": "285",
          "type": "event"
        }
      }
    }
  }
}
```
Response:
```
{
    "errors": [
        {
            "detail": "Unknown error",
            "source": {
                "pointer": ""
            },
            "status": 500,
            "title": "Unknown error"
        }
    ],
    "jsonapi": {
        "version": "1.0"
    }
}{
    "errors": [
        {
            "detail": "Unknown error",
            "source": {
                "pointer": ""
            },
            "status": 500,
            "title": "Unknown error"
        }
    ],
    "jsonapi": {
        "version": "1.0"
    }
}
```


Discussion:
@poush @enigmaeth @shubham-padia @magdalenesuo  Can you please have a look at it. 
@sumedh123 Please check again after #4364 gets merged.
@magdalenesuo I am still getting 500.

Resolving patch:
diff --git a/app/api/orders.py b/app/api/orders.py
--- a/app/api/orders.py
+++ b/app/api/orders.py
@@ -64,7 +64,7 @@ def after_create_object(self, order, data, view_kwargs):
             save_to_db(od)
         order.quantity = order.get_tickets_count()
         save_to_db(order)
-        if not has_access('is_coorganizer', **view_kwargs):
+        if not has_access('is_coorganizer', event_id=data['event']):
             TicketingManager.calculate_update_amount(order)
         send_email_to_attendees(order)
 


Test patch: