Skip to content

Commit

Permalink
Upgrade to CKAN 2.11 (#30)
Browse files Browse the repository at this point in the history
* Added the 'get_site_statistics' helper function which was removed in CKAN 2.11 while it was a core helper function before.

* Improve home page appearance

* Fix data uploads

* Fix dataset read pages

* Hide unwanted license section from resource list

* Small formatting improvements

* Fix dropdowns

* Formatting improvements to the header

* Fix the navbar across devices.

* Shorted the dashboard menu item name

* Fix the nav bar toggler formatting

* Get dashboard newsfeed working again

* Upgraded the axios library to take into account a security advisory as the version we were using was vulnerability to CSRF attacks: https://github.com/fjelltopp/ckanext-dms/security/dependabot/2.

* Resolved comments raised by Jonathan during PR review: delete unused CSS rule, consolidate the way we import helpers in the plugin, and remove the import core CKAN modules in favor of using the toolkit.

* Fix tests

---------

Co-authored-by: Jonathan S Berry <[email protected]>
  • Loading branch information
ntwalibas and jonathansberry authored Nov 19, 2024
1 parent 21c660d commit e3acd36
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 75 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ jobs:
# The CKAN version tag of the Solr and Postgres containers should match
# the one of the container the tests run on.
# You can switch this base image with a custom image tailored to your project
image: openknowledge/ckan-dev:2.9
image: ckan/ckan-base:2.11-py3.10
options: --user root
services:
solr:
image: ckan/ckan-solr-dev:2.9
image: ckan/ckan-solr:2.11-solr9
postgres:
image: ckan/ckan-postgres-dev:2.9
image: ckan/ckan-postgres-dev:2.11
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand All @@ -29,7 +30,7 @@ jobs:
CKAN_REDIS_URL: redis://redis:6379/1

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install requirements
# Install any extra requirements your extension has here (dev requirements, other extensions etc)
run: |
Expand Down
51 changes: 28 additions & 23 deletions ckanext/dms/assets/css/dms-main.css
Original file line number Diff line number Diff line change
Expand Up @@ -4133,8 +4133,9 @@ select[multiple].input-group-sm > .input-group-btn > .btn {
.navbar {
position: relative;
min-height: 50px;
margin-bottom: 20px;
margin-bottom: 0px;
border: 1px solid transparent;
justify-content: flex-start;
}
@media (min-width: 768px) {
.navbar {
Expand Down Expand Up @@ -4164,7 +4165,6 @@ select[multiple].input-group-sm > .input-group-btn > .btn {
box-shadow: none;
}
.navbar-collapse.collapse {
display: block !important;
height: auto !important;
padding-bottom: 0;
overflow: visible !important;
Expand Down Expand Up @@ -4256,17 +4256,17 @@ select[multiple].input-group-sm > .input-group-btn > .btn {
margin-left: -15px;
}
}
.navbar-toggle {
position: relative;
float: right;
padding: 9px 10px;
margin-right: 15px;
margin-top: 8px;
margin-bottom: 8px;
background-color: transparent;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
.navbar-light .navbar-toggler {
color: #990005;
margin-left: auto;
border-color: transparent;
}
.navbar-light .navbar-toggler:focus,
.navbar-light .navbar-toggler:active {
box-shadow: none;
}
.navbar-light .navbar-toggler > .fa {
font-size: 14px;
}
.navbar-toggle:focus {
outline: 0;
Expand Down Expand Up @@ -7670,7 +7670,7 @@ select[data-module="autocomplete"] {
width: 100%;
height: auto;
}
.simple-input .field .btn-search {
.site-search .btn{
position: absolute;
display: block;
height: 17px;
Expand All @@ -7686,7 +7686,7 @@ select[data-module="autocomplete"] {
-o-transition: color 0.2s ease-in;
transition: color 0.2s ease-in;
}
.simple-input .field .btn-search:hover {
.site-search .btn:hover {
color: #000;
}
.editor textarea {
Expand Down Expand Up @@ -8513,8 +8513,8 @@ td.diff_header {
margin-bottom: 15px;
}
.search-form {
margin-bottom: 20px;
padding-bottom: 25px;
margin-bottom: 15px;
padding-bottom: 35px;
border-bottom: 1px dotted #dddddd;
}
.search-form .search-input {
Expand Down Expand Up @@ -9764,7 +9764,8 @@ h4 small {
float: left;
border-left: 1px solid #660003;
}
.account-masthead .account ul li a {
.account-masthead .account ul li a,
.account-masthead .account ul li button {
display: block;
color: #ecbfc1;
font-size: 13px;
Expand Down Expand Up @@ -9936,10 +9937,13 @@ h4 small {
margin-right: 0;
}
.masthead .debug {
position: absolute;
top: 37px;
left: 10px;
color: rgba(255, 255, 255, 0.5);
bottom: 0px;
right: 0px;
top: initial;
left: initial;
padding: 15px;
background-color: #990005;
border: none;
}
@media (min-width: 992px) {
.masthead .navbar-collapse {
Expand All @@ -9961,8 +9965,9 @@ h4 small {
padding-right: 15px;
}
.masthead .site-search {
display: none;
display: none !important;
}

}
@media (max-width: 767px) {
.masthead .navbar-collapse {
Expand Down
66 changes: 54 additions & 12 deletions ckanext/dms/assets/css/dms.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ p.small {
}

.masthead .navbar-collapse{
padding-top: 12px;
padding-top: 20px;
}

.masthead .navigation .nav-pills > li > a
.masthead .navbar .navbar-nav > li > a
{
font-style: normal;
font-weight: 700;
Expand All @@ -173,13 +173,25 @@ p.small {
background-color: transparent;
padding: 10px 0px;
margin-left: 30px;
}

@media only screen and (max-width: 991px) {
.masthead .navbar .navbar-nav > li > a {
margin-left: 0;
}
}

.masthead .navbar .navbar-nav > li:first-child > a {
padding-top: 0;
}

.masthead .navigation .nav-pills li a:hover,
.masthead .navigation .nav-pills li a:focus,
.masthead .navigation .nav-pills li.active a
.masthead .navbar .navbar-nav > li:last-child > a {
padding-bottom: 0;
}

.masthead .navbar .navbar-nav li:hover a,
.masthead .navbar .navbar-nav li:focus a,
.masthead .navbar .navbar-nav li.active a
{
color: #212121;
background-color: transparent;
Expand All @@ -188,6 +200,23 @@ p.small {

.masthead .site-search {
margin: 5px 0px 5px 30px;
display: inline-block !important;
position: relative;
}

@media (max-width: 991px) {
.masthead .main-navbar ul {
margin-right: 0;
width: 100%;
}

.masthead .site-search {
display: none !important;
}
}

@media (max-width: 769px) {

}

.masthead .site-search input {
Expand All @@ -196,7 +225,7 @@ p.small {
padding: 10px 14px;
}

.btn-search .fa-search {
.masthead .site-search .fa-search {
color: #990005;
font-size: 20px;
position: absolute;
Expand All @@ -215,7 +244,8 @@ p.small {
background: #EDE8E8;
}

.account-masthead .account ul li a {
.account-masthead .account ul li a,
.account-masthead .account ul li button {
font-style: normal;
font-weight: 400;
font-size: 14px;
Expand All @@ -226,7 +256,8 @@ p.small {
line-height: 40px;
}

.account-masthead .account ul li a:hover{
.account-masthead .account ul li a:hover,
.account-masthead .account ul li button:hover{
color: #212121;
background-color: transparent;
}
Expand Down Expand Up @@ -376,8 +407,8 @@ p.small {
border: none;
}

.dataset-resources li a.label,
.dataset-resources li a.label:hover{
.dataset-resources li a.badge,
.dataset-resources li a.badge:hover{
background-color: transparent;
color: #056839;
padding: 0px;
Expand Down Expand Up @@ -515,7 +546,7 @@ a.tag:hover {
text-decoration: underline;
}

@media only screen and (min-width: 769px) {
@media only screen and (min-width: 991px) {
.mobile-menu {
display: none;
}
Expand All @@ -535,7 +566,7 @@ a.tag:hover {
margin-bottom: 30px;
}

.main, .hero {
.main, .homepage .hero {
min-height: 80vh;
padding-top: 32px;
padding-bottom: 64px;
Expand Down Expand Up @@ -692,4 +723,15 @@ a.tag:hover {
background-color: #990005;
}

.module-narrow .nav-item > a, .module-narrow .nav-aside li a{
font-size: 14px;
}

.form-control.form-select{
appearance: auto;
}

.navbar-toggler .fa.fa-bars {
color: #990005 !important;
font-size: 22px;
}
24 changes: 18 additions & 6 deletions ckanext/dms/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ckan.logic as logic
import ckan.model as model
from ckan.plugins import toolkit
from ckan.common import c, request, is_flask_request

# for datetime string conversion
Expand All @@ -11,7 +11,7 @@ def get_dataset_from_id(id):
'model': model, 'ignore_auth': True,
'validate': False, 'use_cache': False
}
package_show_action = logic.get_action('package_show')
package_show_action = toolkit.get_action('package_show')
return package_show_action(context, {'id': id})


Expand Down Expand Up @@ -66,21 +66,33 @@ def _facet_sort_function(facet_name, facet_items):


def get_featured_datasets():
featured_datasets = logic.get_action('package_search')(
featured_datasets = toolkit.get_action('package_search')(
data_dict={'fq': 'tags:featured', 'sort': 'metadata_modified desc', 'rows': 3})['results']
recently_updated = logic.get_action('package_search')(
recently_updated = toolkit.get_action('package_search')(
data_dict={'q': '*:*', 'sort': 'metadata_modified desc', 'rows': 3})['results']
datasets = featured_datasets + recently_updated
return datasets[:3]


def get_user_from_id(userid):
user_show_action = logic.get_action('user_show')
user_show_action = toolkit.get_action('user_show')
user_info = user_show_action({}, {"id": userid})
return user_info['fullname']


def get_all_groups():
return logic.get_action('group_list')(
return toolkit.get_action('group_list')(
data_dict={'sort': 'title asc', 'all_fields': True})


def get_site_statistics() -> dict[str, int]:
'''This function used be a core helper but it was removed in CKAN 2.11.0
We reproduce it here to templates can continue working as usual.
'''
stats = {}
stats['dataset_count'] = toolkit.get_action('package_search')(
{}, {"rows": 1})['count']
stats['group_count'] = len(toolkit.get_action('group_list')({}, {}))
stats['organization_count'] = len(
toolkit.get_action('organization_list')({}, {}))
return stats
20 changes: 9 additions & 11 deletions ckanext/dms/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
from giftless_client import LfsClient
from werkzeug.datastructures import FileStorage as FlaskFileStorage

import ckanext.dms.helpers
from ckanext.dms.helpers import (
get_dataset_from_id, get_facet_items_dict
)
import ckanext.dms.helpers as dms_helpers

log = logging.getLogger(__name__)

Expand All @@ -28,12 +25,13 @@ class DmsPlugin(plugins.SingletonPlugin):
def get_helpers(self):
return {
'max_resource_size': uploader.get_max_resource_size,
'get_dataset_from_id': get_dataset_from_id,
'get_dataset_from_id': dms_helpers.get_dataset_from_id,
'blob_storage_resource_filename': blobstorage_helpers.resource_filename,
'get_facet_items_dict': get_facet_items_dict,
'get_featured_datasets': ckanext.dms.helpers.get_featured_datasets,
'get_user_from_id': ckanext.dms.helpers.get_user_from_id,
'get_all_groups': ckanext.dms.helpers.get_all_groups
'get_facet_items_dict': dms_helpers.get_facet_items_dict,
'get_featured_datasets': dms_helpers.get_featured_datasets,
'get_user_from_id': dms_helpers.get_user_from_id,
'get_all_groups': dms_helpers.get_all_groups,
'get_site_statistics': dms_helpers.get_site_statistics,
}

# IConfigurer
Expand All @@ -53,14 +51,14 @@ def dataset_facets(self, facet_dict, package_type):
return new_fd

# IResourceController
def before_create(self, context, resource):
def before_resource_create(self, context, resource):
if _data_dict_is_resource(resource):
_giftless_upload(context, resource)

_update_resource_last_modified_date(resource)
return resource

def before_update(self, context, current, resource):
def before_resource_update(self, context, current, resource):
if _data_dict_is_resource(resource):
_giftless_upload(context, resource, current=current)
_update_resource_last_modified_date(resource, current=current)
Expand Down
2 changes: 1 addition & 1 deletion ckanext/dms/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"@babel/core": "^7.12.16",
"@babel/preset-env": "^7.12.16",
"@babel/preset-react": "^7.12.13",
"axios": "^0.21.1",
"axios": "^0.28.0",
"babel-loader": "^8.2.2",
"bluebird": "^3.7.2",
"core-js": "^3.9.1",
Expand Down
Loading

0 comments on commit e3acd36

Please sign in to comment.