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

Issue:
Cleaning Image upload in profile page
Image upload in profile page doesn't work.

Fixing this issue fixes:
- [ ] #2703 
- [ ] #2701 


Discussion:

Resolving patch:
diff --git a/app/helpers/data.py b/app/helpers/data.py
--- a/app/helpers/data.py
+++ b/app/helpers/data.py
@@ -701,16 +701,19 @@ def update_user(form, user_id, contacts_only_update=False):
                 user_detail.twitter = ''
 
             user_detail.details = form['details']
-            logo = form.get('logo', None)
-            # print logo
-            if string_not_empty(logo) and logo:
+            avatar_img = form.get('avatar-img', None)
+            user_detail.avatar_uploaded = ""
+            user_detail.thumbnail = ""
+            user_detail.small = ""
+            user_detail.icon = ""
+            if string_not_empty(avatar_img) and avatar_img:
                 filename = '{}.png'.format(time.time())
                 filepath = '{}/static/{}'.format(path.realpath('.'),
-                                                 logo[len('/serve_static/'):])
+                                                 avatar_img[len('/serve_static/'):])
                 # print "File path 1", filepath
-                logo_file = UploadedFile(filepath, filename)
-                logo_temp = upload(logo_file, 'users/%d/avatar' % int(user_id))
-                user_detail.avatar_uploaded = logo_temp
+                avatar_img_file = UploadedFile(filepath, filename)
+                avatar_img_temp = upload(avatar_img_file, 'users/%d/avatar' % int(user_id))
+                user_detail.avatar_uploaded = avatar_img_temp
                 image_sizes = DataGetter.get_image_sizes_by_type(type='profile')
                 if not image_sizes:
                     image_sizes = ImageSizes(full_width=150,
@@ -723,11 +726,11 @@ def update_user(form, user_id, contacts_only_update=False):
                 save_to_db(image_sizes, "Image Sizes Saved")
                 filename = '{}.jpg'.format(time.time())
                 filepath = '{}/static/{}'.format(path.realpath('.'),
-                                                 logo[len('/serve_static/'):])
+                                                 avatar_img[len('/serve_static/'):])
                 # print "File path 1", filepath
-                logo_file = UploadedFile(filepath, filename)
+                avatar_img_file = UploadedFile(filepath, filename)
 
-                temp_img_file = upload_local(logo_file,
+                temp_img_file = upload_local(avatar_img_file,
                                              'users/{user_id}/temp'.format(user_id=int(user_id)))
                 temp_img_file = temp_img_file.replace('/serve_', '')
 


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

Issue:
After Password Reset direct to Login Page
After resetting the password the user is redirected to the start page. Please change as folllows:

* [x] redirect to login page
* [x] display message "Your password has been changed. Please login with your new password now."


Discussion:
@mariobehling  on it

Resolving patch:
diff --git a/app/views/home.py b/app/views/home.py
--- a/app/views/home.py
+++ b/app/views/home.py
@@ -177,6 +177,7 @@ def password_reset_view():
         user = DataGetter.get_user_by_email(email)
         if user:
             link = request.host + url_for(".change_password_view", hash=user.reset_password)
+            return link
             send_email_with_reset_password_hash(email, link)
             flash('Please go to the link sent to your email to reset your password')
         return redirect(url_for('.login_view'))
diff --git a/app/views/users/settings.py b/app/views/users/settings.py
--- a/app/views/users/settings.py
+++ b/app/views/users/settings.py
@@ -8,6 +8,7 @@
 from app.helpers.data import DataManager, save_to_db
 from app.helpers.data_getter import DataGetter
 from app.models.email_notifications import EmailNotification
+from app.views.home import record_user_login_logout
 
 
 def get_or_create_notification_settings(event_id):
@@ -43,7 +44,10 @@ def password_view():
                 user.password = generate_password_hash(request.form['new_password'], salt)
                 user.salt = salt
                 save_to_db(user, "password changed")
-                flash('Password changed successfully.', 'success')
+                record_user_login_logout('user_logout', login.current_user)
+                login.logout_user()
+                flash('Your password has been changed. Please login with your new password now.', 'success')
+                return redirect(url_for('admin.login_view'))
             else:
                 flash('The new password and the repeat don\'t match.', 'danger')
         else:


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

Issue:
Links and Social Media Section Does Not Work
Tried to add External Link/Twitter/Facebook links to the event page, but links do not show up at the right hand side of the event page as before.


Discussion:
Here's a screenshot showing the area where the links are supposed to be:

![screenshot](https://cloud.githubusercontent.com/assets/9492662/21467915/1c6d2a8e-ca38-11e6-9148-11b58ec0c721.PNG)

Tried many times to add the links again and again but was unsuccessful. The social media section on previously created events appears to be working fine though; just that I am now unable to add social media links to newly created events. 

@GabrielLee22 thanks for report :)

Resolving patch:
diff --git a/app/helpers/wizard/event.py b/app/helpers/wizard/event.py
--- a/app/helpers/wizard/event.py
+++ b/app/helpers/wizard/event.py
@@ -23,6 +23,7 @@
 from app.models.ticket import Ticket, ticket_tags_table, TicketTag
 from app.models.user import ORGANIZER
 from app.models.users_events_roles import UsersEventsRoles
+from app.models.social_link import SocialLink
 
 
 def get_event_json(event_id):
@@ -160,6 +161,8 @@ def save_event_from_json(json, event_id=None):
     copyright.logo = logo
     copyright.licence_url = licence_url
 
+    save_social_links(event_data['social_links'], event)
+
     event.ticket_include = event_data['ticket_include']
 
     if event.ticket_include:
@@ -402,3 +405,14 @@ def save_resized_background(background_image_file, event_id, size, image_sizes):
     )
 
     return save_resized_image(background_image_file, width_, height_, basewidth, aspect, height_size, upload_path)
+
+
+def save_social_links(social_links, event):
+
+    for social_link in social_links:
+        social_exists = SocialLink.query.filter_by(name=social_link['name'], event_id=event.id).scalar()
+        if social_exists:
+            SocialLink.query.filter_by(name=social_link['name'], event_id=event.id).update({'link': social_link['link']})
+        else:
+            social = SocialLink(social_link['name'], social_link['link'], event.id)
+            db.session.add(social)


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

Issue:
Internal server error when clicking any tags in the home page
Internal server error on clicking the tags (like #Conference #ScienceAnTechnology ) in the home page under each event.


Discussion:
@niranjan94 looks like this bug is only with category tags,
since there is a line `testandremove('category')` at https://github.com/fossasia/open-event-orga-server/blob/development/app/views/home.py#L244
removing the line works well with the tag
Please find out why that method is causing an error ... 
Issue is with `request.args.get(key).lower() == request.args.get("query").lower():`
where both objects doesn't have a method lower() on them.
@niranjan94 

@nikhilrayaprolu Not exactly `request.args.get(key)` returns a `string` which has the method `lower()` (https://docs.python.org/2/library/string.html#string.lower)
@niranjan94 the issue is with `request.args.get("query").lower():` . we dont have any parameter named "query" so this is returning None

Resolving patch:
diff --git a/app/helpers/flask_helpers.py b/app/helpers/flask_helpers.py
--- a/app/helpers/flask_helpers.py
+++ b/app/helpers/flask_helpers.py
@@ -56,5 +56,5 @@ def deslugify(text):
 
 
 def camel_case(text):
-    text = deslugify(slugify(text))
+    text = slugify(text).replace('-', " ")
     return ''.join(x for x in text.title() if not x.isspace())
diff --git a/app/views/home.py b/app/views/home.py
--- a/app/views/home.py
+++ b/app/views/home.py
@@ -225,7 +225,7 @@ def browse_view():
     params = dict((k, v) for k, v in params if v)
 
     def test_and_remove(key):
-        if request.args.get(key):
+        if request.args.get(key) and request.args.get("query"):
             if request.args.get(key).lower() == request.args.get("query").lower():
                 erase_from_dict(params, 'query')
 
@@ -246,8 +246,7 @@ def test_and_remove(key):
     test_and_remove("category")
     erase_from_dict(params, 'location')
 
-    return redirect(url_for('explore.explore_view', location=slugify(country)) + '?' +
-                    urllib.urlencode(params))
+    return redirect(url_for('explore.explore_view', location=slugify(country)) + '?' + urllib.urlencode(params))
 
 
 @home_routes.route('/check_email/', methods=('POST', 'GET'))


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

Issue:
Importing FOSSASIA sample results in many duplicate speakers
After importing FOSSASIA 2016 zip, speakers are imported and shown multiple times.

Please compare here: http://open-event-dev.herokuapp.com/e/906f86d6/


Discussion:
Internal event management http://open-event-dev.herokuapp.com/events/266/

Resolving patch:
diff --git a/app/views/public/event_detail.py b/app/views/public/event_detail.py
--- a/app/views/public/event_detail.py
+++ b/app/views/public/event_detail.py
@@ -59,6 +59,12 @@ def display_event_detail_home(identifier):
     else:
         licence_details = None
 
+    speakers = []
+    for session in accepted_sessions:
+        for speaker in session.speakers:
+            if speaker not in speakers:
+                speakers.append(speaker)
+
     module = DataGetter.get_module()
     tickets = DataGetter.get_sales_open_tickets(event.id, True)
     return render_template('gentelella/guest/event/details.html',
@@ -69,6 +75,7 @@ def display_event_detail_home(identifier):
                            accepted_sessions_count=len(accepted_sessions),
                            call_for_speakers=call_for_speakers,
                            licence_details=licence_details,
+                           speakers=speakers,
                            module=module,
                            tickets=tickets if tickets else [])
 


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

Issue:
Internal server error when rejecting/accepting session with email
Reject URL: `/events/<event_id>/sessions/<session_id>/reject/`
Accept URL: `/events/<event_id>/sessions/<session_id>/accept/`


Discussion:
@niranjan94 It is working well at http://open-event-dev.herokuapp.com/events/255/sessions/7172/accept/
 at the development server

Resolving patch:
diff --git a/app/helpers/notification_email_triggers.py b/app/helpers/notification_email_triggers.py
--- a/app/helpers/notification_email_triggers.py
+++ b/app/helpers/notification_email_triggers.py
@@ -37,11 +37,13 @@ def trigger_session_state_change_notifications(session, event_id, state=None):
         email_notification_setting = DataGetter.get_email_notification_settings_by_event_id(speaker.user_id, event_id)
         if not admin_msg_setting or \
             (email_notification_setting and email_notification_setting.session_accept_reject == 1 and
-             admin_msg_setting.user_control_status == 1) or  admin_msg_setting.user_control_status == 0:
+             admin_msg_setting.user_control_status == 1) or admin_msg_setting.user_control_status == 0:
 
-            send_session_accept_reject(speaker.email, session.title, state, link)
+            if speaker.email:
+                send_session_accept_reject(speaker.email, session.title, state, link)
             # Send notification
-        send_notif_session_accept_reject(speaker.user, session.title, state, link)
+        if speaker.user:
+            send_notif_session_accept_reject(speaker.user, session.title, state, link)
     session.state_email_sent = True
     from app.helpers.data import save_to_db
     save_to_db(session)
@@ -55,7 +57,8 @@ def trigger_session_schedule_change_notifications(session, event_id):
         if not admin_msg_setting or \
             (email_notification_setting and email_notification_setting.session_schedule == 1 and
              admin_msg_setting.user_control_status == 1) or admin_msg_setting.user_control_status == 0:
-
-            send_schedule_change(speaker.email, session.title, link)
-            # Send notification
-        send_notif_session_schedule(speaker.user, session.title, link)
+            if speaker.email:
+                send_schedule_change(speaker.email, session.title, link)
+        # Send notification
+        if speaker.user:
+            send_notif_session_schedule(speaker.user, session.title, link)


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

Issue:
SAWarning: The IN-predicate on "ticket.Id" was invoked with an empty sequence.
I am getting this error on creating an event in my local system:

![screenshot from 2016-12-28 21-00-16](https://cloud.githubusercontent.com/assets/9530293/21525075/c096329e-cd40-11e6-852f-0f3e410537f3.png)



Discussion:
@SaptakS it's just a warning right ? Does it break functionality ?
@niranjan94 it gives 404 on publishing event. See the POST request below. It gives error to save event.
`404` ?! That isn't due to the warning .... Something else seems to be causing it here ,.,
@SaptakS found it. Due to https://github.com/fossasia/open-event-orga-server/pull/2706. will fix

Resolving patch:
diff --git a/app/helpers/wizard/sessions_speakers.py b/app/helpers/wizard/sessions_speakers.py
--- a/app/helpers/wizard/sessions_speakers.py
+++ b/app/helpers/wizard/sessions_speakers.py
@@ -35,8 +35,8 @@ def get_microlocations_json(event_id):
     return data
 
 
-def save_session_speakers(json):
-    event_id = json['event_id']
+def save_session_speakers(json, event_id=None):
+    event_id = event_id if event_id else json['event_id']
     event = DataGetter.get_event(event_id)
 
     if json['sessions_speakers_enabled']:
diff --git a/app/helpers/wizard/sponsors.py b/app/helpers/wizard/sponsors.py
--- a/app/helpers/wizard/sponsors.py
+++ b/app/helpers/wizard/sponsors.py
@@ -20,8 +20,8 @@ def get_sponsors_json(event_id_or_sponsors):
     return data
 
 
-def save_sponsors_from_json(json):
-    event_id = json['event_id']
+def save_sponsors_from_json(json, event_id=None):
+    event_id = event_id if event_id else json['event_id']
     event = DataGetter.get_event(event_id)
     sponsors_enabled = json['sponsors_enabled']
 
diff --git a/app/views/users/events.py b/app/views/users/events.py
--- a/app/views/users/events.py
+++ b/app/views/users/events.py
@@ -475,8 +475,8 @@ def save_event_from_wizard(what):
         return jsonify(save_session_speakers(data))
     elif what == 'all':
         response = save_event_from_json(data['event'], event_id)
-        save_sponsors_from_json(data['sponsors'])
-        save_session_speakers(data['session_speakers'])
+        save_sponsors_from_json(data['sponsors'], response['event_id'])
+        save_session_speakers(data['session_speakers'], response['event_id'])
         return jsonify(response)
     else:
         abort(404)


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

Issue:
Custom roles functionality broken
As seen below, I created a custom role superman with access to modules,reports and messages panels.
![selection_035](https://cloud.githubusercontent.com/assets/13910561/21529947/2ede1560-cd63-11e6-8c30-676caf1c2571.png)

I assigned the custom role to a different user.
![selection_034](https://cloud.githubusercontent.com/assets/13910561/21529948/2ee1f3f6-cd63-11e6-800e-c8d3c8e0a832.png)

But the user is still not able to access the specified panels.
![selection_036](https://cloud.githubusercontent.com/assets/13910561/21529949/2f9b9176-cd63-11e6-826d-c384b3f4b75f.png)

Steps to recreate the issue:
- Create a custom role
- Assign that role to a different user
- After assigning, try to access the respective assigned panels from the different user account



Discussion:

Resolving patch:
diff --git a/app/models/user.py b/app/models/user.py
--- a/app/models/user.py
+++ b/app/models/user.py
@@ -220,8 +220,8 @@ def can_access_panel(self, panel_name):
             return True
 
         custom_sys_roles = UserSystemRole.query.filter_by(user=self)
-        for role in custom_sys_roles:
-            if role.can_access(panel_name):
+        for custom_role in custom_sys_roles:
+            if custom_role.role.can_access(panel_name):
                 return True
 
         return False
diff --git a/app/views/super_admin/__init__.py b/app/views/super_admin/__init__.py
--- a/app/views/super_admin/__init__.py
+++ b/app/views/super_admin/__init__.py
@@ -35,5 +35,5 @@ def check_accessible(panel_name):
     if not AuthManager.is_accessible():
         return redirect(url_for('admin.login_view', next=request.url))
     else:
-        if not current_user.can_access_panel(panel_name) or not current_user.is_staff:
+        if not current_user.can_access_panel(panel_name) and not current_user.is_staff:
             abort(403)


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

Issue:
Links cannot start with "www."
Input links cannot start with "www". It has to be "https://" or "http://".
If it starts with 'www', it takes to page within the open-event site as shown:

https://cloud.githubusercontent.com/assets/20799954/21526383/b8b2059a-cd49-11e6-86e4-3273217455c3.jpg


Discussion:

Resolving patch:
diff --git a/app/helpers/wizard/event.py b/app/helpers/wizard/event.py
--- a/app/helpers/wizard/event.py
+++ b/app/helpers/wizard/event.py
@@ -124,7 +124,10 @@ def save_event_from_json(json, event_id=None):
         abort(400)
 
     event.name = event_data['name']
-    event.event_url = event_data['event_url']
+    if not event_data['event_url'].startswith("http"):
+        event.event_url = "https://" + event_data['event_url']
+    else:
+        event.event_url = event_data['event_url']
     event.location_name = event_data['location_name']
     event.show_map = 1 if event_data['show_map'] else 0
     event.start_time = start_time


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

Issue:
No link for user with custom roles to access their designated tabs.
- [ ] Add link to the first-found accessible tab in dropdown menu
- [x] Show only those tabs to which user has access to ( #2673 )

![selection_039](https://cloud.githubusercontent.com/assets/13910561/21530290/a5febbe8-cd65-11e6-8b04-b66a43599285.png)





Discussion:
We can list all the admin tabs he/she has access to, in the profile dropdown (the one with logout option)  menu itself.
@niranjan94 @SaptakS Your views ?
@shubham-padia no. Let there be a link to /admin/ provided there. Let's keep that drop down simple and clean. 
@niranjan94 Agreed. But a link to `/admin/` will give the user access denied as the user does not have access to all tabs. Alternatively we could give a link to one of the tabs user has access to.
e.g If the user has access to `reports`,`modules` and `sales`, we could give a link to `/admin/reports/` in the dropdown, but then the user would have to click all the other tabs(refer below point) visible to him to make sure which tabs he has access to.

Also, as seen below, even though the user has access to limited no. of admin tabs, he sees all the other tabs as an option. Is this the expected behaviour or should changes be made to this too.

![selection_040](https://cloud.githubusercontent.com/assets/13910561/21541264/fc278002-cdda-11e6-9a77-0c1502e0edbf.png)

Or we could have a basic landing page which shows all the tabs that the user has access to along with some very basic information from `/admin/` for those who do not have access to `/admin/`. 

Let's try to keep the dropdown clean and minimal. 
@niranjan94 Yeah, that sounds good. 
Also about 

> some very basic information from /admin/

What should be included in that particularly, IMO the super admin would have chosen wisely not to show the statistics at `/admin` and we should keep it that way.

Resolving patch:
diff --git a/app/models/user.py b/app/models/user.py
--- a/app/models/user.py
+++ b/app/models/user.py
@@ -17,6 +17,7 @@
 from .system_role import UserSystemRole
 from .user_permissions import UserPermission
 from .users_events_roles import UsersEventsRoles as UER
+from .panel_permissions import PanelPermission
 
 # System-wide
 ADMIN = 'admin'
@@ -213,6 +214,19 @@ def is_sys_role(self, role_id):
         role = UserSystemRole.query.filter_by(user=self, role_id=role_id).first()
         return bool(role)
 
+    def first_access_panel(self):
+        """Check if the user is assigned a Custom Role or not
+        This checks if there is an entry containing the current user in the `user_system_roles` table
+        returns panel name if exists otherwise false
+        """
+        custom_role = UserSystemRole.query.filter_by(user=self).first()
+        if not custom_role:
+            return False
+        perm = PanelPermission.query.filter_by(role_id=custom_role.role_id, can_access=True).first()
+        if not perm:
+            return False
+        return perm.panel_name
+
     def can_access_panel(self, panel_name):
         """Check if user can access an Admin Panel
         """


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

Issue:
Allow only super admin to update roles
fixes #2772 .
The below user has admin access, but is not a super admin, thus the user cannot update roles.

![selection_043](https://cloud.githubusercontent.com/assets/13910561/21562667/a9e17d9a-cea0-11e6-9f0b-107b9c7c2926.png)



Discussion:

Resolving patch:
diff --git a/app/views/super_admin/users.py b/app/views/super_admin/users.py
--- a/app/views/super_admin/users.py
+++ b/app/views/super_admin/users.py
@@ -1,6 +1,8 @@
 from flask import Blueprint
 from flask import request
 from flask import url_for, redirect, flash, render_template
+from flask.ext.login import current_user
+from flask.ext.restplus import abort
 from sqlalchemy_continuum import transaction_class
 
 from app.helpers.data import delete_from_db, DataManager, save_to_db
@@ -59,19 +61,22 @@ def edit_view(user_id):
 
 @sadmin_users.route('/<user_id>/update-roles', methods=('GET', 'POST'))
 def update_roles_view(user_id):
-    user = DataGetter.get_user(user_id)
-    user.is_admin = request.form.get('admin') == 'yes'
-    save_to_db(user)
-
-    custom_sys_roles = DataGetter.get_custom_sys_roles()
-    for role in custom_sys_roles:
-        field = request.form.get('custom_role-{}'.format(role.id))
-        if field:
-            DataManager.get_or_create_user_sys_role(user, role)
-        else:
-            DataManager.delete_user_sys_role(user, role)
-
-    return redirect(url_for('.index_view'))
+    if current_user.is_super_admin:
+        user = DataGetter.get_user(user_id)
+        user.is_admin = request.form.get('admin') == 'yes'
+        save_to_db(user)
+
+        custom_sys_roles = DataGetter.get_custom_sys_roles()
+        for role in custom_sys_roles:
+            field = request.form.get('custom_role-{}'.format(role.id))
+            if field:
+                DataManager.get_or_create_user_sys_role(user, role)
+            else:
+                DataManager.delete_user_sys_role(user, role)
+
+        return redirect(url_for('.index_view'))
+    else:
+        abort(403)
 
 
 @sadmin_users.route('/<user_id>/', methods=('GET', 'POST'))


Test patch: