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

Issue:
Allow make_fe_url to generate url even if frontend_url setting is null
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

open-event-api user registration is not working and I guess this is the most probable reason for it.



Discussion:

Resolving patch:
diff --git a/app/api/helpers/files.py b/app/api/helpers/files.py
--- a/app/api/helpers/files.py
+++ b/app/api/helpers/files.py
@@ -169,5 +169,5 @@ def make_fe_url(settings=None, path=None):
     """
     if settings is None:
         settings = get_settings()
-    fe_host = settings['frontend_url']
-    return fe_host if path is None else (fe_host + path)
+    front_end_host = settings['frontend_url'] if settings['frontend_url'] else ""
+    return front_end_host if path is None else (front_end_host + path)


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

Issue:
ticket-fees API : Type for requests should be singular
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

**Current behavior:**
<!-- Describe how the bug manifests. -->
![image](https://user-images.githubusercontent.com/17252805/28493385-b77e3efa-6f33-11e7-905b-9481c392f5e0.png)
Following error shows up when making requests, with the correct type i.e. `ticket-fee` however requests pass through for type `ticket-fees`
**Expected behavior:**
<!-- Describe what the behavior would be without the bug. -->
Type should be singular i.e. `ticket-fee`



Discussion:

Resolving patch:
diff --git a/app/api/ticket_fees.py b/app/api/ticket_fees.py
--- a/app/api/ticket_fees.py
+++ b/app/api/ticket_fees.py
@@ -18,7 +18,7 @@ class Meta:
         """
         Meta class for image_size Api Schema
         """
-        type_ = 'ticket-fees'
+        type_ = 'ticket-fee'
         self_view = 'v1.ticket_fee_detail'
         self_view_kwargs = {'id': '<id>'}
         inflect = dasherize


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

Issue:
IntegrityError: (psycopg2.IntegrityError) column "role_name" contains null values
https://sentry.eventyay.com/eventyay/api/issues/24/

```
IntegrityError: (psycopg2.IntegrityError) column "role_name" contains null values
 [SQL: 'ALTER TABLE role_invites ALTER COLUMN role_name SET NOT NULL']
(26 additional frame(s) were not displayed)
...
  File "sqlalchemy/engine/base.py", line 1189, in _execute_context
    context)
  File "sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception
    exc_info
  File "sqlalchemy/util/compat.py", line 203, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "sqlalchemy/engine/base.py", line 1182, in _execute_context
    context)
  File "sqlalchemy/engine/default.py", line 470, in do_execute
    cursor.execute(statement, parameters)

IntegrityError: (psycopg2.IntegrityError) column "role_name" contains null values
 [SQL: 'ALTER TABLE role_invites ALTER COLUMN role_name SET NOT NULL']
```

> Occurred while running migrations on a clone of the current production database


Discussion:

Resolving patch:
diff --git a/migrations/versions/4b9a4e5aebe6_.py b/migrations/versions/4b9a4e5aebe6_.py
--- a/migrations/versions/4b9a4e5aebe6_.py
+++ b/migrations/versions/4b9a4e5aebe6_.py
@@ -18,6 +18,7 @@ def upgrade():
     # commands auto generated by Alembic - please adjust! #
     op.add_column('role_invites', sa.Column('role_name', sa.String(), nullable=True))
     op.execute('UPDATE role_invites SET role_name=(SELECT name FROM roles WHERE id = role_invites.role_id)')
+    op.execute('DELETE FROM role_invites WHERE role_name IS NULL')
     op.alter_column('role_invites', 'role_name',
                     existing_type=sa.VARCHAR(),
                     nullable=False)


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

Issue:
IntegrityError: (psycopg2.IntegrityError) column "field_identifier" contains null values
https://sentry.eventyay.com/eventyay/api/issues/25/

```
IntegrityError: (psycopg2.IntegrityError) column "field_identifier" contains null values
 [SQL: 'ALTER TABLE custom_forms ADD COLUMN field_identifier VARCHAR NOT NULL']
(25 additional frame(s) were not displayed)
...
  File "sqlalchemy/engine/base.py", line 1189, in _execute_context
    context)
  File "sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception
    exc_info
  File "sqlalchemy/util/compat.py", line 203, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "sqlalchemy/engine/base.py", line 1182, in _execute_context
    context)
  File "sqlalchemy/engine/default.py", line 470, in do_execute
    cursor.execute(statement, parameters)

IntegrityError: (psycopg2.IntegrityError) column "field_identifier" contains null values
 [SQL: 'ALTER TABLE custom_forms ADD COLUMN field_identifier VARCHAR NOT NULL']
```


Discussion:

Resolving patch:
diff --git a/migrations/versions/aefa134809bf_.py b/migrations/versions/aefa134809bf_.py
--- a/migrations/versions/aefa134809bf_.py
+++ b/migrations/versions/aefa134809bf_.py
@@ -18,6 +18,7 @@
 
 def upgrade():
     # ### commands auto generated by Alembic - please adjust! ###
+    op.execute("DELETE FROM custom_forms")
     op.add_column('custom_forms', sa.Column('field_identifier', sa.String(), nullable=False))
     op.add_column('custom_forms', sa.Column('form', sa.String(), nullable=False))
     op.add_column('custom_forms', sa.Column('is_fixed', sa.Boolean(), nullable=True))


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

Issue:
User missing relationship with email-notification.
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

**Current behavior:**
I created some sample email-notifications manually and got successful response. But, when I try to retrieve them in my app, I get an empty array. Also the call is made only to users and not to email-notifications as I can see in the network tab in dev tools. Please check.


Discussion:

Resolving patch:
diff --git a/app/api/__init__.py b/app/api/__init__.py
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -49,6 +49,7 @@
 api.route(UserRelationship, 'user_event_invoices', '/users/<int:id>/relationships/event-invoices')
 api.route(UserRelationship, 'user_speaker', '/users/<int:id>/relationships/speakers')
 api.route(UserRelationship, 'user_access_codes', '/users/<int:id>/relationships/access-codes')
+api.route(UserRelationship, 'user_email_notifications', '/users/<int:id>/relationships/email-notifications')
 
 # notifications
 api.route(NotificationList, 'notification_list', '/notifications', '/users/<int:id>/notifications')
diff --git a/app/api/users.py b/app/api/users.py
--- a/app/api/users.py
+++ b/app/api/users.py
@@ -92,6 +92,16 @@ class Meta:
         related_view_kwargs={'user_id': '<id>'},
         schema='AccessCodeSchema',
         type_='access-codes')
+    email_notifications = Relationship(
+        attribute='email_notifications',
+        self_view='v1.user_email_notifications',
+        self_view_kwargs={'id': '<id>'},
+        related_view='v1.email_notification_list',
+        related_view_kwargs={'id': '<id>'},
+        schema='EmailNotificationSchema',
+        many=True,
+        type_='email-notification'
+    )
 
 
 class UserList(ResourceList):
diff --git a/app/models/email_notification.py b/app/models/email_notification.py
--- a/app/models/email_notification.py
+++ b/app/models/email_notification.py
@@ -14,7 +14,7 @@ class EmailNotification(db.Model):
     user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='CASCADE'))
     event_id = db.Column(db.Integer, db.ForeignKey('events.id', ondelete='CASCADE'))
     event = db.relationship("Event")
-    user = db.relationship("User")
+    user = db.relationship("User", backref="email_notifications")
 
     def __init__(self,
                  next_event=0,


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

Issue:
Permission missing for all relationship endpoints
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

**Current behavior:**
<!-- Describe how the bug manifests. -->
current relationship endpoints like `events/id/sessions/relationships` do not have a proper relationship

**Expected behavior:**
<!-- Describe what the behavior would be without the bug. -->

**Steps to reproduce:**
<!-- If you are able to illustrate the bug or feature request with an example, please provide steps to reproduce -->

**Related code:**

```
insert any relevant code here else remove this section
```

**Other information:**
<!-- List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to fix, Stack Overflow links, forum links, etc. -->

**System information:** 

<!-- Add information about the system your facing this bug on. If you think this is irrelevant or if it's a UI bug or a feature request, please remove this section -->

```
Your operating system
```

```
output of `python --version`
```



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
@@ -2,6 +2,7 @@
 from marshmallow_jsonapi.flask import Schema, Relationship
 from marshmallow_jsonapi import fields
 
+from app.api.bootstrap import api
 from app.models import db
 from app.models.order import Order
 from app.models.ticket_holder import TicketHolder
@@ -133,7 +134,7 @@ class AttendeeRelationshipOptional(ResourceRelationship):
     """
     Attendee Relationship(Optional)
     """
-    decorators = (jwt_required,)
+    decorators = (api.has_permission('is_user_itself', fetch="user_id", fetch_as="id", model=TicketHolder),)
     schema = AttendeeSchema
     data_layer = {'session': db.session,
                   'model': TicketHolder}
diff --git a/app/api/users.py b/app/api/users.py
--- a/app/api/users.py
+++ b/app/api/users.py
@@ -229,7 +229,7 @@ def before_update_object(self, user, data, view_kwargs):
 
 class UserRelationship(ResourceRelationship):
 
-    decorators = (jwt_required, )
+    decorators = (is_user_itself, )
     schema = UserSchema
     data_layer = {'session': db.session,
                   'model': User}


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

Issue:
Role-invite: remove GET /role-invites
Parent issue #4101.
Related issue: #4155 

Make /role-invites POST only.


Discussion:

Resolving patch:
diff --git a/app/api/role_invites.py b/app/api/role_invites.py
--- a/app/api/role_invites.py
+++ b/app/api/role_invites.py
@@ -97,7 +97,7 @@ def after_create_object(self, role_invite, data, view_kwargs):
                 save_to_db(uer, 'Role Invite accepted')
 
     view_kwargs = True
-    decorators = (api.has_permission('is_admin', methods="GET"),)
+    methods = ['POST']
     schema = RoleInviteSchema
     data_layer = {'session': db.session,
                   'model': RoleInvite,


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

Issue:
User missing relationship with 'notification' in user response.
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

**Current behavior:**
The user response is  missing a relationship with the notification.
```
"relationships": {
            "access-codes": {
                "links": {
                    "related": "/v1/users/110/access-codes",
                    "self": "/v1/users/110/relationships/access-codes"
                }
            },
            "discount-codes": {
                "links": {
                    "related": "/v1/users/110/discount-codes",
                    "self": "/v1/users/110/relationships/discount-codes"
                }
            },
            "speakers": {
                "links": {
                    "related": "/v1/users/110/speakers",
                    "self": "/v1/users/110/relationships/speakers"
                }
            },
            "email-notifications": {
                "links": {
                    "related": "/v1/users/110/email-notifications",
                    "self": "/v1/users/110/relationships/email-notifications"
                }
            }
        }
```
Expected:
The user should have relationship with the notifiation.


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
@@ -56,8 +56,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)
-    notification = Relationship(
-        attribute='notification',
+    notifications = Relationship(
+        attribute='notifications',
         self_view='v1.user_notification',
         self_view_kwargs={'id': '<id>'},
         related_view='v1.notification_list',


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

Issue:
Fix notification link in user response
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

**Current behavior:**
`
 "notifications": {
        "links": {
          "self": "/v1/users/2/relationships/notifications",
          "related": "/v1/notifications?user_id=2"
        }
`

**Expected behavior:**
 `
"notifications": {
                "links": {
                    "self": "/v1/users/1/relationships/notifications",
                    "related": "/v1/users/1/notifications"
                }
`



Discussion:

Resolving patch:
diff --git a/app/api/__init__.py b/app/api/__init__.py
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -60,7 +60,7 @@
 api.route(UserRelationship, 'user_email_notifications', '/users/<int:id>/relationships/email-notifications')
 
 # notifications
-api.route(NotificationList, 'notification_list', '/notifications', '/users/<int:id>/notifications')
+api.route(NotificationList, 'notification_list', '/notifications', '/users/<int:user_id>/notifications')
 api.route(NotificationDetail, 'notification_detail', '/notifications/<int:id>')
 api.route(NotificationRelationship, 'notification_user',
           '/notifications/<int:id>/relationships/user')
diff --git a/app/api/notifications.py b/app/api/notifications.py
--- a/app/api/notifications.py
+++ b/app/api/notifications.py
@@ -69,8 +69,8 @@ def before_create_object(self, data, view_kwargs):
         :param view_kwargs:
         :return:
         """
-        if view_kwargs.get('id') is not None:
-            user = safe_query(self, User, 'id', view_kwargs['id'], 'id')
+        if view_kwargs.get('user_id') is not None:
+            user = safe_query(self, User, 'id', view_kwargs['user_id'], 'user_id')
             data['user_id'] = user.id
 
     view_kwargs = True


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

Issue:
Fix permission for notificationlist resource
Currently, it allows any user to access the resource. I used my local generated token to access notifications at open-event api


Discussion:

Resolving patch:
diff --git a/app/api/notifications.py b/app/api/notifications.py
--- a/app/api/notifications.py
+++ b/app/api/notifications.py
@@ -74,7 +74,7 @@ def before_create_object(self, data, view_kwargs):
             data['user_id'] = user.id
 
     view_kwargs = True
-    decorators = (is_user_itself,)
+    decorators = (api.has_permission('is_user_itself', fetch="user_id", fetch_as="id", model=Notification),)
     schema = NotificationSchema
     data_layer = {'session': db.session,
                   'model': Notification,
@@ -88,8 +88,7 @@ class NotificationDetail(ResourceDetail):
     """
     Notification detail by ID
     """
-    decorators = (api.has_permission('is_user_itself', fetch="user_id", fetch_as="id",
-                  model=Notification),)
+    decorators = (api.has_permission('is_user_itself', fetch="user_id", fetch_as="id", model=Notification),)
     schema = NotificationSchema
     data_layer = {'session': db.session,
                   'model': Notification}
@@ -99,8 +98,7 @@ class NotificationRelationship(ResourceRelationship):
     """
     Notification Relationship
     """
-    decorators = (api.has_permission('is_user_itself', fetch="user_id", fetch_as="id",
-                                     model=Notification),)
+    decorators = (api.has_permission('is_user_itself', fetch="user_id", fetch_as="id", model=Notification),)
     schema = NotificationSchema
     methods = ['GET', 'PATCH']
     data_layer = {'session': db.session,


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

Issue:
notifications: add separate resource list for direct endpoints
parent issue #4101 


Discussion:

Resolving patch:
diff --git a/app/api/__init__.py b/app/api/__init__.py
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -61,7 +61,7 @@
 api.route(UserRelationship, 'user_email_notifications', '/users/<int:id>/relationships/email-notifications')
 
 # notifications
-api.route(NotificationList, 'notification_list', '/notifications', '/users/<int:user_id>/notifications')
+api.route(NotificationList, 'notification_list', '/users/<int:user_id>/notifications')
 api.route(NotificationDetail, 'notification_detail', '/notifications/<int:id>')
 api.route(NotificationRelationship, 'notification_user',
           '/notifications/<int:id>/relationships/user')
diff --git a/app/api/notifications.py b/app/api/notifications.py
--- a/app/api/notifications.py
+++ b/app/api/notifications.py
@@ -27,10 +27,10 @@ class Meta:
         inflect = dasherize
 
     id = fields.Str(dump_only=True)
-    title = fields.Str(allow_none=True)
-    message = fields.Str(allow_none=True)
+    title = fields.Str(allow_none=True, dump_only=True)
+    message = fields.Str(allow_none=True, dump_only=True)
     received_at = fields.DateTime(dump_only=True)
-    accept = fields.Str(allow_none=True)
+    accept = fields.Str(allow_none=True, dump_only=True)
     is_read = fields.Boolean()
     user = Relationship(attribute='user',
                         self_view='v1.notification_user',
@@ -47,9 +47,6 @@ class NotificationList(ResourceList):
     List all the Notification
     """
 
-    def before_post(self, args, kwargs, data):
-        require_relationship(['user'], data)
-
     def query(self, view_kwargs):
         """
         query method for Notifications list
@@ -75,6 +72,7 @@ def before_create_object(self, data, view_kwargs):
 
     view_kwargs = True
     decorators = (api.has_permission('is_user_itself', fetch="user_id", fetch_as="id", model=Notification),)
+    methods = ['GET']
     schema = NotificationSchema
     data_layer = {'session': db.session,
                   'model': Notification,


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -1359,22 +1359,6 @@ def notification_get_list(transaction):
         db.session.commit()
 
 
-@hooks.before("Notifications > Notifications Collection > Create Notificaiton")
-def notification_post(transaction):
-    """
-    POST /users/2/notifications
-    :param transaction:
-    :return:
-    """
-    # Skip until docs for direct endpoints added
-    transaction['skip'] = True
-
-    with stash['app'].app_context():
-        user = UserFactory()
-        db.session.add(user)
-        db.session.commit()
-
-
 @hooks.before("Notifications > Notification Detail > Notification Detail")
 def notification_get_detail(transaction):
     """
Repository: fossasia/open-event-server

Issue:
Email for Role Invite
Parent Issue #4196

Email for role invite to be sent to the user who is invited.


Discussion:

Resolving patch:
diff --git a/app/api/helpers/mail.py b/app/api/helpers/mail.py
--- a/app/api/helpers/mail.py
+++ b/app/api/helpers/mail.py
@@ -7,7 +7,7 @@
 from app.api.helpers.log import record_activity
 from app.api.helpers.system_mails import MAILS
 from app.api.helpers.utilities import string_empty
-from app.models.mail import Mail, USER_CONFIRM, NEW_SESSION, SESSION_ACCEPT_REJECT
+from app.models.mail import Mail, USER_CONFIRM, NEW_SESSION, SESSION_ACCEPT_REJECT, EVENT_ROLE
 
 
 def send_email(to, action, subject, html):
@@ -119,3 +119,21 @@ def send_email_session_accept_reject(email, session, link):
             link=link
         )
     )
+
+
+def send_email_role_invite(email, role_name, event_name, link):
+    """email for role invite"""
+    send_email(
+        to=email,
+        action=EVENT_ROLE,
+        subject=MAILS[EVENT_ROLE]['subject'].format(
+            role=role_name,
+            event=event_name
+        ),
+        html=MAILS[EVENT_ROLE]['message'].format(
+            email=email,
+            role=role_name,
+            event=event_name,
+            link=link
+        )
+    )
diff --git a/app/api/role_invites.py b/app/api/role_invites.py
--- a/app/api/role_invites.py
+++ b/app/api/role_invites.py
@@ -6,6 +6,7 @@
 
 from app.api.helpers.utilities import dasherize
 from app.models import db
+from app.settings import get_settings
 from app.models.event import Event
 from app.models.role_invite import RoleInvite
 from app.models.users_events_role import UsersEventsRoles
@@ -18,6 +19,7 @@
 from app.api.helpers.exceptions import UnprocessableEntity
 from app.api.helpers.exceptions import ForbiddenException
 from app.api.helpers.query import event_query
+from app.api.helpers.mail import send_email_role_invite
 
 
 class RoleInviteSchema(Schema):
@@ -96,6 +98,13 @@ def after_create_object(self, role_invite, data, view_kwargs):
                 uer = UsersEventsRoles(user, event, role)
                 save_to_db(uer, 'Role Invite accepted')
 
+        event = Event.query.filter_by(id=role_invite.event_id).first()
+        frontend_url = get_settings()['frontend_url']
+        link = "{}/events/{}/role-invites/{}" \
+            .format(frontend_url, event.id, role_invite.hash)
+        send_email_role_invite(role_invite.email, role_invite.role_name, event.name, link)
+
+
     view_kwargs = True
     methods = ['POST']
     schema = RoleInviteSchema


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

Issue:
font-color attribute should be dump_only in Tracks API
Reported by: @geekyd 


Discussion:

Resolving patch:
diff --git a/app/api/tracks.py b/app/api/tracks.py
--- a/app/api/tracks.py
+++ b/app/api/tracks.py
@@ -32,12 +32,6 @@ class Meta:
         self_view_kwargs = {'id': '<id>'}
         inflect = dasherize
 
-    @pre_load
-    def remove_font_color(self, data):
-        if data.get('font_color'):
-            del data['font_color']
-        return data
-
     @validates_schema
     def valid_color(self, data):
         if not re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', data['color']):
@@ -47,7 +41,7 @@ def valid_color(self, data):
     name = fields.Str(required=True)
     description = fields.Str(allow_none=True)
     color = fields.Str(required=True)
-    font_color = fields.Str(allow_none=True)
+    font_color = fields.Str(allow_none=True, dump_only=True)
     event = Relationship(attribute='event',
                          self_view='v1.track_event',
                          self_view_kwargs={'id': '<id>'},


Test patch: