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

Issue:
Use identifier instead of id to send order receipts
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
Currently, the endpoint to send order receipts uses order ids, but purchasers do not know about order ids, instead they know of order identifiers. Thus, it's more appropriate to use order identifiers instead of ids in that endpoint.

**Describe the solution you'd like**
Use order identifiers instead of order endpoints.


Discussion:

Resolving patch:
diff --git a/app/api/attendees.py b/app/api/attendees.py
--- a/app/api/attendees.py
+++ b/app/api/attendees.py
@@ -193,12 +193,14 @@ class AttendeeRelationshipOptional(ResourceRelationship):
 @attendee_misc_routes.route('/attendees/send-receipt', methods=['POST'])
 @jwt_required
 def send_receipt():
-    order_id = request.json.get('order-id')
-    if order_id:
+    # Function to send receipts to attendees related to the provided order.
+
+    order_identifier = request.json.get('order-identifier')
+    if order_identifier:
         try:
-            order = db.session.query(Order).filter_by(id=int(order_id)).one()
+            order = db.session.query(Order).filter_by(identifier=order_identifier).one()
         except NoResultFound:
-            raise ObjectNotFound({'parameter': '{id}'}, "Order not found")
+            raise ObjectNotFound({'parameter': '{identifier}'}, "Order not found")
 
         if order.user_id != current_identity.id:
             abort(
@@ -213,5 +215,5 @@ def send_receipt():
             return jsonify(message="receipt sent to attendees")
     else:
         abort(
-            make_response(jsonify(error="Order id missing"), 422)
+            make_response(jsonify(error="Order identifier missing"), 422)
         )


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -1822,7 +1822,7 @@ def ticket_tag_ticket(transaction):
 @hooks.before("Attendees > Attendees Collection > Create Attendee")
 def attendee_post(transaction):
     """
-    POST /events/1/attendees
+    POST /attendees
     :param transaction:
     :return:
     """
@@ -1875,6 +1875,21 @@ def attendee_delete(transaction):
         db.session.commit()
 
 
+@hooks.before("Attendees > Send order receipts > Send email receipts to attendees")
+def attendee_receipts(transaction):
+    """
+    POST /attendees/send-receipt
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        order = OrderFactory()
+        order.identifier = 'xyz789'
+        order.status = 'completed'
+        db.session.add(order)
+        db.session.commit()
+
+
 # ------------------------- Tracks -------------------------
 @hooks.before("Tracks > Tracks Collection > Create Track")
 def track_post(transaction):
Repository: fossasia/open-event-server

Issue:
Make payment_mode field of orders API optional
**Describe the bug**
Since we do not know the payment_mode on order creation this field should be optional and can be updated when user updated attendees.

**Expected behavior**
This field should be optional.



Discussion:

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
@@ -50,7 +50,7 @@ def initial_values(self, data):
     created_at = fields.DateTime(dump_only=True)
     transaction_id = fields.Str(dump_only=True)
     payment_mode = fields.Str(default="free",
-                              validate=validate.OneOf(choices=["free", "stripe", "paypal"]))
+                              validate=validate.OneOf(choices=["free", "stripe", "paypal"]), allow_none=True)
     paid_via = fields.Str(dump_only=True)
     brand = fields.Str(dump_only=True)
     exp_month = fields.Str(dump_only=True)
diff --git a/app/models/order.py b/app/models/order.py
--- a/app/models/order.py
+++ b/app/models/order.py
@@ -21,7 +21,8 @@ def get_updatable_fields():
     """
     :return: The list of fields which can be modified by the order user using the pre payment form.
     """
-    return ['country', 'address', 'city', 'state', 'zipcode', 'status', 'paid_via', 'order_notes', 'deleted_at', 'user']
+    return ['country', 'address', 'city', 'state', 'zipcode', 'status', 'paid_via', 'order_notes', 'deleted_at', 'user',
+            'payment_mode']
 
 
 class OrderTicket(SoftDeletionModel):


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

Issue:
HTTP 500 error in charges endpoint
**Describe the bug**
Every time I send my stripe token using the charges end point I am getting 500 internal server error

**To Reproduce**
Use the charges endpoint and add your stripe token in the request

**Expected behavior**
A success message or the appropriate error should be displayed
**Additional context**
![screenshot from 2018-07-15 17-03-25](https://user-images.githubusercontent.com/20878145/42733583-0890ce7a-8851-11e8-824d-c86f4cd24955.png)






Discussion:
Can't reproduce locally or on the heroku deployment.
![charge_500](https://user-images.githubusercontent.com/21277837/42736273-8aea6fb8-8881-11e8-9801-9e62d3422968.png)

@nikit19 Can you please show me the payload for the POST request of the order ?

Resolving patch:
diff --git a/app/api/data_layers/ChargesLayer.py b/app/api/data_layers/ChargesLayer.py
--- a/app/api/data_layers/ChargesLayer.py
+++ b/app/api/data_layers/ChargesLayer.py
@@ -24,8 +24,8 @@ def create_object(self, data, view_kwargs):
             # when identifier is passed
             order = Order.query.filter_by(identifier=view_kwargs['order_identifier']).first()
         if not order:
-            raise ObjectNotFound({'parameter': 'id'},
-                                 "Order with id: {} not found".format(view_kwargs['id']))
+            raise ObjectNotFound({'parameter': 'order_identifier'},
+                                 "Order with identifier: {} not found".format(view_kwargs['order_identifier']))
         elif order.status == 'cancelled' or order.status == 'expired' or order.status == 'completed':
             raise ConflictException({'parameter': 'id'},
                                     "You cannot charge payments on a cancelled, expired or completed order")
diff --git a/app/api/helpers/payment.py b/app/api/helpers/payment.py
--- a/app/api/helpers/payment.py
+++ b/app/api/helpers/payment.py
@@ -47,7 +47,7 @@ def get_credentials(event=None):
             if represents_int(event):
                 authorization = StripeAuthorization.query.filter_by(event_id=event).first()
             else:
-                authorization = event.stripe
+                authorization = event.stripe_authorization
             if authorization:
                 return {
                     'SECRET_KEY': authorization.stripe_secret_key,


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

Issue:
Add boolean attributes is_sales_admin and is_marketer in users table
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
Add boolean attributes is_sales_admin and is_marketer in users table

**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->

**Describe alternatives you've considered**
<!-- A clear and concise description of any alternative solutions or features you've considered. -->

**Additional context**
<!-- Add any other context or screenshots about the feature request here. -->

**Working on it**


Discussion:

Resolving patch:
diff --git a/app/api/schema/users.py b/app/api/schema/users.py
--- a/app/api/schema/users.py
+++ b/app/api/schema/users.py
@@ -52,6 +52,10 @@ class Meta:
     password = fields.Str(required=True, load_only=True)
     is_super_admin = fields.Boolean(dump_only=True)
     is_admin = fields.Boolean(dump_only=True)
+
+    is_sales_admin = fields.Boolean(dump_only=True)
+    is_marketer = fields.Boolean(dump_only=True)
+
     is_user_organizer = fields.Boolean(dump_only=True)
     is_user_coorganizer = fields.Boolean(dump_only=True)
     is_user_track_organizer = fields.Boolean(dump_only=True)
diff --git a/app/models/user.py b/app/models/user.py
--- a/app/models/user.py
+++ b/app/models/user.py
@@ -12,7 +12,7 @@
 from app.api.helpers.db import get_count
 from app.models import db
 from app.models.base import SoftDeletionModel
-from app.models.custom_system_role import UserSystemRole
+from app.models.custom_system_role import UserSystemRole, CustomSysRole
 from app.models.helpers.versioning import clean_up_string, clean_html
 from app.models.notification import Notification
 from app.models.panel_permission import PanelPermission
@@ -28,6 +28,9 @@
 ADMIN = 'admin'
 SUPERADMIN = 'super_admin'
 
+MARKETER = 'Marketer'
+SALES_ADMIN = 'Sales Admin'
+
 SYS_ROLES_LIST = [
     ADMIN,
     SUPERADMIN,
@@ -170,6 +173,27 @@ def has_role(self, event_id):
         else:
             return True
 
+    def _is_system_role(self, role_name):
+        """
+        Checks if a user has a particular Role.
+        """
+        role = CustomSysRole.query.filter_by(name=role_name).first()
+        ucsr = UserSystemRole.query.filter_by(user=self,
+                                              role=role).first()
+        if not ucsr:
+            return False
+        else:
+            return True
+
+    @hybrid_property
+    def is_marketer(self):
+        # type: (object) -> object
+        return self._is_system_role(MARKETER)
+
+    @hybrid_property
+    def is_sales_admin(self):
+        return self._is_system_role(SALES_ADMIN)
+
     def _is_role(self, role_name, event_id=None):
         """
         Checks if a user has a particular Role at an Event.


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

Issue:
Correct exception for quantity < max order in tickets schema
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
Validation check message for quantity to be more than max-order needs to be corrected.

**To Reproduce**
A validation check for quantity and max-order is:
```
        if 'quantity' in data and 'max_order' in data:
            if data['quantity'] < data['max_order']:
                raise UnprocessableEntity({'pointer': '/data/attributes/quantity'},
                                          "quantity should be lesser than max-order")
```

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
The message should be: "quantity should not be lesser than max-order".


Discussion:

Resolving patch:
diff --git a/app/api/schema/tickets.py b/app/api/schema/tickets.py
--- a/app/api/schema/tickets.py
+++ b/app/api/schema/tickets.py
@@ -39,17 +39,17 @@ def validate_quantity(self, data):
         if 'max_order' in data and 'min_order' in data:
             if data['max_order'] < data['min_order']:
                 raise UnprocessableEntity({'pointer': '/data/attributes/max-order'},
-                                          "max-order should be greater than min-order")
+                                          "max-order should be greater than or equal to min-order")
 
         if 'quantity' in data and 'min_order' in data:
             if data['quantity'] < data['min_order']:
                 raise UnprocessableEntity({'pointer': '/data/attributes/quantity'},
-                                          "quantity should be greater than min-order")
+                                          "quantity should be greater than or equal to min-order")
 
         if 'quantity' in data and 'max_order' in data:
             if data['quantity'] < data['max_order']:
                 raise UnprocessableEntity({'pointer': '/data/attributes/quantity'},
-                                          "quantity should be lesser than max-order")
+                                          "quantity should be greater than or equal to max-order")
 
     @validates_schema(pass_original=True)
     def validate_discount_code(self, data, original_data):


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

Issue:
Add stripe test key for testing purposes on the heroku deployment
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
Stripe test key needs to be added for testing purposes on the heroku deployment.

**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->
Update the `populate_db.py` file to add it in the settings. 



Discussion:

Resolving patch:
diff --git a/populate_db.py b/populate_db.py
--- a/populate_db.py
+++ b/populate_db.py
@@ -1,6 +1,7 @@
 from app import current_app
 from app.models import db
 from app.api.helpers.db import get_or_create  # , save_to_db
+from envparse import env
 
 # Admin message settings
 from app.api.helpers.system_mails import MAILS
@@ -67,6 +68,21 @@ def create_services():
 def create_settings():
     get_or_create(Setting, app_name='Open Event')
 
+    if current_app.config['DEVELOPMENT']:
+        # get the stripe keys from the env file and save it in the settings.
+        env.read_envfile()
+        stripe_secret_key = env('STRIPE_SECRET_KEY', default=None)
+        stripe_publishable_key = env('STRIPE_PUBLISHABLE_KEY', default=None)
+        stripe_client_id = env('STRIPE_CLIENT_ID', default=None)
+
+        if stripe_client_id and stripe_secret_key and stripe_publishable_key:
+            setting, _ = get_or_create(Setting, app_name='Open Event')
+            setting.stripe_client_id = stripe_client_id
+            setting.stripe_publishable_key = stripe_publishable_key
+            setting.stripe_secret_key = stripe_secret_key
+            db.session.add(setting)
+            db.session.commit()
+
 
 def create_event_image_sizes():
     get_or_create(


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

Issue:
Add custom form for attendees
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->

Add custom form for attendees

**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->

**Describe alternatives you've considered**
<!-- A clear and concise description of any alternative solutions or features you've considered. -->

**Additional context**
<!-- Add any other context or screenshots about the feature request here. -->

**Working on it**


Discussion:

Resolving patch:
diff --git a/app/models/custom_form.py b/app/models/custom_form.py
--- a/app/models/custom_form.py
+++ b/app/models/custom_form.py
@@ -35,8 +35,34 @@
     "linkedin": {"include": 0, "require": 0}
 }
 
+ATTENDEE_FORM = {
+    "firstname": {"include": 1, "require": 1},
+    "lastname": {"include": 1, "require": 1},
+    "email": {"include": 1, "require": 0},
+    "address": {"include": 1, "require": 0},
+    "city": {"include": 1, "require": 0},
+    "state": {"include": 1, "require": 0},
+    "country": {"include": 1, "require": 0},
+    "job_title": {"include": 1, "require": 0},
+    "phone": {"include": 1, "require": 0},
+    "tax_business_info": {"include": 0, "require": 0},
+    "billing_address": {"include": 0, "require": 0},
+    "home_address": {"include": 0, "require": 0},
+    "shipping_address": {"include": 0, "require": 0},
+    "company": {"include": 0, "require": 0},
+    "work_address": {"include": 0, "require": 0},
+    "work_phone": {"include": 0, "require": 0},
+    "website": {"include": 1, "require": 0},
+    "blog": {"include": 0, "require": 0},
+    "twitter": {"include": 1, "require": 0},
+    "facebook": {"include": 0, "require": 0},
+    "github": {"include": 1, "require": 0},
+    "gender": {"include": 0, "require": 0},
+}
+
 session_form_str = json.dumps(SESSION_FORM, separators=(',', ':'))
 speaker_form_str = json.dumps(SPEAKER_FORM, separators=(',', ':'))
+attendee_form_str = json.dumps(ATTENDEE_FORM, separators=(',', ':'))
 
 
 class CustomForms(SoftDeletionModel):


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

Issue:
Add client ids and secret keys of third party from env for Heroku
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->

Add client ids and secret keys of third party from env for Heroku

**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->

**Describe alternatives you've considered**
<!-- A clear and concise description of any alternative solutions or features you've considered. -->

**Additional context**
<!-- Add any other context or screenshots about the feature request here. -->

**Working on it**


Discussion:

Resolving patch:
diff --git a/populate_db.py b/populate_db.py
--- a/populate_db.py
+++ b/populate_db.py
@@ -74,14 +74,29 @@ def create_settings():
         stripe_secret_key = env('STRIPE_SECRET_KEY', default=None)
         stripe_publishable_key = env('STRIPE_PUBLISHABLE_KEY', default=None)
         stripe_client_id = env('STRIPE_CLIENT_ID', default=None)
-
-        if stripe_client_id and stripe_secret_key and stripe_publishable_key:
-            setting, _ = get_or_create(Setting, app_name='Open Event')
-            setting.stripe_client_id = stripe_client_id
-            setting.stripe_publishable_key = stripe_publishable_key
-            setting.stripe_secret_key = stripe_secret_key
-            db.session.add(setting)
-            db.session.commit()
+        fb_client_id = env('FACEBOOK_CLIENT_ID', default=None)
+        fb_client_secret = env('FACEBOOK_CLIENT_SECRET', default=None)
+        google_client_id = env('GOOGLE_CLIENT_ID', default=None)
+        google_client_secret = env('GOOGLE_CLIENT_SECRET', default=None)
+        tw_consumer_key = env('TWITTER_CONSUMER_KEY', default=None)
+        tw_consumer_secret = env('TWITTER_CONSUMER_SECRET', default=None)
+        in_client_id = env('INSTAGRAM_CLIENT_ID', default=None)
+        in_client_secret = env('INSTAGRAM_CLIENT_SECRET', default=None)
+
+        setting, _ = get_or_create(Setting, app_name='Open Event')
+        setting.stripe_client_id = stripe_client_id
+        setting.stripe_publishable_key = stripe_publishable_key
+        setting.stripe_secret_key = stripe_secret_key
+        setting.fb_client_id = fb_client_id
+        setting.fb_client_secret = fb_client_secret
+        setting.google_client_id = google_client_id
+        setting.google_client_secret = google_client_secret
+        setting.tw_consumer_key = tw_consumer_key
+        setting.tw_consumer_secret = tw_consumer_secret
+        setting.in_client_id = in_client_id
+        setting.in_client_secret = in_client_secret
+        db.session.add(setting)
+        db.session.commit()
 
 
 def create_event_image_sizes():


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

Issue:
For the edit action button in admin/users the super admin should be allowed to make the users as an admin.
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
The patch for the users is working but is_admin is a readonly property even for the super user. Used the patch request for users and changed the value for is_admin from true to false. But there is no change after the request to the value of is_admin. 

**To Reproduce**
Steps to reproduce the behavior:
1. Go to v1/users/user_id
2. Send a patch request
3. Change the value of is_admin for some user from false to true.
4. See error

![image](https://user-images.githubusercontent.com/22127980/42907807-8f6542fc-8afc-11e8-84cd-0fe415042fb2.png)

After the request
![image](https://user-images.githubusercontent.com/22127980/42907825-9ecafdd6-8afc-11e8-8372-5cc65888b08b.png)






Discussion:

Resolving patch:
diff --git a/app/api/users.py b/app/api/users.py
--- a/app/api/users.py
+++ b/app/api/users.py
@@ -183,6 +183,9 @@ def before_update_object(self, user, data, view_kwargs):
         if data.get('email') and data['email'] != user.email:
             view_kwargs['email_changed'] = user.email
 
+        if data.get('is_admin') != user.is_admin:
+            user.is_admin = not user.is_admin
+
     def after_update_object(self, user, data, view_kwargs):
         """
         method to mail user about email change


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

Issue:
Deleted_at for events is a readonly column and can not be changed
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
The admin should be able to restore the deleted events. So changing the value of deleted events from a date to null should be possible through a patch request (only for an admin).

**To Reproduce**
Steps to reproduce the behavior:
1. Go to v1/events/event_id?get_trashed=true (id of a deleted event)
2. Send a patch request changing the deleted_at column to null.
3. See error

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
The patch request should be successful
Current Behavior
![image](https://user-images.githubusercontent.com/22127980/42912174-a4d29ed2-8b0b-11e8-818e-020c0b988d61.png)

After patch
![image](https://user-images.githubusercontent.com/22127980/42912208-cc4d23e2-8b0b-11e8-85d3-30c5bf96de24.png)






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
@@ -444,6 +444,9 @@ def before_update_object(self, event, data, view_kwargs):
             data['thumbnail_image_url'] = uploaded_images['thumbnail_image_url']
             data['icon_image_url'] = uploaded_images['icon_image_url']
 
+        if has_access('is_admin') and data.get('deleted_at') != event.deleted_at:
+            event.deleted_at = data.get('deleted_at')
+
     def after_update_object(self, event, data, view_kwargs):
         if event.state == 'published' and event.schedule_published_on:
             start_export_tasks(event)


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

Issue:
Shift cookie_policy to public schema
**Describe the bug**
Cookie policy should be in the public schema as it has to be shown to all the visitors.



Discussion:

Resolving patch:
diff --git a/app/api/schema/settings.py b/app/api/schema/settings.py
--- a/app/api/schema/settings.py
+++ b/app/api/schema/settings.py
@@ -43,6 +43,12 @@ class Meta:
     # Url of Frontend
     frontend_url = fields.Url(allow_none=True)
 
+    #
+    # Cookie Policy
+    #
+    cookie_policy = fields.Str(allow_none=True)
+    cookie_policy_link = fields.Str(allow_none=True)
+
 
 class SettingSchemaNonAdmin(SettingSchemaPublic):
     """
@@ -161,9 +167,3 @@ class Meta:
     smtp_password = fields.Str(allow_none=True)
     smtp_port = fields.Integer(allow_none=True)
     smtp_encryption = fields.Str(allow_none=True)  # Can be tls, ssl, none
-
-    #
-    # Cookie Policy
-    #
-    cookie_policy = fields.Str(allow_none=True)
-    cookie_policy_link = fields.Str(allow_none=True)


Test patch: