Skip to content

Commit

Permalink
SPC-108 Upgrade to CKAN 2.10 (#46)
Browse files Browse the repository at this point in the history
* SPC-116 Update user identification to use flask login

* SPC-117 Remove need for multiple accounts to share an email

* SPC-116 Improve authn tests

* SPC-116 Update tests to use API tokens instead of keys

* SPC-116 Log substitute users in with flask_login.

* SPC-116 Use the UserWithToken factory instead

* SPC-116 Fix authn tests

* SPC-112 Update IPackageController function names

* SPC-114 Use new activity plugin

* SPC-114 Use new activity stream url structure

* SPC 113  - Fix bootstrap 5 template format (#47)

* Attempt to fix bootstrap 5 compatibility issue for CKAN 2.10

* SPC 113 - Attempt to fix bootstrap 5 compatibility issue for CKAN 2.10

* SPC 113 - Reverted header.html to the one currently used, added navbar-expand.css in assets

* SPC 113 - Clean css file

* SPC 113 - Clean css file

* SPC 113 - Fix

---------

Co-authored-by: toavina <toavina@fjelltopp.org>

* SPC-116 Temporary fix for user identification

* SPC-123 Temporary fix to type cast envvar configs

* SPC-114 Create deleted dataset activities properly.

* SPC 124 - Fix add dataset button bootstrap 5 error (#48)

* SPC 113 - Fix add dataset button bootstrap 5 error

* SPC 113 - css file improvement

---------

Co-authored-by: toavina <toavina@fjelltopp.org>

* SPC-108 Fix github build

* SPC-108 Update IResourceController function names

---------

Co-authored-by: Toavina A <toavinahajaina@gmail.com>
Co-authored-by: toavina <toavina@fjelltopp.org>
Co-authored-by: Tomasz Sabała <tomek@fjelltopp.org>
  • Loading branch information
4 people committed Jul 4, 2023
1 parent c1a0790 commit d5b88dc
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 79 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ 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.7
image: openknowledge/ckan-dev:2.10.0
services:
solr:
image: ckan/ckan-solr-dev:2.9
postgres:
image: ckan/ckan-postgres-dev:2.9
image: ckan/ckan-postgres-dev:2.10
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand Down
123 changes: 115 additions & 8 deletions ckanext/spectrum/assets/css/spectrum.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
border-radius: 3px;
box-shadow: rgba(0, 0, 0, 0.08) 0px 4px 12px;
height: 130px;
transform: scale(0.9);
}

#NavbarHeadingContainer {
Expand Down Expand Up @@ -63,15 +64,30 @@
margin: 5px 0;
}

/* Updates for bootstrap 5 */

/* Menu button */
.masthead .main-navbar ul li a:hover,
.masthead .main-navbar ul li.active a {
background-color: #49338f;
}
.masthead .main-navbar ul li a{
background-color: #5daedf;
}

/* mobile */
@media only screen and (max-width: 768px) {
#NavbarHeadingContainer {
margin-top: 12px;
margin-top: -20px;
}
#NavbarLogo {
margin-top: -90px;
margin-top: -85px;
}
.img-responsive, .media-heading {
display: none;
}


#NavbarHeading1,
#NavbarHeading2 {
font-size: 24px;
Expand All @@ -90,10 +106,10 @@
/* tablet */
@media only screen and (min-width: 768px) {
#NavbarHeadingContainer {
margin-top: 28px;
margin-top: 5px;
}
#NavbarLogo {
margin-top: -55px;
margin-top: -38px;
}
#NavbarHeading1,
#NavbarHeading2 {
Expand All @@ -108,10 +124,10 @@
/* medium devices */
@media only screen and (min-width: 992px) {
#NavbarHeadingContainer {
margin-top: 33px;
margin-top: -3px;
}
#NavbarLogo {
margin-top: -70px;
margin-top: -40px;
}
#NavbarHeading1,
#NavbarHeading2 {
Expand All @@ -123,16 +139,17 @@
.masthead .site-search input {
margin-top: -5px;
}

}


/* desktop */
@media only screen and (min-width: 1200px) {
#NavbarHeadingContainer {
margin-top: 30px;
margin-top: -8px;
}
#NavbarLogo {
margin-top: -80px;
margin-top: -70px;
}
#NavbarHeading1,
#NavbarHeading2 {
Expand All @@ -150,3 +167,93 @@ a.dropdown-item {
padding: 10px;
display: block;
}


@media (max-width: 768px) {
/* Hide the navbar */
.navbar {
flex-wrap: nowrap;
justify-content: flex-start;
}
/* Remove the separator in the dataset page */
.wrapper:before {
content: none;
}
}

.btn-primary {
background-color: #49338f;
}

/* Hide site search */
@media only screen and (max-width: 992px) {
.site-search {
display: none !important;
}
}

/* Search panel */
.homepage .module-search .search-form {
padding: 15px 20px 15px;
}

.img-responsive {
max-width: 100%;
height: auto;
}

.masthead {
margin-bottom: initial;
padding: 10px 0;
color: #ffffff;
background: #5daedf;
}

.account-masthead {
min-height: 30px;
color: #ffffff;
background: #2b83b6;
}

.homepage .module-search .module-content {
border-radius: 3px 3px 0 0;
background-color: #5daedf;
border-bottom: none;
}

.homepage .module-search .tags {
padding: 5px 5px 5px 5px;
background-color: #2b83b6;
border-radius: 0 0 3px 3px;
}

.homepage .module-search {
color: #fff;
padding: 5px;
border: 1px solid #ccc;
}

.search-form {
margin-bottom: 0px;
padding-bottom: 0px;
border-bottom: 1px dotted #ddd;
}

/* Body */
body {
background: #9d9898;
}

/* Footer */
.site-footer {
background: #9d9898;
padding: 20px 0;
}

.site-footer, .site-footer a, .site-footer .attribution p {
color: #ffffff;
}




1 change: 0 additions & 1 deletion ckanext/spectrum/assets/webassets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ spectrum-theme:
filter: cssrewrite
output: ckanext-spectrum/%(version)s-spectrum.css
contents:
- css/spectrum-main.css
- css/spectrum.css
8 changes: 5 additions & 3 deletions ckanext/spectrum/authn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ckan.model as model
import ckan.plugins.toolkit as toolkit
from flask import current_app


def substitute_user(substitute_user_id):
Expand All @@ -15,5 +15,7 @@ def substitute_user(substitute_user_id):
}
}, 400

toolkit.g.user = substitute_user_obj.name
toolkit.g.userobj = substitute_user_obj
# Temporary fix: This should change once CKAN github issue 7581 is resolved
# https://github.com/ckan/ckan/issues/7581
current_app.login_manager._update_request_context_with_user(substitute_user_obj)

42 changes: 20 additions & 22 deletions ckanext/spectrum/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ckanext.blob_storage.helpers as blobstorage_helpers

import ckan.lib.uploader as uploader
import ckan.logic.schema as schema
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
import ckanext.spectrum.actions as spectrum_actions
Expand All @@ -13,16 +12,17 @@
import ckanext.spectrum.upload as spectrum_upload
import ckanext.spectrum.validators as spectrum_validators
from ckan.lib.plugins import DefaultPermissionLabels
from ckan.views import _identify_user_default
from ckanext.spectrum.helpers import (
get_dataset_from_id, get_facet_items_dict
)
from ckan.common import config_declaration

log = logging.getLogger(__name__)


class SpectrumPlugin(plugins.SingletonPlugin, DefaultPermissionLabels):

plugins.implements(plugins.IConfigurable)
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.IFacets, inherit=True)
plugins.implements(plugins.ITemplateHelpers)
Expand All @@ -48,8 +48,15 @@ def update_config(self, config_):
toolkit.add_template_directory(config_, "templates")
toolkit.add_public_directory(config_, "public")
toolkit.add_resource("assets", "spectrum")
if (schema.default_user_schema.__name__ != 'spectrum_user_schema'):
schema.default_user_schema = alter_user_schema(schema.default_user_schema)

# IConfigurable
def configure(self, config):
"""
Temporary fix to CKAN Github issue 7593.
https://github.com/ckan/ckan/issues/7593
This should be removed when the issue is resolved.
"""
config_declaration.normalize(config)

# IFacets
def dataset_facets(self, facet_dict, package_type):
Expand All @@ -60,11 +67,11 @@ 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):
spectrum_upload.handle_giftless_uploads(context, resource)
return resource

def before_update(self, context, current, resource):
def before_resource_update(self, context, current, resource):
spectrum_upload.handle_giftless_uploads(context, resource, current=current)
return resource

Expand Down Expand Up @@ -112,16 +119,18 @@ def get_validators(self):
}

# IPackageContoller
def after_delete(self, context, data_dict):
def after_dataset_delete(self, context, data_dict):
package_data = toolkit.get_action('package_show')(context, data_dict)
if package_data.get('private'):
package_data['state'] = 'deleted'
context['package'].state = 'deleted'
spectrum_upload.add_activity(context, package_data, "changed")

def after_update(self, context, data_dict):
def after_dataset_update(self, context, data_dict):
if data_dict.get('private'):
spectrum_upload.add_activity(context, data_dict, "changed")

def after_create(self, context, data_dict):
def after_dataset_create(self, context, data_dict):
if data_dict.get('private'):
spectrum_upload.add_activity(context, data_dict, "new")

Expand All @@ -136,10 +145,8 @@ def identify(self):
"""

if toolkit.request.path.startswith('/api/') or ('/download/' in toolkit.request.path):
# Private import is only way to set g.userobj using core CKAN.
_identify_user_default()

if not toolkit.g.userobj or not toolkit.g.userobj.sysadmin:
user_is_sysadmin = getattr(toolkit.current_user, 'sysadmin', False)
if not user_is_sysadmin:
return {
"success": False,
"error": {
Expand All @@ -152,12 +159,3 @@ def identify(self):

if substitute_user_id:
return spectrum_authn.substitute_user(substitute_user_id)


def alter_user_schema(default_user_schema):
@schema.validator_args
def spectrum_user_schema(email_is_unique):
spectrum_user_schema = default_user_schema()
spectrum_user_schema['email'].remove(email_is_unique)
return spectrum_user_schema
return spectrum_user_schema
4 changes: 2 additions & 2 deletions ckanext/spectrum/templates/home/layout1.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<div class="main hero">
<div class="container">
<div class="row row1">
<div class="col-md-6 col1">
<div class="col-md-12 col-lg-6 col1">
{% block promoted %}
{% snippet 'home/snippets/promoted.html' %}
{% endblock %}
</div>
<div class="col-md-6 col2">
<div class="col-md-12 col-lg-6 col2">
{% block stats %}
{% snippet 'home/snippets/stats.html' %}
{% endblock %}
Expand Down
5 changes: 3 additions & 2 deletions ckanext/spectrum/templates/package/read_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

{% block content_primary_nav %}
{{ h.build_nav_icon(dataset_type ~ '.read', _('Dataset'), id=pkg.id if is_activity_archive else pkg.name, icon='sitemap') }}
{{ h.build_nav_icon(dataset_type ~ '.activity', _('Activity Stream'), id=pkg.id if is_activity_archive else pkg.name, icon='clock-o') }}
{% endblock %}
{{ h.build_nav_icon('activity.package_activity', _('Activity Stream'), id=pkg.id if is_activity_archive else pkg.name, icon='clock-o') }}
{% endblock content_primary_nav %}


{% block secondary_content %}
<div class="module context-info">
Expand Down
2 changes: 1 addition & 1 deletion ckanext/spectrum/templates/snippets/dataset_selector.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="addDatasetMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<button class="btn btn-primary dropdown-toggle" type="button" id="addDatasetMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-plus-square"></i> {{_('Add Dataset')}}
</button>
<div class="dropdown-menu" aria-labelledby="addDatasetMenuButton">
Expand Down

0 comments on commit d5b88dc

Please sign in to comment.