Repository: fossasia/open-event-server

Issue:
relationship with organiser is not present with event details
**Describe the bug**
Event details should have a relationship with organizer
![image](https://user-images.githubusercontent.com/16715499/41516113-712bfa68-72d0-11e8-9cb4-7c59b30f0021.png)


**To Reproduce**
Steps to reproduce the behavior:
1. Make any event detail call `https://open-event-api-dev.herokuapp.com/v1/events/76`
2. Look at relationships

**Expected behavior**
It should be present



Discussion:
current relationship response
```
relationships": {
            "social-links": {
                "links": {
                    "self": "/v1/events/76/relationships/social-links",
                    "related": "/v1/events/76/social-links"
                }
            },
            "faqs": {
                "links": {
                    "self": "/v1/events/76/relationships/faqs",
                    "related": "/v1/events/76/faqs"
                }
            },
            "event-sub-topic": {
                "links": {
                    "self": "/v1/events/76/relationships/event-sub-topic",
                    "related": "/v1/events/76/event-sub-topic"
                }
            },
            "feedbacks": {
                "links": {
                    "self": "/v1/events/76/relationships/feedbacks",
                    "related": "/v1/events/76/feedbacks"
                }
            },
            "tickets": {
                "links": {
                    "self": "/v1/events/76/relationships/tickets",
                    "related": "/v1/events/76/tickets"
                }
            },
            "speakers-call": {
                "links": {
                    "self": "/v1/events/76/relationships/speakers-call",
                    "related": "/v1/events/76/speakers-call"
                }
            },
            "tax": {
                "links": {
                    "self": "/v1/events/76/relationships/tax",
                    "related": "/v1/events/76/tax"
                }
            },
            "custom-forms": {
                "links": {
                    "self": "/v1/events/76/relationships/custom-forms",
                    "related": "/v1/events/76/custom-forms"
                }
            },
            "faq-types": {
                "links": {
                    "self": "/v1/events/76/relationships/faq-types",
                    "related": "/v1/events/76/faq-types"
                }
            },
            "sponsors": {
                "links": {
                    "self": "/v1/events/76/relationships/sponsors",
                    "related": "/v1/events/76/sponsors"
                }
            },
            "session-types": {
                "links": {
                    "self": "/v1/events/76/relationships/session-types",
                    "related": "/v1/events/76/session-types"
                }
            },
            "event-topic": {
                "links": {
                    "self": "/v1/events/76/relationships/event-topic",
                    "related": "/v1/events/76/event-topic"
                }
            },
            "sessions": {
                "links": {
                    "self": "/v1/events/76/relationships/sessions",
                    "related": "/v1/events/76/sessions"
                }
            },
            "event-type": {
                "links": {
                    "self": "/v1/events/76/relationships/event-type",
                    "related": "/v1/events/76/event-type"
                }
            },
            "microlocations": {
                "links": {
                    "self": "/v1/events/76/relationships/microlocations",
                    "related": "/v1/events/76/microlocations"
                }
            },
            "speakers": {
                "links": {
                    "self": "/v1/events/76/relationships/speakers",
                    "related": "/v1/events/76/speakers"
                }
            },
            "ticket-tags": {
                "links": {
                    "self": "/v1/events/76/relationships/ticket-tags",
                    "related": "/v1/events/76/ticket-tags"
                }
            },
            "tracks": {
                "links": {
                    "self": "/v1/events/76/relationships/tracks",
                    "related": "/v1/events/76/tracks"
                }
            },
            "event-copyright": {
                "links": {
                    "self": "/v1/events/76/relationships/event-copyright",
                    "related": "/v1/events/76/event-copyright"
                }
            }
```
@srv-twry please look into it, its a blocker on open event android side
@mayank8318 @schedutron @bhaveshAn Can one of you look into this ? I am slightly busy. Thanks.

Resolving patch:
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -59,7 +59,8 @@ def before_get(self, args, kwargs):
         :param kwargs:
         :return:
         """
-        if 'Authorization' in request.headers and (has_access('is_admin') or kwargs.get('user_id')):
+        if 'Authorization' in request.headers and (has_access('is_admin') or has_access('is_user_itself',
+                                                                                        user_id=kwargs.get('user_id'))):
             self.schema = EventSchema
         else:
             self.schema = EventSchemaPublic
@@ -80,7 +81,9 @@ def query(self, view_kwargs):
 
         if view_kwargs.get('user_id') and 'GET' in request.method:
             if not has_access('is_user_itself', user_id=int(view_kwargs['user_id'])):
-                raise ForbiddenException({'source': ''}, 'Access Forbidden')
+                # other registered users can see the published events of the user.
+                query_ = query_.filter_by(state='published')
+
             user = safe_query(db, User, 'id', view_kwargs['user_id'], 'user_id')
             query_ = query_.join(Event.roles).filter_by(user_id=user.id).join(UsersEventsRoles.role). \
                 filter(Role.name != ATTENDEE)
@@ -116,9 +119,9 @@ def before_post(self, args, kwargs, data=None):
         :return:
         """
         is_verified = User.query.filter_by(id=kwargs['user_id']).first().is_verified
-        if (data.get('state', None) == 'published' and not is_verified):
+        if data.get('state', None) == 'published' and not is_verified:
             raise ForbiddenException({'source': ''},
-                                      "Only verified accounts can publish events")
+                                     "Only verified accounts can publish events")
         if data.get('state', None) == 'published' and not data.get('location_name', None):
             raise ConflictException({'pointer': '/data/attributes/location-name'},
                                     "Location is required to publish the event")
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
@@ -254,6 +254,20 @@ def validate_timezone(self, data, original_data):
                                 schema='CustomFormSchema',
                                 many=True,
                                 type_='custom-form')
+    organizers = Relationship(attribute='organizers',
+                              self_view='v1.event_organizers',
+                              self_view_kwargs={'id': '<id>'},
+                              related_view='v1.user_list',
+                              schema='UserSchemaPublic',
+                              type_='user',
+                              many=True)
+    coorganizers = Relationship(attribute='coorganizers',
+                                self_view='v1.event_coorganizers',
+                                self_view_kwargs={'id': '<id>'},
+                                related_view='v1.user_list',
+                                schema='UserSchemaPublic',
+                                type_='user',
+                                many=True)
 
 
 class EventSchema(EventSchemaPublic):
@@ -279,20 +293,6 @@ class Meta:
                                   related_view_kwargs={'event_id': '<id>'},
                                   schema='DiscountCodeSchema',
                                   type_='discount-code')
-    organizers = Relationship(attribute='organizers',
-                              self_view='v1.event_organizers',
-                              self_view_kwargs={'id': '<id>'},
-                              related_view='v1.user_list',
-                              schema='UserSchemaPublic',
-                              type_='user',
-                              many=True)
-    coorganizers = Relationship(attribute='coorganizers',
-                                self_view='v1.event_coorganizers',
-                                self_view_kwargs={'id': '<id>'},
-                                related_view='v1.user_list',
-                                schema='UserSchemaPublic',
-                                type_='user',
-                                many=True)
     track_organizers = Relationship(attribute='track_organizers',
                                     self_view='v1.event_track_organizers',
                                     self_view_kwargs={'id': '<id>'},


Test patch: