From af24971965829a279e241a993f76194bdbe56a5c Mon Sep 17 00:00:00 2001
From: Thorge Petersen <petersen@rz.uni-kiel.de>
Date: Mon, 24 Jun 2024 15:30:09 +0200
Subject: [PATCH] Removed custom dashboard blueprint and associated view and
 added the dashboard link to the account navigation

---
 CHANGELOG.md                       |  8 ++++++++
 ckanext/odsh/plugin.py             | 12 +-----------
 ckanext/odsh/templates/header.html | 30 +++++++++++++++++++-----------
 ckanext/odsh/views/dashboard.py    | 27 ---------------------------
 4 files changed, 28 insertions(+), 49 deletions(-)
 delete mode 100644 ckanext/odsh/views/dashboard.py

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e4878c25..6f9558a2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## Unreleased
 
+### Added
+
+- Added a "Dashboard" link to the account navigation for quick access to the user dashboard.
+
+### Removed
+
+- Removed custom dashboard blueprint and associated view as these functionalities are covered by the default CKAN implementation.
+
 ### Fixed
 
 - Added a check to ensure `data.id` is present before rendering the delete button in the dataset edit form. This prevents server errors when `data.id` is not available, e.g., for new datasets.
diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py
index 2078ae16..9ca9f663 100644
--- a/ckanext/odsh/plugin.py
+++ b/ckanext/odsh/plugin.py
@@ -21,7 +21,6 @@ import ckanext.odsh.tools as tools
 from ckanext.odsh.views import default
 # from ckanext.odsh.views import package
 from ckanext.odsh.views import user
-from ckanext.odsh.views import dashboard
 from ckanext.odsh.views import harvest
 from ckanext.odsh.views import feed
 # from ckanext.dcat import blueprints as dcat_view
@@ -75,15 +74,6 @@ class OdshPlugin(p.SingletonPlugin, DefaultTranslation, tk.DefaultDatasetForm):
                              view_func=user.index, strict_slashes=False)
         # bp_user.add_url_rule(u'/user/register', view_func=user.register)
 
-        # Dashboard
-        bp_dashboard = dashboard.blueprint
-        bp_dashboard.add_url_rule(
-            u'/dashboard/datasets', view_func=dashboard.datasets)
-        bp_dashboard.add_url_rule(
-            u'/dashboard/organizations', view_func=dashboard.organizations)
-        bp_dashboard.add_url_rule(
-            u'/dashboard/groups', view_func=dashboard.groups)
-
         # Harvest
         bp_harvest = harvest.blueprint
         bp_harvest.add_url_rule(u'/harvest', view_func=harvest.search, strict_slashes=False)
@@ -95,7 +85,7 @@ class OdshPlugin(p.SingletonPlugin, DefaultTranslation, tk.DefaultDatasetForm):
         bp_feed = feed.blueprint
         bp_feed.add_url_rule(u'/feeds/custom.atom', methods=[u'GET'], view_func=feed.custom)
 
-        return [bp_default, bp_user, bp_dashboard, bp_harvest, bp_feed] #bp_package
+        return [bp_default, bp_user, bp_harvest, bp_feed] # bp_package
 
     # IActions
 
diff --git a/ckanext/odsh/templates/header.html b/ckanext/odsh/templates/header.html
index 429f730b..0a957ee0 100644
--- a/ckanext/odsh/templates/header.html
+++ b/ckanext/odsh/templates/header.html
@@ -18,15 +18,15 @@
       </a>
       {% endblock %}
     </hgroup>
-    <h1 class='site-title'> {{ g.site_title }} </h1>
+    <h1 class="site-title"> {{ g.site_title }} </h1>
     <div id="menu-button-and-title" aria-label="{{ _('Toggle menu') }}" data-module="odsh_toggle_menu">
       <span class="fa fa-bars"></span>
-      <h1 class='site-title-mobile'> {{ g.site_title }} </h1>
+      <h1 class="site-title-mobile"> {{ g.site_title }} </h1>
     </div>
   </div>
 
   <div class="container navigation-container">
-    <div class='row navigation-row'>
+    <div class="row navigation-row">
       <nav class="navigation">
         <ul class="nav nav-pills">
           <li class="header-menu-mobile" data-module="odsh_toggle_menu">
@@ -44,10 +44,10 @@
           <li><a href="/infos">{{ _('Infos') }}</a></li>
           {% set clazz='active' if c.action=='login' else ''%}
           {% if h.check_access('package_create') %}
-          <li class='{{clazz}}'>
+          <li class="{{clazz}}">
             <a href="/harvest">{{ _('Harvester') }}</a>
           </li>
-          <li class='{{clazz}}'>
+          <li class="{{clazz}}">
             {% link_for _('Upload'), named_route='dataset.new', class_='text' %}
           </li>
           {% endif %}
@@ -56,9 +56,9 @@
           <li class="dropdown navbar-right {{clazz}}">
             {% set name = c.userobj.fullname if c.userobj.fullname else c.userobj.email%}
             <a href="#" class="dropdown-toggle" data-bs-toggle="dropdown" id="accountMenuButton" aria-expanded="false">
-              <svg class='user-icon' viewBox="0 0 54 54">
-                <circle class='user-icon' cx="27" cy="17" r="7.5" />
-                <path class='user-icon'
+              <svg class="user-icon" viewBox="0 0 54 54">
+                <circle class="user-icon" cx="27" cy="17" r="7.5" />
+                <path class="user-icon"
                   d="M42.5,44.5h-31v-6.4c0-4.7,3.9-8.6,8.6-8.6h13.9c4.7,0,8.6,3.9,8.6,8.6V44.5z" />
               </svg>
               {{name}}</a>
@@ -73,7 +73,7 @@
               {% endif %}
               {% block header_account_profile %}
               <li>
-                <svg class='user-icon-small' viewBox="0 0 54 54">
+                <svg class="user-icon-small" viewBox="0 0 54 54">
                   <circle cx="27" cy="17" r="7.5" />
                   <path d="M42.5,44.5h-31v-6.4c0-4.7,3.9-8.6,8.6-8.6h13.9c4.7,0,8.6,3.9,8.6,8.6V44.5z" />
                 </svg>
@@ -84,10 +84,18 @@
                 </a>
               </li>
               {% endblock %}
+              {% block header_dashboard %}
+                <li>
+                  <a href="{{ h.url_for('dashboard.datasets') }}" aria-label="{{ _('View dashboard') }}" title="{{ _('View dashboard') }}" role="menuitem">
+                    <i class="fa fa-tachometer"></i>
+                    <span class="text">{{ _('Dashboard') }}</span>
+                  </a>
+                </li>
+              {% endblock %}
               {% block header_account_settings_link %}
               <li>
                 <a href="{{ h.url_for('user.edit', id=c.userobj.name) }}" aria-label="{{ _('Edit profile') }}" title="{{ _('Edit profile') }}" role="menuitem">
-                  <i class='fa fa-edit'></i>
+                  <i class="fa fa-edit"></i>
                   <span class="text">
                     {{ _('Edit profile') }}
                   </span>
@@ -97,7 +105,7 @@
               {% block header_account_log_out_link %}
               <li>
                 <a href="{{ h.url_for('user.logout') }}" aria-label="{{ _('Logout') }}" title="{{ _('Logout') }}" role="menuitem">
-                  <i class='fa fa-sign-out'></i>
+                  <i class="fa fa-sign-out"></i>
                   <span class="text">{{ _('Logout') }}</span>
                 </a>
               </li>
diff --git a/ckanext/odsh/views/dashboard.py b/ckanext/odsh/views/dashboard.py
deleted file mode 100644
index 463487c4..00000000
--- a/ckanext/odsh/views/dashboard.py
+++ /dev/null
@@ -1,27 +0,0 @@
-import ckan.authz as authz
-import ckan.lib.helpers as h
-from ckan.common import g, _
-from flask import Blueprint
-import ckan.views.dashboard as dashboard
-import logging
-
-log = logging.getLogger(__name__)
-
-blueprint = Blueprint(u'odsh_dashboard', __name__)
-
-@blueprint.before_request
-def before_request() -> None:
-    is_sysadmin = authz.is_sysadmin(g.user)
-    if not is_sysadmin:
-        h.flash_error(_(u'Not authorized to see this page'))
-        return h.redirect_to(u'user.login')
-    return None
-
-def datasets():
-    return dashboard.datasets()
-
-def organizations():
-    return dashboard.organizations()
-
-def groups():
-    return dashboard.groups()
-- 
GitLab