Repository: hedyorg/hedy

Issue:
[UI idea] Add classes overview to admin page
**Idea incl level**
I would be nice to have a classes overview on the admin page. As we already support an user overview and overall statistics this would be nice additional insight in usage. As this is highly related to #1741 I think it can be best solved in one go.


Discussion:

Resolving patch:
diff --git a/app.py b/app.py
--- a/app.py
+++ b/app.py
@@ -1144,11 +1144,6 @@ def main_page(page):
         else:
             return utils.error_page(error=403, ui_message='not_teacher')
 
-    if page == 'stats':
-        if not is_admin(current_user()):
-            return utils.error_page(error=403, ui_message='unauthorized')
-        return render_template('admin-stats.html')
-
     requested_page = hedyweb.PageTranslations(page)
     if not requested_page.exists():
         abort(404)
@@ -1190,7 +1185,15 @@ def explore():
 @app.route('/admin', methods=['GET'])
 def get_admin_page():
     if not utils.is_testing_request(request) and not is_admin(current_user()):
-        return 'unauthorized', 403
+        return utils.error_page(error=403, ui_message='unauthorized')
+    return render_template('admin.html', page_title=hedyweb.get_page_title('admin'))
+
+
+@app.route('/admin/users', methods=['GET'])
+@requires_login
+def get_admin_users_page(user):
+    if not is_admin(user):
+        return utils.error_page(error=403, ui_message='unauthorized')
 
     category = request.args.get('filter', default=None, type=str)
     category = None if category == "null" else category
@@ -1236,11 +1239,29 @@ def get_admin_page():
         user['index'] = counter
         counter = counter + 1
 
-    return render_template('admin.html', users=userdata, page_title=hedyweb.get_page_title('admin'),
+    return render_template('admin-users.html', users=userdata, page_title=hedyweb.get_page_title('admin'),
                            filter=category, start_date=start_date, end_date=end_date, email_filter=substring,
                            program_count=DATABASE.all_programs_count(), user_count=DATABASE.all_users_count())
 
 
+@app.route('/admin/classes', methods=['GET'])
+@requires_login
+def get_admin_classes_page(user):
+    if not is_admin(user):
+        return utils.error_page(error=403, ui_message='unauthorized')
+
+    classes = DATABASE.all_classes()
+    return render_template('admin-classes.html', classes=classes, page_title=hedyweb.get_page_title('admin'))
+
+
+@app.route('/admin/stats', methods=['GET'])
+@requires_login
+def get_admin_stats_page(user):
+    if not is_admin(user):
+        return utils.error_page(error=403, ui_message='unauthorized')
+    return render_template('admin-stats.html', page_title=hedyweb.get_page_title('admin'))
+
+
 @app.route('/change_language', methods=['POST'])
 def change_language():
     body = request.json
diff --git a/website/database.py b/website/database.py
--- a/website/database.py
+++ b/website/database.py
@@ -314,6 +314,9 @@ def delete_class(self, Class):
     def resolve_class_link(self, link_id):
         return CLASSES.get({'link': link_id})
 
+    def all_classes(self):
+        return CLASSES.scan()
+
     def remove_customizations_class(self, class_id, level):
         CUSTOMIZATIONS.delete({'id': class_id, 'level': level})
 


Test patch: