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

Issue:
Add server code for is_featured events
## Parent Issue:

fossasia/open-event-frontend#1925


Discussion:

Resolving patch:
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
@@ -97,6 +97,7 @@ def validate_timezone(self, data, original_data):
     code_of_conduct = fields.Str(allow_none=True)
     schedule_published_on = fields.DateTime(allow_none=True)
     is_ticketing_enabled = fields.Bool(default=False)
+    is_featured = fields.Bool(default=False)
     payment_country = fields.Str(allow_none=True)
     payment_currency = fields.Str(allow_none=True)
     tickets_available = fields.Float(dump_only=True)
diff --git a/app/models/event.py b/app/models/event.py
--- a/app/models/event.py
+++ b/app/models/event.py
@@ -53,6 +53,7 @@ class Event(SoftDeletionModel):
     longitude = db.Column(db.Float)
     location_name = db.Column(db.String)
     searchable_location_name = db.Column(db.String)
+    is_featured = db.Column(db.Boolean, default=False, nullable=False)
     description = db.Column(db.Text)
     original_image_url = db.Column(db.String)
     thumbnail_image_url = db.Column(db.String)
@@ -207,6 +208,7 @@ def __init__(self,
                  can_pay_by_cheque=None,
                  identifier=None,
                  can_pay_by_bank=None,
+                 is_featured=False,
                  can_pay_onsite=None,
                  cheque_details=None,
                  bank_details=None,
@@ -267,6 +269,7 @@ def __init__(self,
         self.can_pay_by_bank = can_pay_by_bank
         self.can_pay_onsite = can_pay_onsite
         self.is_donation_enabled = is_donation_enabled
+        self.is_featured = is_featured
         self.identifier = get_new_event_identifier()
         self.cheque_details = cheque_details
         self.bank_details = bank_details
diff --git a/migrations/versions/e59e7a75f679_.py b/migrations/versions/e59e7a75f679_.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/e59e7a75f679_.py
@@ -0,0 +1,30 @@
+"""empty message
+
+Revision ID: e59e7a75f679
+Revises: 5551af72812f
+Create Date: 2019-04-19 13:27:05.212985
+
+"""
+
+from alembic import op
+import sqlalchemy as sa
+import sqlalchemy_utils
+
+
+# revision identifiers, used by Alembic.
+revision = 'e59e7a75f679'
+down_revision = '5551af72812f'
+
+
+def upgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.add_column('events', sa.Column('is_featured', sa.Boolean(), server_default='False', nullable=False))
+    op.add_column('events_version', sa.Column('is_featured', sa.Boolean(), server_default='False', autoincrement=False, nullable=True))
+    # ### end Alembic commands ###
+
+
+def downgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.drop_column('events_version', 'is_featured')
+    op.drop_column('events', 'is_featured')
+    # ### end Alembic commands ###


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

Issue:
Notify user when he enters same old password as new password
**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 [...] -->
When a user changes his old password, Notify the user that he has entered the same old password as new password

**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->
Notify user he has entered the same old password as new password

**Additional context**
<!-- Add any other context or screenshots about the feature request here. -->
![image](https://user-images.githubusercontent.com/44091822/56079180-7c54dc00-5e0e-11e9-9a75-613a46b3ccc5.png)



Discussion:
@kushthedude are you working on it?
@shreyanshdwivedi Just make the API reject the same old password , else will be handled in https://github.com/fossasia/open-event-frontend/issues/2636
@kushthedude can I proceed?
Sure

On Fri, 19 Apr 2019 at 5:46 PM, Shreyansh Dwivedi <notifications@github.com>
wrote:

> @kushthedude <https://github.com/kushthedude> can I proceed?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/fossasia/open-event-server/issues/5794#issuecomment-484876316>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AKQMTLXZ53TLU2LPWUNXNYDPRGZZ7ANCNFSM4HFZTOWQ>
> .
>


Resolving patch:
diff --git a/app/api/auth.py b/app/api/auth.py
--- a/app/api/auth.py
+++ b/app/api/auth.py
@@ -251,6 +251,9 @@ def change_password():
         return NotFoundError({'source': ''}, 'User Not Found').respond()
     else:
         if user.is_correct_password(old_password):
+            if user.is_correct_password(new_password):
+                return BadRequestError({'source': ''},
+                                       'Old and New passwords must be different').respond()
             if len(new_password) < 8:
                 return BadRequestError({'source': ''},
                                        'Password should have minimum 8 characters').respond()


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

Issue:
Implement checks on deleting an event
**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 [...] -->
Deleting of an event should be prevent by an API if any order has been placed for the event, in order to avoid fraud. Please refer to https://github.com/fossasia/open-event-server/issues/5805#issuecomment-483576022

**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->
Implement checks on deleting event. An event shouldn't be deleted if it has any order associated with it.

**Additional context**
<!-- Add any other context or screenshots about the feature request here. -->
Working on it.



Discussion:
@iamareebjamal @mrsaicharan1 @uds5501 I wanted to discuss few things before proceeding. I'm planning to do this - If any order is associated with an event, APIs must restrict its deletion. Once the event passes, we must wait for a span of few days before enabling the deletion of the event because it may happen that the event organiser don't show up at the venue or no event was there at the venue. So a minimum span of few days must be there before allowing the event organiser to delete the event. Your views?
The part about the API blocking the deletion of an event with an order associated is fine I guess. But I'm a little skeptical about the deletion after the event has passed. I don't think you should allow deletion of past events. The organizer might never show up/conduct the event. 
If you really want to implement it, then there should be a refund-check which should check if all the orders have been canceled and a refund has been processed. Post that, the organizer should be allowed to delete the event. 
Right, for now, just implement check for Order thing, we'll tackle other things later
Disable delete for any event with any order for now, we'll refine these checks later.

Then allow deletes only when all the events from account have been deleted

Resolving patch:
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -468,9 +468,11 @@ def before_update_object(self, event, data, view_kwargs):
         :param view_kwargs:
         :return:
         """
-
         if has_access('is_admin') and data.get('deleted_at') != event.deleted_at:
-            event.deleted_at = data.get('deleted_at')
+            if len(event.orders) != 0:
+                raise ForbiddenException({'source': ''}, "Event associated with orders cannot be deleted")
+            else:
+                event.deleted_at = data.get('deleted_at')
 
         if 'is_event_online' not in data and event.is_event_online \
                 or 'is_event_online' in data and not data['is_event_online']:


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

Issue:
Make namespace uniform for endpoints
**Describe the bug**
Currently, the ticket endpoint has a url-prefix of '/' which is not uniform with all other endpoints which have the namespace of '/v1'.

**Expected behavior**
Tickets route needs to be mapped to `/v1/tickets/order-identifier`



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
@@ -28,7 +28,7 @@
 from app.api.helpers.storage import UPLOAD_PATHS
 
 
-ticket_blueprint = Blueprint('ticket_blueprint', __name__, url_prefix='/')
+ticket_blueprint = Blueprint('ticket_blueprint', __name__, url_prefix='/v1')
 auth_routes = Blueprint('auth', __name__, url_prefix='/v1/auth')
 
 


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

Issue:
Change the session status from pending to rejected if the event has passed.
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
Currently if the user's session is in pending state till the event has happened, it still shows pending after the event has passed. A better label will be rejected since the user's session wasn't accepted till the event.

**To Reproduce**
Steps to reproduce the behaviour:
1. Go to 'my sessions after event has passed'
2. Click on 'an older session'
3. See error

**Expected behaviour**
<!-- A clear and concise description of what you expected to happen. -->
Pending label should be Rejected.

**Additional context**
<!-- Add any other context about the problem here. -->
I am working on this issue.


Discussion:
@Anupam-dagar Can I take over? I have half of the work down, if you allow I shall push it by tomorrow.
@uds5501 Sure.

Resolving patch:
diff --git a/app/__init__.py b/app/__init__.py
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -29,7 +29,7 @@
 from app.views import BlueprintsManager
 from app.api.helpers.auth import AuthManager
 from app.api.helpers.scheduled_jobs import send_after_event_mail, send_event_fee_notification, \
-    send_event_fee_notification_followup
+    send_event_fee_notification_followup, change_session_state_on_event_completion
 from app.models.event import Event
 from app.models.role_invite import RoleInvite
 from app.views.healthcheck import health_check_celery, health_check_db, health_check_migrations, check_migrations
@@ -242,6 +242,7 @@ def update_sent_state(sender=None, body=None, **kwargs):
 scheduler.add_job(send_after_event_mail, 'cron', hour=5, minute=30)
 scheduler.add_job(send_event_fee_notification, 'cron', day=1)
 scheduler.add_job(send_event_fee_notification_followup, 'cron', day=15)
+scheduler.add_job(change_session_state_on_event_completion, 'cron', hour=5, minute=30)
 scheduler.start()
 
 
diff --git a/app/api/helpers/scheduled_jobs.py b/app/api/helpers/scheduled_jobs.py
--- a/app/api/helpers/scheduled_jobs.py
+++ b/app/api/helpers/scheduled_jobs.py
@@ -12,6 +12,7 @@
 from app.api.helpers.utilities import monthdelta
 from app.models import db
 from app.models.event import Event
+from app.models.session import Session
 from app.models.event_invoice import EventInvoice
 from app.models.order import Order
 from app.models.ticket import Ticket
@@ -46,6 +47,16 @@ def send_after_event_mail():
                     send_notif_after_event(organizer.user.email, event.name)
 
 
+def change_session_state_on_event_completion():
+    from app import current_app as app
+    with app.app_context():
+        sessions_to_be_changed = Session.query.join(Event).filter(Session.state == 'pending')\
+                                 .filter(Event.ends_at < datetime.datetime.now())
+        for session in sessions_to_be_changed:
+            session.state = 'rejected'
+            save_to_db(session, 'Changed {} session state to rejected'.format(session.title))
+
+
 def send_event_fee_notification():
     from app import current_app as app
     with app.app_context():


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

Issue:
Creating a session without speaker is throwing 500
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
Creating a session without a speaker involved should be possible but currently, it's throwing a 500 server error

**To Reproduce**
Steps to reproduce the behavior:
1. Go to event/sessions-create or cfs/new-session
2. Create a session
3. Select no speaker
4. See error

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
It should work without any error.

**Additional details (please complete the following information):**
 - OS: [e.g. MacOS, Ubuntu, CentOS] Ubuntu 16.04
 - Python Version [e.g. `3.5`, `3.6`] 3.6

**Additional context**
<!-- Add any other context about the problem here. -->
Working on it


Discussion:

Resolving patch:
diff --git a/app/api/sessions.py b/app/api/sessions.py
--- a/app/api/sessions.py
+++ b/app/api/sessions.py
@@ -175,7 +175,7 @@ def after_update_object(self, session, data, view_kwargs):
                                                                 session_id=session.id,
                                                                 event_id=session.event.id,
                                                                 speaker_id=speaker.id)
-                save_to_db(session_speaker_link, "Session Speaker Link Saved")
+                    save_to_db(session_speaker_link, "Session Speaker Link Saved")
 
     decorators = (api.has_permission('is_speaker_for_session', methods="PATCH,DELETE"),)
     schema = SessionSchema


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

Issue:
Paypal is not using production settings
Paypal live mode should be used, when the app is in production which was the intended behavior.


Discussion:

Resolving patch:
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
@@ -136,20 +136,24 @@ def configure_paypal():
         Configure the paypal sdk
         :return: Credentials
         """
-        # Use Sandbox by default.
         settings = get_settings()
-        paypal_mode = 'sandbox'
-        paypal_client = settings.get('paypal_sandbox_client', None)
-        paypal_secret = settings.get('paypal_sandbox_secret', None)
+        # Use Sandbox by default.
+        paypal_mode = settings.get('paypal_mode',
+                                   'live' if (settings['app_environment'] == Environment.PRODUCTION) else 'sandbox')
+        paypal_key = None
+        if paypal_mode == 'sandbox':
+            paypal_key = 'paypal_sandbox'
+        elif paypal_mode == 'live':
+            paypal_key = 'paypal'
+
+        if not paypal_key:
+            raise ConflictException({'pointer': ''}, "Paypal Mode must be 'live' or 'sandbox'")
 
-        # Switch to production if paypal_mode is production.
-        if settings['paypal_mode'] == Environment.PRODUCTION:
-            paypal_mode = 'live'
-            paypal_client = settings.get('paypal_client', None)
-            paypal_secret = settings.get('paypal_secret', None)
+        paypal_client = settings.get(f'{paypal_key}_client', None)
+        paypal_secret = settings.get(f'{paypal_key}_secret', None)
 
         if not paypal_client or not paypal_secret:
-            raise ConflictException({'pointer': ''}, "Payments through Paypal hasn't been configured on the platform")
+            raise ConflictException({'pointer': ''}, "Payments through Paypal have not been configured on the platform")
 
         paypalrestsdk.configure({
             "mode": paypal_mode,


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

Issue:
Space issue in notification generated after `Acceptance of proposal`
**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 [...] -->
No space between `Rejected`

**Screenshot**

<img width="1253" alt="Screenshot 2019-04-26 at 6 10 22 AM" src="https://user-images.githubusercontent.com/44091822/56776468-345c8e80-67ea-11e9-8211-e93d53734c67.png">




Discussion:

Resolving patch:
diff --git a/app/api/helpers/system_notifications.py b/app/api/helpers/system_notifications.py
--- a/app/api/helpers/system_notifications.py
+++ b/app/api/helpers/system_notifications.py
@@ -413,7 +413,7 @@ def get_invite_papers_notification_actions(cfs_link, submit_link):
     SESSION_ACCEPT_REJECT: {
         'title': u'Session {session_name} has been {acceptance}',
         'message': u"The session <strong>{session_name}</strong> has been" +
-                   u"<strong>{acceptance}</strong> by the Organizer.",
+                   u" <strong>{acceptance}</strong> by the Organizer.",
         'recipient': 'Speaker',
     },
     INVITE_PAPERS: {


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

Issue:
Paypal token request syntax isn't backwards compatible
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
 Currently, the paypal token access requires the python version to be `>=3.6.2`, This needs to be fixed

**Stacktrace**
<!-- If applicable, add stacktrace to help explain your problem. -->
```
  RequestsDependencyWarning)
Traceback (most recent call last):
  File "/home/uddeshya/Desktop/mySetup/open-event-server/manage.py", line 3, in <module>
    from app.api.helpers.db import save_to_db
  File "/home/uddeshya/Desktop/mySetup/open-event-server/app/__init__.py", line 26, in <module>
    from app.api.helpers.jwt import jwt_authenticate, jwt_identity
  File "/home/uddeshya/Desktop/mySetup/open-event-server/app/api/__init__.py", line 3, in <module>
    from app.api.stripe_authorization import StripeAuthorizationDetail, StripeAuthorizationRelationship, \
  File "/home/uddeshya/Desktop/mySetup/open-event-server/app/api/stripe_authorization.py", line 7, in <module>
    from app.api.helpers.payment import StripePaymentsManager
  File "/home/uddeshya/Desktop/mySetup/open-event-server/app/api/helpers/payment.py", line 152
    paypal_client = settings.get(f'{paypal_key}_client', None)
                                                      ^
SyntaxError: invalid syntax

```
**Additional details (please complete the following information):**
 - OS: [e.g. MacOS, Ubuntu, CentOS] Ubuntu 16.04
 - Python Version [e.g. `3.5`, `3.6`] 3.5



Discussion:

Resolving patch:
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
@@ -149,8 +149,8 @@ def configure_paypal():
         if not paypal_key:
             raise ConflictException({'pointer': ''}, "Paypal Mode must be 'live' or 'sandbox'")
 
-        paypal_client = settings.get(f'{paypal_key}_client', None)
-        paypal_secret = settings.get(f'{paypal_key}_secret', None)
+        paypal_client = settings.get('{}_client'.format(paypal_key), None)
+        paypal_secret = settings.get('{}_secret'.format(paypal_key), None)
 
         if not paypal_client or not paypal_secret:
             raise ConflictException({'pointer': ''}, "Payments through Paypal have not been configured on the platform")


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

Issue:
Add canPayByOmise fields to event schema
Add fields for the Omise payment gateway in event model and schema

Parent issue #5823 


Discussion:

Resolving patch:
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
@@ -111,6 +111,7 @@ def validate_timezone(self, data, original_data):
     can_pay_by_cheque = fields.Bool(default=False)
     can_pay_by_bank = fields.Bool(default=False)
     can_pay_onsite = fields.Bool(default=False)
+    can_pay_by_omise = fields.Bool(default=False)
     cheque_details = fields.Str(allow_none=True)
     bank_details = fields.Str(allow_none=True)
     onsite_details = fields.Str(allow_none=True)
diff --git a/app/models/event.py b/app/models/event.py
--- a/app/models/event.py
+++ b/app/models/event.py
@@ -100,6 +100,7 @@ class Event(SoftDeletionModel):
     can_pay_by_cheque = db.Column(db.Boolean, default=False)
     can_pay_by_bank = db.Column(db.Boolean, default=False)
     can_pay_onsite = db.Column(db.Boolean, default=False)
+    can_pay_by_omise = db.Column(db.Boolean, default=False)
     cheque_details = db.Column(db.String)
     bank_details = db.Column(db.String)
     onsite_details = db.Column(db.String)
@@ -206,6 +207,7 @@ def __init__(self,
                  can_pay_by_paypal=None,
                  can_pay_by_stripe=None,
                  can_pay_by_cheque=None,
+                 can_pay_by_omise=None,
                  identifier=None,
                  can_pay_by_bank=None,
                  is_featured=False,
@@ -268,6 +270,7 @@ def __init__(self,
         self.can_pay_by_cheque = can_pay_by_cheque
         self.can_pay_by_bank = can_pay_by_bank
         self.can_pay_onsite = can_pay_onsite
+        self.can_pay_by_omise = can_pay_by_omise
         self.is_donation_enabled = is_donation_enabled
         self.is_featured = is_featured
         self.identifier = get_new_event_identifier()
diff --git a/migrations/versions/6f7b6fad3f53_add_can_pay_by_omise_in_event_model.py b/migrations/versions/6f7b6fad3f53_add_can_pay_by_omise_in_event_model.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/6f7b6fad3f53_add_can_pay_by_omise_in_event_model.py
@@ -0,0 +1,30 @@
+"""Add can_pay_by_omise in event model
+
+Revision ID: 6f7b6fad3f53
+Revises: a0532f339abb
+Create Date: 2019-05-07 16:14:57.129985
+
+"""
+
+from alembic import op
+import sqlalchemy as sa
+import sqlalchemy_utils
+
+
+# revision identifiers, used by Alembic.
+revision = '6f7b6fad3f53'
+down_revision = 'a0532f339abb'
+
+
+def upgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.add_column('events', sa.Column('can_pay_by_omise', sa.Boolean(), nullable=True))
+    op.add_column('events_version', sa.Column('can_pay_by_omise', sa.Boolean(), autoincrement=False, nullable=True))
+    # ### end Alembic commands ###
+
+
+def downgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.drop_column('events_version', 'can_pay_by_omise')
+    op.drop_column('events', 'can_pay_by_omise')
+    # ### end Alembic commands ###


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

Issue:
Email not send for Ticket Orders
Users don't receive an email with their order and PDF.

Expected: After a user orders a ticket, they should receive a PDF. If the attendee is a different person with a different email, the attendee should also receive an email.


Discussion:
This is mostly a server side issue. Will solve this today.
@mrsaicharan1 I have been working on it for a while now, do you mind if I take over?
Sure, no problem. Meanwhile, Can I take the server part of this ? https://github.com/fossasia/open-event-frontend/issues/2920
@mrsaicharan1 No problem, go ahead!
@iamareebjamal Please send this issue to server side

Resolving patch:
diff --git a/app/api/orders.py b/app/api/orders.py
--- a/app/api/orders.py
+++ b/app/api/orders.py
@@ -307,6 +307,15 @@ def after_update_object(self, order, data, view_kwargs):
             # delete the attendees so that the tickets are unlocked.
             delete_related_attendees_for_order(order)
 
+        elif order.status == 'completed':
+            send_email_to_attendees(order, current_user.id)
+            send_notif_to_attendees(order, current_user.id)
+
+            order_url = make_frontend_url(path='/orders/{identifier}'.format(identifier=order.identifier))
+            for organizer in order.event.organizers:
+                send_notif_ticket_purchase_organizer(organizer, order.invoice_number, order_url, order.event.name,
+                                                     order.identifier)
+
     def before_delete_object(self, order, view_kwargs):
         """
         method to check for proper permissions for deleting


Test patch: