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

Issue:
Order flow: Implement a 'was_registered_with_order' field to the User model
This field will be true for users who were registered while placing an order as a guest.
This can be used to differentiate between the kind of welcome email which has to be sent.

Parent issue #5546 


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
@@ -30,6 +30,8 @@ class Meta:
     thumbnail_image_url = fields.Url(dump_only=True, allow_none=True)
     small_image_url = fields.Url(dump_only=True, allow_none=True)
     icon_image_url = fields.Url(dump_only=True, allow_none=True)
+    was_registered_with_order = fields.Boolean()
+
 
 
 class UserSchema(UserSchemaPublic):
diff --git a/app/models/user.py b/app/models/user.py
--- a/app/models/user.py
+++ b/app/models/user.py
@@ -75,6 +75,7 @@ class User(SoftDeletionModel):
     is_sales_admin = db.Column(db.Boolean, default=False)
     is_marketer = db.Column(db.Boolean, default=False)
     is_verified = db.Column(db.Boolean, default=False)
+    was_registered_with_order = db.Column(db.Boolean, default=False)
     last_accessed_at = db.Column(db.DateTime(timezone=True))
     created_at = db.Column(db.DateTime(timezone=True), default=datetime.now(pytz.utc))
     speaker = db.relationship('Speaker', backref="user")
diff --git a/migrations/versions/e3caa0f2a16c_.py b/migrations/versions/e3caa0f2a16c_.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/e3caa0f2a16c_.py
@@ -0,0 +1,25 @@
+"""empty message
+
+Revision ID: e3caa0f2a16c
+Revises: 41818fe31207
+Create Date: 2019-01-30 02:32:10.365941
+
+"""
+
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = 'e3caa0f2a16c'
+down_revision = '41818fe31207'
+
+
+def upgrade():
+    op.add_column('users', sa.Column('was_registered_with_order', sa.Boolean(), nullable=True))
+    # ### end Alembic commands ###
+
+
+def downgrade():
+    op.drop_column('users', 'was_registered_with_order')
+    # ### end Alembic commands ###


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

Issue:
Allow GET access to ticket attendees for an order, for non logged in users
parent issue #5546 


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
@@ -112,8 +112,8 @@ def query(self, view_kwargs):
 
         if view_kwargs.get('ticket_id'):
             ticket = safe_query(self, Ticket, 'id', view_kwargs['ticket_id'], 'ticket_id')
-            if not has_access('is_registrar', event_id=ticket.event_id):
-                raise ForbiddenException({'source': ''}, 'Access Forbidden')
+            # if not has_access('is_registrar', event_id=ticket.event_id):
+            #     raise ForbiddenException({'source': ''}, 'Access Forbidden')
             query_ = query_.join(Ticket).filter(Ticket.id == ticket.id)
 
         if view_kwargs.get('user_id'):


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

Issue:
Update docs on Events end point to accomodate additional fields  for Front end's sidebar
The frontend facilitates all the public aspects of an event through a side menu as shown below.
![image](https://user-images.githubusercontent.com/17252805/51509651-e2941900-1e34-11e9-9e09-cfcfccca1ef0.png)

However, it is desired to only show a menu item, if it's corresponding entries exist. For instance, display the item sessions, if sessions are present, display speakers if speakers are present.  Display schedule if the schedule is published etc.

To achieve this functionality the frontend has to make a call to the corresponding endpoint to check if sessions or speakers exist, but that results in sending 100s of network requests for data, user is probably not going to view anyway. 

Thus there needs to be an api endpoint or property values in the event schema itself, which tells if **sessions**,  **speakers** are present for a given event. Current production environment has revealed that querying sessions and speakers results in a significant overhead.




Discussion:
@iamareebjamal What would be the correct approach to rectify this situation.
An event info endpoint which tells the status and information about what is present in the event in form of booleans
Is this issue up for taking ? 
Would like to work on it.
@apoorvkhare07 go ahead.

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
@@ -82,6 +82,8 @@ def validate_timezone(self, data, original_data):
     organizer_name = fields.Str(allow_none=True)
     is_map_shown = fields.Bool(default=False)
     has_organizer_info = fields.Bool(default=False)
+    has_sessions = fields.Bool(default=0, dump_only=True)
+    has_speakers = fields.Bool(default=0, dump_only=True)
     organizer_description = fields.Str(allow_none=True)
     is_sessions_speakers_enabled = fields.Bool(default=False)
     privacy = fields.Str(default="public")
diff --git a/app/models/event.py b/app/models/event.py
--- a/app/models/event.py
+++ b/app/models/event.py
@@ -18,6 +18,8 @@
 from app.models.helpers.versioning import clean_up_string, clean_html
 from app.models.user import ATTENDEE, ORGANIZER
 from app.models.event_topic import EventTopic
+from app.models.session import Session
+from app.models.speaker import Speaker
 from app.models.search import sync
 from app.models.ticket import Ticket
 from app.models.ticket_holder import TicketHolder
@@ -380,6 +382,15 @@ def tickets_sold(self):
     def revenue(self):
         return self.calc_revenue()
 
+    @property
+    def has_sessions(self):
+        return Session.query.filter_by(event_id=self.id).count() > 0
+
+    @property
+    def has_speakers(self):
+        return Speaker.query.filter_by(event_id=self.id).count() > 0
+
+
 
 @event.listens_for(Event, 'after_update')
 @event.listens_for(Event, 'after_insert')


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

Issue:
Session Export CSV does not include all data 
The Session Export should export all data sets that are available e.g. including:
* Submission time
* All speakers
* Proposed length
* Type (Workshop, Talk)
* Level (e.g. Intermediate)
* Status (e.g. pending, accepted etc.)

![screenshot from 2019-01-17 00-04-14](https://user-images.githubusercontent.com/1583873/51284380-a3f0ff80-19eb-11e9-9a1c-3b37c6ad36ad.png)


Discussion:
@mrsaicharan1 Can you take this up?
Yes. I'll work on this issue.

Resolving patch:
diff --git a/app/api/helpers/csv_jobs_util.py b/app/api/helpers/csv_jobs_util.py
--- a/app/api/helpers/csv_jobs_util.py
+++ b/app/api/helpers/csv_jobs_util.py
@@ -47,7 +47,8 @@ def export_attendees_csv(attendees):
 
 def export_sessions_csv(sessions):
     headers = ['Session Title', 'Session Speakers',
-               'Session Track', 'Session Abstract', 'Created At', 'Email Sent']
+               'Session Track', 'Session Abstract', 'Created At', 'Email Sent',
+               'Level', 'Status', 'Session Type', 'Talk Length']
     rows = [headers]
     for session in sessions:
         if not session.deleted_at:
@@ -64,6 +65,10 @@ def export_sessions_csv(sessions):
             column.append(strip_tags(session.short_abstract) if session.short_abstract else '')
             column.append(session.created_at if session.created_at else '')
             column.append('Yes' if session.is_mail_sent else 'No')
+            column.append(session.level)
+            column.append(session.state)
+            column.append(session.type)
+            column.append(len(session.long_abstract))
             rows.append(column)
 
     return rows


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

Issue:
No longer see in My Sessions talks where am an additional speaker.
**Describe the bug**

After the update to ``https://eventyay.com``, when you go to ``My Sessions`` you can no longer see talk proposals where you were added as an additional speaker by someone else. Thus you cannot see whether those talks are still marked as pending, or if accepted or confirmed, as there is no entry for them.

**To Reproduce**

Presumably have someone else create a talk proposal where they are the owner, and then add you as additional speaker. See if that talk then appears under ``My Sessions`` for yourself.

**Expected behavior**

As used to be the case, expect to see talk proposals under ``My Sessions`` where was added as an additional speaker by someone else.

**Screenshots**

N/A

**Desktop (please complete the following information):**
 
macOS / Chrome

**Smartphone (please complete the following information):**

N/A

**Additional context**

N/A



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
@@ -87,7 +87,8 @@ def query(self, view_kwargs):
             query_ = query_.join(Microlocation).filter(Microlocation.id == microlocation.id)
         if view_kwargs.get('user_id') is not None:
             user = safe_query(self, User, 'id', view_kwargs['user_id'], 'user_id')
-            query_ = query_.join(User).filter(User.id == user.id)
+            query_ = query_.join(User)\
+                .join(Speaker).filter((User.id == user.id or Session.speakers.any(Speaker.user_id == user.id)))
         query_ = event_query(self, query_, view_kwargs)
         if view_kwargs.get('speaker_id'):
             speaker = safe_query(self, Speaker, 'id', view_kwargs['speaker_id'], 'speaker_id')


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

Issue:
Can't delete 'expired orders'
**Describe the bug**
I now have a lot of 'expired orders', which seem to add to the max nr of tickets - so we have 28 of 100 tickets sold, even though only 7 orders were placed, the rest are tests or expired. I tried to delete them but 'an unexpected error occured'. Cancellation gives the same issue.
https://eventyay.com/events/d1196adb/tickets/orders/expired

Happens in Chromium/Linux.


Discussion:
Expired orders should not be counted in the "tickets sold" category and automatically disappear after 48 hours or so.

Resolving patch:
diff --git a/app/api/orders.py b/app/api/orders.py
--- a/app/api/orders.py
+++ b/app/api/orders.py
@@ -315,8 +315,7 @@ def before_delete_object(self, order, view_kwargs):
 
     # This is to ensure that the permissions manager runs and hence changes the kwarg from order identifier to id.
     decorators = (jwt_required, api.has_permission(
-        'auth_required', methods="PATCH,DELETE", fetch="user_id", model=Order),)
-
+        'auth_required', methods="PATCH,DELETE", model=Order),)
     schema = OrderSchema
     data_layer = {'session': db.session,
                   'model': Order,


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

Issue:
Facebook Login Should throw an error when auth keys unavailable
**Describe the bug**
Whenever a user clicks on Login with Facebook, he should be notified if the keys are not set in the admin settings.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to 'Login Page'
2. Click on 'Login with Facebook'
3. Doesn't do anything

**Expected behavior**
It should notify the user that the keys are not set, otherwise redirect to facebook oauth login page.

**Additional context**
Working on this



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
@@ -94,6 +94,8 @@ def login_user(provider, auth_code):
             'client_secret': provider_class.get_client_secret(),
             'code': auth_code
         }
+        if not payload['client_id'] or payload['client_secret']:
+            raise NotImplementedError({'source': ''}, 'Facebook Login Not Configured')
         access_token = requests.get('https://graph.facebook.com/v3.0/oauth/access_token', params=payload).json()
         payload_details = {
             'input_token': access_token['access_token'],


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

Issue:
Users are given various roles when they are deleted
**Describe the bug**
Users are given various roles when they are deleted

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->

**Screenshots**
![userdelete](https://user-images.githubusercontent.com/19900978/52442524-5cbce100-2b49-11e9-9c3d-1ddc5ce649b2.gif)

**Additional context**
I am working on this issue


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
@@ -208,7 +208,7 @@ def before_update_object(self, user, data, view_kwargs):
             else:
                 raise ConflictException({'pointer': '/data/attributes/email'}, "Email already exists")
 
-        if has_access('is_super_admin') and data.get('is_admin') != user.is_admin:
+        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:


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

Issue:
Making the required password length uniform
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
For front end : A new user has to set a password of length >= 6
For server : A new user has to set a password of atleast 4 characters. (On making a super-admin by `create_db.py` )

**To Reproduce**
Steps to reproduce the behavior:
1. Go to create_db.py
2. See error

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
The required length should be uniform so I am proposing to set this length to 6 on server side


**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/auth.py b/app/api/auth.py
--- a/app/api/auth.py
+++ b/app/api/auth.py
@@ -251,7 +251,9 @@ def change_password():
         return NotFoundError({'source': ''}, 'User Not Found').respond()
     else:
         if user.is_correct_password(old_password):
-
+            if len(new_password) < 8:
+                return BadRequestError({'source': ''},
+                                       'Password should have minimum 8 characters').respond()
             user.password = new_password
             save_to_db(user)
             send_email_with_action(user, PASSWORD_CHANGE,
diff --git a/app/api/users.py b/app/api/users.py
--- a/app/api/users.py
+++ b/app/api/users.py
@@ -41,10 +41,14 @@ class UserList(ResourceList):
     def before_create_object(self, data, view_kwargs):
         """
         method to check if there is an existing user with same email which is received in data to create a new user
+        and if the password is at least 8 characters long
         :param data:
         :param view_kwargs:
         :return:
         """
+        if len(data['password']) < 8:
+            raise UnprocessableEntity({'source': '/data/attributes/password'},
+                                       'Password should be at least 8 characters long')
         if db.session.query(User.id).filter_by(email=data['email']).scalar() is not None:
             raise ConflictException({'pointer': '/data/attributes/email'}, "Email already exists")
 
diff --git a/create_db.py b/create_db.py
--- a/create_db.py
+++ b/create_db.py
@@ -24,8 +24,8 @@ def create_default_user(email, password):
         ask_password = True
         while ask_password:
             password = getpass.getpass("Enter password for super_admin : ")
-            if len(password) < 4:
-                print('\nPassword should have minimum 4 characters')
+            if len(password) < 8:
+                print('\nPassword should have minimum 8 characters')
                 continue
             repassword = getpass.getpass("Enter your password again to confirm : ")
             if password != repassword:


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

Issue:
Admin Statistics counting deleted events 
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
The frontend is accounting deleted event data in the front-end admin statistics.
For ex. the published event count being shown is 3 even though one of the events has been deleted. Same goes for draft counts.

Note : I am opening this issue in the server side because the `admin` panel has direct end-point at the server.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to 'Admin'
2. Delete a few events
3. See error


![image](https://user-images.githubusercontent.com/21087061/52662122-8bf89700-2f29-11e9-941e-e2003984e145.png)

![image](https://user-images.githubusercontent.com/21087061/52662150-a0d52a80-2f29-11e9-8445-37507012d40d.png)

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
The deleted events should not be counted in `published` or `draft` status

**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/schema/admin_statistics_schema/events.py b/app/api/schema/admin_statistics_schema/events.py
--- a/app/api/schema/admin_statistics_schema/events.py
+++ b/app/api/schema/admin_statistics_schema/events.py
@@ -26,11 +26,11 @@ class Meta:
 
     def events_draft_count(self, obj):
         events = Event.query.filter(Event.ends_at > datetime.now(pytz.utc))
-        return get_count(events.filter_by(state='draft'))
+        return get_count(events.filter_by(state='draft', deleted_at=None))
 
     def events_published_count(self, obj):
         events = Event.query.filter(Event.ends_at > datetime.now(pytz.utc))
-        return get_count(events.filter_by(state='published'))
+        return get_count(events.filter_by(state='published', deleted_at=None))
 
     def events_past_count(self, obj):
         return get_count(Event.query.filter(Event.ends_at < datetime.now(pytz.utc)))


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

Issue:
Translations download not working for Admin(.po messages)
**Describe the bug**
Admin should be able to download .po messages

**To Reproduce**
Steps to reproduce the behavior:
1. Go to 'Admin page'
2. Click on 'Content tab'
3. Click down to 'Translations' bar
4. Click on the download button for .po files
5. No action 
**Expected behavior**
The .po files should be downloaded in a .zip format

**Additional context**
Willing to work on this



Discussion:

Resolving patch:
diff --git a/app/__init__.py b/app/__init__.py
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -148,6 +148,7 @@ def create_app():
         from app.api.users import user_misc_routes
         from app.api.orders import order_misc_routes
         from app.api.role_invites import role_invites_misc_routes
+        from app.api.admin_translations import admin_blueprint
 
         app.register_blueprint(api_v1)
         app.register_blueprint(event_copy)
@@ -161,6 +162,7 @@ def create_app():
         app.register_blueprint(attendee_misc_routes)
         app.register_blueprint(order_misc_routes)
         app.register_blueprint(role_invites_misc_routes)
+        app.register_blueprint(admin_blueprint)
 
     sa.orm.configure_mappers()
 
diff --git a/app/api/admin_translations.py b/app/api/admin_translations.py
new file mode 100644
--- /dev/null
+++ b/app/api/admin_translations.py
@@ -0,0 +1,24 @@
+from flask import send_file, Blueprint
+import shutil
+import uuid
+import tempfile
+import os
+
+admin_blueprint = Blueprint('admin_blueprint', __name__, url_prefix='/admin/content/translations/all')
+temp_dir = tempfile.gettempdir()
+translations_dir = 'app/translations'
+
+@admin_blueprint.route('/', methods=['GET'])
+def download_translations():
+    """Admin Translations Downloads"""
+    uuid_literal = uuid.uuid4()
+    zip_file = "translations{}".format(uuid_literal)
+    zip_file_ext = zip_file+'.zip'
+    shutil.make_archive(zip_file, "zip", translations_dir)
+    shutil.move(zip_file_ext, temp_dir)
+    path_to_zip = os.path.join(temp_dir, zip_file_ext)
+    from .helpers.tasks import delete_translations
+    delete_translations.apply_async(path_to_zip, countdown=600)
+    return send_file(path_to_zip,  mimetype='application/zip',
+                     as_attachment=True,
+                     attachment_filename='translations.zip')
diff --git a/app/api/helpers/tasks.py b/app/api/helpers/tasks.py
--- a/app/api/helpers/tasks.py
+++ b/app/api/helpers/tasks.py
@@ -477,3 +477,11 @@ def export_speakers_pdf_task(self, event_id):
         logging.error('Error in exporting speakers as PDF')
 
     return result
+
+
+@celery.task(base=RequestContextTask, name='delete.translations', bind=True)
+def delete_translations(self, zip_file_path):
+    try:
+        os.remove(zip_file_path)
+    except:
+        logging.exception('Error while deleting translations zip file')


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

Issue:
By-Organizer section showing no information in Admin/Sales
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->

**To Reproduce**
Steps to reproduce the behavior:
1. Go to Admin/Sales
2. See error
![image](https://user-images.githubusercontent.com/21087061/52954161-6e0ab680-33af-11e9-9d7e-f18597574159.png)

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
It should be showing the information of the sales per event organiser email

**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. -->
Looking into it


Discussion:

Resolving patch:
diff --git a/app/api/admin_sales/organizer.py b/app/api/admin_sales/organizer.py
--- a/app/api/admin_sales/organizer.py
+++ b/app/api/admin_sales/organizer.py
@@ -19,7 +19,7 @@ class AdminSalesByOrganizersSchema(Schema):
     Sales summarized by organizer
 
     Provides
-        organizer (first name and last name),
+        organizer (first name, last name and email),
         count of tickets and total sales for orders grouped by status
     """
 
@@ -31,6 +31,7 @@ class Meta:
     id = fields.String()
     first_name = fields.String()
     last_name = fields.String()
+    email = fields.String()
     starts_at = fields.DateTime()
     ends_at = fields.DateTime()
     sales = fields.Method('calc_sales')


Test patch: