Repository: fossasia/open-event-server

Issue:
Remove /admin from all URL. Make URLs relative to root instead.
Remove /admin from all URL. Make URLs relative to root instead. As detailed here in #622.



Discussion:

Resolving patch:
diff --git a/open_event/views/admin/admin.py b/open_event/views/admin/admin.py
--- a/open_event/views/admin/admin.py
+++ b/open_event/views/admin/admin.py
@@ -26,8 +26,12 @@
 
 class AdminView(object):
     """Main Admin class View"""
+
     def __init__(self, app_name):
-        self.admin = Admin(name=app_name, template_mode='bootstrap3', index_view=MyHomeView())
+        self.admin = Admin(name=app_name, template_mode='bootstrap3', index_view=MyHomeView(
+            name='Home',
+            url='/'
+        ), static_url_path='/static')
 
     def init(self, app):
         """Init flask admin"""
@@ -35,16 +39,16 @@ def init(self, app):
         self._add_views()
 
     def _add_views(self):
-        self.admin.add_view(EventsView(Event, db.session, name='Events', url='events'))
-        self.admin.add_view(MySessionView(name='MySessions', url='events/mysessions'))
-        self.admin.add_view(EventsSpeakersView(Speaker, db.session, name='Speaker', url='events/<event_id>/speakers'))
-        self.admin.add_view(EventsSponsorsView(Sponsor, db.session, name='Sponsor', url='events/<event_id>/sponsors'))
-        self.admin.add_view(SessionView(Session, db.session, name='Sessions', url='events/<event_id>/sessions'))
-        self.admin.add_view(SchedulerView(name='Scheduler', url='events/<event_id>/scheduler'))
-        self.admin.add_view(RoleView(Role, db.session, name='Role', url='events/<event_id>/roles'))
-        self.admin.add_view(ProfileView(User, db.session, name='Profile', url='profile'))
-        self.admin.add_view(TracksView(Track, db.session, name='Track', url='events/<event_id>/tracks'))
-        self.admin.add_view(InviteView(Invite, db.session, name='Invite', url='events/<event_id>/invite'))
+        self.admin.add_view(EventsView(Event, db.session, name='Events', url='/events'))
+        self.admin.add_view(MySessionView(name='MySessions', url='/events/mysessions'))
+        self.admin.add_view(EventsSpeakersView(Speaker, db.session, name='Speaker', url='/events/<event_id>/speakers'))
+        self.admin.add_view(EventsSponsorsView(Sponsor, db.session, name='Sponsor', url='/events/<event_id>/sponsors'))
+        self.admin.add_view(SessionView(Session, db.session, name='Sessions', url='/events/<event_id>/sessions'))
+        self.admin.add_view(SchedulerView(name='Scheduler', url='/events/<event_id>/scheduler'))
+        self.admin.add_view(RoleView(Role, db.session, name='Role', url='/events/<event_id>/roles'))
+        self.admin.add_view(ProfileView(User, db.session, name='Profile', url='/profile'))
+        self.admin.add_view(TracksView(Track, db.session, name='Track', url='/events/<event_id>/tracks'))
+        self.admin.add_view(InviteView(Invite, db.session, name='Invite', url='/events/<event_id>/invite'))
 
     @staticmethod
     def init_login(app):
@@ -56,4 +60,3 @@ def init_login(app):
         @login_manager.user_loader
         def load_user(user_id):
             return db.session.query(User).get(user_id)
-


Test patch:
diff --git a/tests/auth_helper.py b/tests/auth_helper.py
--- a/tests/auth_helper.py
+++ b/tests/auth_helper.py
@@ -5,7 +5,7 @@
 
 
 def login(app, email, password):
-    return app.post('admin/login/',
+    return app.post('login/',
                     data=dict(
                         email=email,
                         password=password
@@ -13,7 +13,7 @@ def login(app, email, password):
 
 
 def logout(app):
-    return app.get('admin/logout', follow_redirects=True)
+    return app.get('logout', follow_redirects=True)
 
 
 def register(app, email, password):
diff --git a/tests/test_fb_oauth.py b/tests/test_fb_oauth.py
--- a/tests/test_fb_oauth.py
+++ b/tests/test_fb_oauth.py
@@ -33,8 +33,8 @@ def test_user_already_logged_in(self):
             self.app.get(url_for('admin.create_account_after_confirmation_view', hash=data_hash), follow_redirects=True)
             logout(self.app)
             login(self.app, 'email@gmail.com', 'test')
-            self.assertTrue('Create New Event' in self.app.get('/fCallback/?code=dummy_code&state=dummy_state',
-                                                               follow_redirects=True).data)
+            self.assertTrue('Create event' in self.app.get('/fCallback/?code=dummy_code&state=dummy_state',
+                                                           follow_redirects=True).data)
             self.assertEqual(self.app.get('/fCallback/?code=dummy_code&state=dummy_state').status_code, 302)
 
     def test_error_return(self):
@@ -44,7 +44,7 @@ def test_error_return(self):
                 "/fCallback/?code=dummy_code&state=dummy_state&error=access denied").data)
             self.assertTrue("Error encountered" in self.app.get(
                 "/fCallback/?code=dummy_code&state=dummy_state&error=12234").data)
-            self.assertTrue("/admin/login" in self.app.get("/fCallback/?no_code_and_state").data)
+            self.assertTrue("/login" in self.app.get("/fCallback/?no_code_and_state").data)
             self.assertEqual(self.app.get("/fCallback/1234").status_code, 404)
 
     def test_if_user_has_user_details(self):
diff --git a/tests/test_google_oauth.py b/tests/test_google_oauth.py
--- a/tests/test_google_oauth.py
+++ b/tests/test_google_oauth.py
@@ -11,6 +11,7 @@
 from tests.auth_helper import login, logout
 from open_event.helpers.helpers import get_serializer
 
+
 class TestGoogleOauth(OpenEventTestCase):
     def setUp(self):
         self.app = Setup.create_app()
@@ -25,8 +26,8 @@ def test_user_already_logged_in(self):
             self.app.get(url_for('admin.create_account_after_confirmation_view', hash=data_hash), follow_redirects=True)
             logout(self.app)
             login(self.app, 'email@gmail.com', 'test')
-            self.assertTrue('Create New Event' in self.app.get('/gCallback/?state=dummy_state&code=dummy_code',
-                                                               follow_redirects=True).data)
+            self.assertTrue('Create event' in self.app.get('/gCallback/?state=dummy_state&code=dummy_code',
+                                                           follow_redirects=True).data)
             self.assertEqual(self.app.get('/gCallback/?state=dummy_state&code=dummy_code').status_code, 302)
 
     def test_redirect(self):
@@ -49,7 +50,7 @@ def test_error_return(self):
                 "/gCallback/?state=dummy_state&code=dummy_code&error=access denied").data)
             self.assertTrue("Error encountered" in self.app.get(
                 "/gCallback/?state=dummy_state&code=dummy_code&error=12234").data)
-            self.assertTrue("/admin/login" in self.app.get("/gCallback/?no_code_and_state").data)
+            self.assertTrue("/login" in self.app.get("/gCallback/?no_code_and_state").data)
             self.assertEqual(self.app.get("/gCallback/1234").status_code, 404)
 
 
diff --git a/tests/test_login.py b/tests/test_login.py
--- a/tests/test_login.py
+++ b/tests/test_login.py
@@ -12,7 +12,7 @@ def setUp(self):
         self.app = Setup.create_app()
 
     def test_login_page_loads(self):
-        rv = self.app.get('admin/login', follow_redirects=True)
+        rv = self.app.get('login', follow_redirects=True)
         self.assertTrue("Login Form" in rv.data)
 
     def test_correct_login(self):
@@ -20,7 +20,7 @@ def test_correct_login(self):
             register(self.app, u'email@gmail.com', u'test')
             logout(self.app)
             rv = login(self.app, 'email@gmail.com', 'test')
-            self.assertTrue("Create New Event" in rv.data, msg=rv.data)
+            self.assertTrue("Create event" in rv.data, msg=rv.data)
 
     def test_incorrect_login(self):
         with app.test_request_context():
@@ -32,7 +32,7 @@ def test_incorrect_login(self):
     def test_registration(self):
         with app.test_request_context():
             rv = register(self.app, u'email@gmail.com', u'test')
-            self.assertTrue("Create New Event" in rv.data)
+            self.assertTrue("Create event" in rv.data)
 
     def test_logout(self):
         login(self.app, 'email@gmail.com', 'test')
diff --git a/tests/test_my_session.py b/tests/test_my_session.py
--- a/tests/test_my_session.py
+++ b/tests/test_my_session.py
@@ -14,7 +14,7 @@ def test_my_session_list(self):
         with app.test_request_context():
             register(self.app, u'email2@gmail.com', u'test2')
             login(self.app, 'email2@gmail.com', 'test2')
-            rv = self.app.get('admin/events/mysessions/', follow_redirects=True)
+            rv = self.app.get('events/mysessions/', follow_redirects=True)
             logout(self.app)
             self.assertTrue("My Session Proposals" in rv.data, msg=rv.data)