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

Issue:
copied events have no organizer
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
Currently, copied events have no associated event roles and are being showed with no organizers

**To Reproduce**
Steps to reproduce the behavior:
1. Go to any event
2. Click on copy
3. Go to Admin/Events 
4. See error

![screenshot from 2019-02-20 15-53-44](https://user-images.githubusercontent.com/21087061/53084979-eb593700-3527-11e9-86a5-1a5c868d3db5.png)

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
The copied event should also be organized by previous organiser himself

**Additional details (please complete the following information):**
 - OS: [e.g. MacOS, Ubuntu, CentOS] Ubuntu
 - Python Version [e.g. `3.5`, `3.6`] 3.5

**Additional context**
<!-- Add any other context about the problem here. -->
Working on it


Discussion:

Resolving patch:
diff --git a/app/api/event_copy.py b/app/api/event_copy.py
--- a/app/api/event_copy.py
+++ b/app/api/event_copy.py
@@ -14,6 +14,7 @@
 from app.models.sponsor import Sponsor
 from app.models.ticket import Ticket
 from app.models.track import Track
+from app.models.users_events_role import UsersEventsRoles
 
 event_copy = Blueprint('event_copy', __name__, url_prefix='/v1/events')
 
@@ -39,6 +40,7 @@ def create_event_copy(identifier):
     custom_forms = CustomForms.query.filter_by(event_id=event.id).all()
     discount_codes = DiscountCode.query.filter_by(event_id=event.id).all()
     speaker_calls = SpeakersCall.query.filter_by(event_id=event.id).all()
+    user_event_roles = UsersEventsRoles.query.filter_by(event_id=event.id).all()
 
     db.session.expunge(event)  # expunge the object from session
     make_transient(event)
@@ -123,6 +125,14 @@ def create_event_copy(identifier):
         db.session.add(form)
         db.session.commit()
 
+    for user_role in user_event_roles:
+        db.session.expunge(user_role)
+        make_transient(user_role)
+        user_role.event_id = event.id
+        delattr(user_role, 'id')
+        db.session.add(user_role)
+        db.session.commit()
+
     return jsonify({
         'id': event.id,
         'identifier': event.identifier,


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

Issue:
admin dashboard : number of organisers > number of actual users
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
Currently, the admin dashboard is effectively reporting the number of `published + draft` events in the `No. of organizers` tab which should not be the case.
In my example, the number of total organisers is 3 while the number reported here is 7

**To Reproduce**
Steps to reproduce the behavior:
1. Go to Admin Dashboard
2. See error

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
It should be reporting the actual number of organizers

![image](https://user-images.githubusercontent.com/21087061/53127560-c1842c80-3588-11e9-9504-2e7f80bed84c.png)
![image](https://user-images.githubusercontent.com/21087061/53127581-cea11b80-3588-11e9-8ae5-ee8ebd06b8ed.png)

**Additional details (please complete the following information):**
 - OS: [e.g. MacOS, Ubuntu, CentOS] Ubuntu
 - Python Version [e.g. `3.5`, `3.6`] 3.5

**Additional context**
<!-- Add any other context about the problem here. -->
Working on the issue


Discussion:

Resolving patch:
diff --git a/app/api/admin_statistics_api/users.py b/app/api/admin_statistics_api/users.py
--- a/app/api/admin_statistics_api/users.py
+++ b/app/api/admin_statistics_api/users.py
@@ -12,7 +12,6 @@
 from app.models.role import Role
 from app.api.helpers.db import get_count
 
-
 class AdminStatisticsUserSchema(Schema):
     """
     Api schema
@@ -49,21 +48,21 @@ def unverified_count(self, obj):
 
     def get_all_user_roles(self, role_name):
         role = Role.query.filter_by(name=role_name).first()
-        uers = UsersEventsRoles.query.join(UsersEventsRoles.event).join(UsersEventsRoles.role).filter(
-            Event.deleted_at.is_(None), UsersEventsRoles.role == role)
-        return uers
+        newquery = User.query.join(UsersEventsRoles.user).join(UsersEventsRoles.role).filter(
+            UsersEventsRoles.role == role).distinct()
+        return newquery
 
     def organizer_count(self, obj):
-        return get_count(self.get_all_user_roles('organizer'))
+        return self.get_all_user_roles('organizer').count()
 
     def coorganizer_count(self, obj):
-        return get_count(self.get_all_user_roles('coorganizer'))
+        return self.get_all_user_roles('coorganizer').count()
 
     def track_organizer_count(self, obj):
-        return get_count(self.get_all_user_roles('track_organizer'))
+        return self.get_all_user_roles('track_organizer').count()
 
     def attendee_count(self, obj):
-        return get_count(self.get_all_user_roles('attendee'))
+        return self.get_all_user_roles('attendee').count()
 
 
 class AdminStatisticsUserDetail(ResourceDetail):


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

Issue:
Donations PATCH error
**Describe the bug**
Donations aren't getting enabled on the admin panel. Throws a 409 conflict error.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to 'Admin Panel'
2. Click on 'Modules Section'
3. See unexpected error



**Additional context**
Working on this.
![screenshot from 2019-02-18 15-12-59](https://user-images.githubusercontent.com/25197147/52941946-e9f50680-338f-11e9-9882-45bf38d401d5.png)



Discussion:

Resolving patch:
diff --git a/app/api/modules.py b/app/api/modules.py
--- a/app/api/modules.py
+++ b/app/api/modules.py
@@ -6,7 +6,6 @@
 from app.models.module import Module
 from app.api.helpers.exceptions import ConflictException
 
-
 class ModuleDetail(ResourceDetail):
     """
     module detail by id
@@ -29,9 +28,6 @@ def before_patch(self, args, kwargs, data=None):
         :param data:
         :return:
         """
-        if data.get('donation_include'):
-            raise ConflictException({'pointer': '/data/attributes/donation-include'},
-                                    "No donation support in the system")
 
     decorators = (api.has_permission('is_admin', methods='PATCH', id='1'),)
     methods = ['GET', 'PATCH']


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

Issue:
Number of attendees  in admin section is wrong
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
In the admin dashboard, the given number of attendees is wrong because we can simply find the list of attendees in any event's attendee list

![image](https://user-images.githubusercontent.com/21087061/53297811-e22ed980-3849-11e9-9463-f84f4d2f945f.png)

![screenshot from 2019-02-24 15-33-02](https://user-images.githubusercontent.com/21087061/53297815-ef4bc880-3849-11e9-8a63-d47935d7e216.png)

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
The number of attendees should account for the number of attendees present in each event. 

**Additional details (please complete the following information):**
 - OS: [e.g. MacOS, Ubuntu, CentOS] Ubuntu 16.04 LTS
 - Python Version [e.g. `3.5`, `3.6`] 3.5

**Additional context**
<!-- Add any other context about the problem here. -->
Working on it


Discussion:

Resolving patch:
diff --git a/app/api/admin_statistics_api/users.py b/app/api/admin_statistics_api/users.py
--- a/app/api/admin_statistics_api/users.py
+++ b/app/api/admin_statistics_api/users.py
@@ -10,6 +10,7 @@
 from app.models.event import Event
 from app.models.users_events_role import UsersEventsRoles
 from app.models.role import Role
+from app.models.ticket_holder import TicketHolder
 from app.api.helpers.db import get_count
 
 class AdminStatisticsUserSchema(Schema):
@@ -62,7 +63,8 @@ def track_organizer_count(self, obj):
         return self.get_all_user_roles('track_organizer').count()
 
     def attendee_count(self, obj):
-        return self.get_all_user_roles('attendee').count()
+        unique_attendee_query = db.session.query(TicketHolder.email).distinct()
+        return unique_attendee_query.count()
 
 
 class AdminStatisticsUserDetail(ResourceDetail):


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

Issue:
Email: New Session Proposal does not provide correct link
The proposal email does not provide correct link, e.g. it is: https://eventyay.com/events/598/sessions/5201

![screenshot from 2019-01-23 17-43-00](https://user-images.githubusercontent.com/1583873/51622223-700b6200-1f36-11e9-9d5f-a5fc76c63c16.png)



Discussion:
What should be the expected link for the same?

Working on this


Resolving patch:
diff --git a/app/api/sessions.py b/app/api/sessions.py
--- a/app/api/sessions.py
+++ b/app/api/sessions.py
@@ -51,8 +51,9 @@ def after_create_object(self, session, data, view_kwargs):
             organizer = session.event.get_organizer()
             organizer_email = organizer.email
             frontend_url = get_settings()['frontend_url']
+            event = session.event
             link = "{}/events/{}/sessions/{}"\
-                .format(frontend_url, session.event_id, session.id)
+                .format(frontend_url, event.identifier, session.id)
             send_email_new_session(organizer_email, event_name, link)
             send_notif_new_session_organizer(organizer, event_name, link, session.id)
 
@@ -126,12 +127,14 @@ def after_update_object(self, session, data, view_kwargs):
 
         if 'state' in data and data.get('send_email', None) and (session.state == 'accepted' or
                                                                  session.state == 'rejected'):
+
+            event = session.event
             # Email for speaker
             speakers = session.speakers
             for speaker in speakers:
                 frontend_url = get_settings()['frontend_url']
                 link = "{}/events/{}/sessions/{}" \
-                    .format(frontend_url, session.event_id, session.id)
+                    .format(frontend_url, event.identifier, session.id)
                 send_email_session_accept_reject(speaker.email, session, link)
                 send_notif_session_accept_reject(speaker, session.title, session.state, link, session.id)
 
@@ -141,7 +144,7 @@ def after_update_object(self, session, data, view_kwargs):
                 organizer_email = organizer.email
                 frontend_url = get_settings()['frontend_url']
                 link = "{}/events/{}/sessions/{}" \
-                    .format(frontend_url, session.event_id, session.id)
+                    .format(frontend_url, event.identifier, session.id)
                 send_email_session_accept_reject(organizer_email, session,
                                                  link)
                 send_notif_session_accept_reject(organizer, session.title,


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

Issue:
Settings don't refresh on PATCH
**Describe the bug**
Settings are cached in memory and never again fetched from DB, even when they are patched. 

- Refresh settings on PATCH request

Secondly, if someone edits settings from DB, there is no way to refresh them. Call for discussion if this should be left that way. Cache should be expired after a period of time, or there should be an endpoint to explicitly refresh in memory settings


Discussion:
@poush @CosmicCoder96 What are your views on the second problem?
Is this error still occurring? Would like to look into fixing this as this might be a priority in some cases.
I've fixed the bug. The issue is open to discuss the second point 
@iamareebjamal IMO, creating an endpoint would be much feasible as the user can click a button and get the updates instantaneously.
Otherwise, he would have to wait for the cache cycle-time to finish.
This option does not concern the user. But yes, I agree there should be an endpoint for admins to refresh the settings
I guess both the things should be there. Incase user makes an update but then forgets about refreshing the cached settings, it will automatically happen once the cache expires. Moreover, if the user wants the settings to immediately be reflected then he/she can simply hit the refresh button. 
@iamareebjamal can i work on adding a endpoint to refresh settings

Resolving patch:
diff --git a/app/api/settings.py b/app/api/settings.py
--- a/app/api/settings.py
+++ b/app/api/settings.py
@@ -27,6 +27,9 @@ class SettingDetail(ResourceDetail):
     """
 
     def before_get(self, args, kwargs):
+        refresh = request.args.get('refresh')
+        if refresh == 'true':
+            refresh_settings()
         kwargs['id'] = 1
 
         if 'Authorization' in request.headers:


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

Issue:
Replace all 3rd party links to reliable resource
**Describe the bug**
Many links which have either been used for testing/mainstream access  using `urllib` are often blocked due to some issue with the site security or some other reason. 

**Expected behavior**
All links must point to a certain reliable resource like FOSSASIA's website to ensure reliable access.

**Stacktrace**
One of the plausible errors which might occur `urllib.error.HTTPError: HTTP Error 403: Forbidden`

**Additional Info**:
Working  on it


Discussion:

Resolving patch:
diff --git a/app/api/helpers/utilities.py b/app/api/helpers/utilities.py
--- a/app/api/helpers/utilities.py
+++ b/app/api/helpers/utilities.py
@@ -112,6 +112,8 @@ def update_state(task_handle, state, result=None):
             state=state, meta=result
         )
 
+static_page = 'https://eventyay.com/'
+image_link = 'https://www.gstatic.com/webp/gallery/1.jpg'
 
 # store task results in case of testing
 # state and info
diff --git a/app/factories/common.py b/app/factories/common.py
--- a/app/factories/common.py
+++ b/app/factories/common.py
@@ -1,12 +1,12 @@
 import factory
-
+from app.api.helpers.utilities import static_page, image_link
 # use camelCase for naming variables
 
 string_ = 'example'
 email_ = factory.Sequence(lambda n: 'user{0}@example.com'.format(n))
 integer_ = 25
-url_ = 'http://example.com'
-imageUrl_ = 'https://www.w3schools.com/html/pic_mountain.jpg'
+url_ = static_page
+imageUrl_ = image_link
 date_ = '2016-12-13T23:59:59.123456+00:00'
 dateFuture_ = '2099-12-13T23:59:59.123456+00:00'
 dateEndFuture_ = '2099-12-14T23:59:59.123456+00:00'


Test patch:
diff --git a/tests/all/integration/api/helpers/test_files.py b/tests/all/integration/api/helpers/test_files.py
--- a/tests/all/integration/api/helpers/test_files.py
+++ b/tests/all/integration/api/helpers/test_files.py
@@ -12,7 +12,7 @@
 from app.api.helpers.files import uploaded_image, uploaded_file
 from tests.all.integration.setup_database import Setup
 from tests.all.integration.utils import OpenEventTestCase
-
+from app.api.helpers.utilities import image_link
 
 class TestFilesHelperValidation(OpenEventTestCase):
     def setUp(self):
@@ -112,7 +112,7 @@ def test_create_save_resized_image(self):
         """Method to test create resized images"""
 
         with app.test_request_context():
-            image_url_test = 'https://www.gstatic.com/webp/gallery/1.jpg'
+            image_url_test = image_link
             width = 500
             height = 200
             aspect_ratio = False
@@ -129,7 +129,7 @@ def test_create_save_image_sizes(self):
         """Method to test create image sizes"""
 
         with app.test_request_context():
-            image_url_test = 'https://www.gstatic.com/webp/gallery/1.jpg'
+            image_url_test =  image_link
             image_sizes_type = "event-image"
             width_large = 1300
             width_thumbnail = 500
Repository: fossasia/open-event-server

Issue:
is_billing_enabled is not updatable
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
`is_billing_enabled` field is not updatable which is the primary reason of forbidden message when integrating `isBillingEnabled` to front-end and ordering ticket.

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
The tickets should be ordered without any forbidden message

**Additional details (please complete the following information):**
 - OS: [e.g. MacOS, Ubuntu, CentOS] Ubuntu 18.04

**Additional context**
<!-- Add any other context about the problem here. -->
https://github.com/fossasia/open-event-frontend/pull/2207#pullrequestreview-212709278



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
@@ -275,7 +275,11 @@ def before_update_object(self, order, data, view_kwargs):
                                          "You cannot update a non-pending order")
             else:
                 for element in data:
-                    if data[element] and data[element]\
+                    if element == 'is_billing_enabled' and order.status == 'completed' and data[element]\
+                            and data[element] != getattr(order, element, None):
+                        raise ForbiddenException({'pointer': 'data/{}'.format(element)},
+                                                 "You cannot update {} of a completed order".format(element))
+                    elif data[element] and data[element]\
                             != getattr(order, element, None) and element not in get_updatable_fields():
                         raise ForbiddenException({'pointer': 'data/{}'.format(element)},
                                                  "You cannot update {} of an order".format(element))
diff --git a/app/models/order.py b/app/models/order.py
--- a/app/models/order.py
+++ b/app/models/order.py
@@ -23,7 +23,7 @@ def get_updatable_fields():
     """
     return ['country', 'address', 'city', 'state', 'zipcode', 'company', 'tax_business_info', 'status', 'paid_via',
             'order_notes', 'deleted_at', 'user', 'payment_mode', 'event', 'discount_code_id', 'discount_code',
-            'ticket_holders', 'user', 'tickets_pdf_url']
+            'ticket_holders', 'user', 'tickets_pdf_url', 'is_billing_enabled']
 
 
 class OrderTicket(SoftDeletionModel):


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

Issue:
Date for speakers call shouldn't be past event date

![Screenshot from 2019-03-13 13-17-53](https://user-images.githubusercontent.com/25197147/54261749-9347aa80-4592-11e9-9bdf-1dc71a134e4e.png)
**Describe the bug**
Currently, the Call for Speakers date can be set after the Event date. 

**To Reproduce**
Steps to reproduce the behavior:
1. Go to 'Create event'
2. Fill in necessary details and go to Sessions&Speakers tab
3. Set the Event date as Friday, June 14th 2019, 12:00 AM 
4. Set the date for Call for Speakers as Sat, Oct 12 12:00 AM
4. See error

**Expected behavior**
This should return an error with an appropriate message

**Additional Information**
Working on it.


Discussion:

Resolving patch:
diff --git a/app/api/speakers_calls.py b/app/api/speakers_calls.py
--- a/app/api/speakers_calls.py
+++ b/app/api/speakers_calls.py
@@ -36,7 +36,10 @@ def before_create_object(self, data, view_kwargs):
         :return:
         """
         try:
-            self.session.query(SpeakersCall).filter_by(event_id=data['event'], deleted_at=None).one()
+            speakers_call = self.session.query(SpeakersCall).filter_by(event_id=data['event'], deleted_at=None).one()
+            event = speakers_call.event
+            if speakers_call.starts_at > event.starts_at or speakers_call.ends_at > event.starts_at:
+                raise ForbiddenException({'source': ''}, "Speakers call date can\'t be after the event start date")
         except NoResultFound:
             pass
         else:
@@ -67,10 +70,14 @@ def before_patch(self, args, kwargs, data):
         if kwargs.get('event_id'):
             try:
                 speakers_call = SpeakersCall.query.filter_by(event_id=kwargs['event_id']).one()
+                event = speakers_call.event
+                if speakers_call.starts_at > event.starts_at or speakers_call.ends_at > event.starts_at:
+                    raise ForbiddenException({'source': ''}, "Speakers call date can\'t be after the event start date")
             except NoResultFound:
                 raise ObjectNotFound({'source': ''}, "Object: not found")
             kwargs['id'] = speakers_call.id
 
+
     def before_get_object(self, view_kwargs):
         """
         before get method to get the resource id for fetching details


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

Issue:
deleting Inactive Users assigning them roles automatically
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
Deleting Inactive Users assigning them roles automatically, please see the GIF for clarity

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
No such roles should be assigned to any deleted user

**GIF**
<!-- If applicable, add screenshots to help explain your problem. -->
![ezgif com-video-to-gif 5](https://user-images.githubusercontent.com/21087061/53220697-e57c6680-368b-11e9-9c07-1afb9d2450ff.gif)

**Desktop (please complete the following information):**
 - OS: [e.g. iOS] Ubuntu 16.04LTS
 - Browser [e.g. chrome, safari] Chrome

**Additional context**
<!-- Add any other context about the problem here. -->
Working on it


Discussion:
Pushing a PR tonight

Resolving patch:
diff --git a/app/api/users.py b/app/api/users.py
--- a/app/api/users.py
+++ b/app/api/users.py
@@ -216,10 +216,10 @@ def before_update_object(self, user, data, view_kwargs):
         if has_access('is_super_admin') and data.get('is_admin') and data.get('is_admin') != user.is_admin:
             user.is_admin = not user.is_admin
 
-        if has_access('is_admin') and data.get('is_sales_admin') != user.is_sales_admin:
+        if has_access('is_admin') and ('is_sales_admin' in data) and data.get('is_sales_admin') != user.is_sales_admin:
             user.is_sales_admin = not user.is_sales_admin
 
-        if has_access('is_admin') and data.get('is_marketer') != user.is_marketer:
+        if has_access('is_admin') and ('us_marketer' in data) and data.get('is_marketer') != user.is_marketer:
             user.is_marketer = not user.is_marketer
 
     def after_update_object(self, user, data, view_kwargs):


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

Issue:
Payment currency missing in admin sales api
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
`payment_currency` is missing in `discounted` and `events` of `admin_sales`. 

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
`payment_currency` must be returned too

**Additional context**
<!-- Add any other context about the problem here. -->
Related to https://github.com/fossasia/open-event-frontend/issues/2316
Working on it



Discussion:

Resolving patch:
diff --git a/app/api/admin_sales/discounted.py b/app/api/admin_sales/discounted.py
--- a/app/api/admin_sales/discounted.py
+++ b/app/api/admin_sales/discounted.py
@@ -49,6 +49,7 @@ class Meta:
     code = fields.String()
     email = fields.String()
     event_name = fields.String()
+    payment_currency = fields.String()
     sales = fields.Method('calc_sales')
 
     @staticmethod
diff --git a/app/api/admin_sales/events.py b/app/api/admin_sales/events.py
--- a/app/api/admin_sales/events.py
+++ b/app/api/admin_sales/events.py
@@ -30,6 +30,7 @@ class Meta:
     name = fields.String()
     starts_at = fields.DateTime()
     ends_at = fields.DateTime()
+    payment_currency = fields.String()
     sales = fields.Method('calc_sales')
 
     @staticmethod


Test patch: