Repository: fossasia/open-event-server

Issue:
Show Button "View" or "Preview" on Event Dashboard to view public page of event
Please (re)implement a view or preview button on the specific event dashboard to show `/e/ID/`:
- [x] Button "View" if event has been published.
- [x] Button "Preview" if event has not been published (In this case restrict access to event page to organizers, co-organizers, track organizers of event).

![screenshot from 2016-06-18 11 29 03](https://cloud.githubusercontent.com/assets/1583873/16170144/1a7c39ec-3549-11e6-971d-34fca0d142a6.png)



Discussion:

Resolving patch:
diff --git a/open_event/helpers/data_getter.py b/open_event/helpers/data_getter.py
--- a/open_event/helpers/data_getter.py
+++ b/open_event/helpers/data_getter.py
@@ -109,12 +109,12 @@ def get_custom_form_elements(event_id):
         )
 
     @staticmethod
-    def get_sessions_of_user_by_id(session_id):
+    def get_sessions_of_user_by_id(session_id, user=login.current_user):
         """
         :return: Return Sessions object with the current user as a speaker by ID
         """
         try:
-            return Session.query.filter(Session.speakers.any(Speaker.email == login.current_user.email)).filter(
+            return Session.query.filter(Session.speakers.any(Speaker.user_id == user.id)).filter(
                 Session.id == session_id).one()
         except MultipleResultsFound, e:
             return None
diff --git a/open_event/models/user.py b/open_event/models/user.py
--- a/open_event/models/user.py
+++ b/open_event/models/user.py
@@ -1,6 +1,10 @@
 from sqlalchemy import event
 from datetime import datetime
 
+from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
+
+from open_event.models.session import Session
+from open_event.models.speaker import Speaker
 from . import db
 from user_detail import UserDetail
 from .role import Role
@@ -100,6 +104,19 @@ def can_update(self, service_class, event_id):
     def can_delete(self, service_class, event_id):
         return self._has_perm('delete', service_class, event_id)
 
+    def is_speaker_at_session(self, session_id):
+        try:
+            session = Session.query.filter(Session.speakers.any(Speaker.user_id == self.id)).filter(
+                Session.id == session_id).one()
+            if session:
+                return True
+            else:
+                return False
+        except MultipleResultsFound, e:
+            return False
+        except NoResultFound, e:
+            return False
+
     # Flask-Login integration
     def is_authenticated(self):
         return True
diff --git a/open_event/views/public/event_detail.py b/open_event/views/public/event_detail.py
--- a/open_event/views/public/event_detail.py
+++ b/open_event/views/public/event_detail.py
@@ -16,7 +16,11 @@
 def get_published_event_or_abort(event_id):
     event = DataGetter.get_event(event_id=event_id)
     if not event or (event.state != u'Published' and event.state != 'Published'):
-        abort(404)
+        user = login.current_user
+        if not login.current_user.is_authenticated or (not user.is_organizer(event_id) and not
+                                                       user.is_coorganizer(event_id) and not
+                                                       user.is_track_organizer(event_id)):
+            abort(404)
     return event
 
 class EventDetailView(BaseView):


Test patch: