Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AuScope/ckan-docker into …
Browse files Browse the repository at this point in the history
…dev-sample

# Conflicts:
#	.env.dev
#	.gitignore
#	ckan/src/ckanext-igsn-theme/ckanext/igsn_theme/templates/header.html
  • Loading branch information
NTaherifar committed May 29, 2024
2 parents 1d27946 + 3460ab9 commit 530dc03
Show file tree
Hide file tree
Showing 18 changed files with 273 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ CKAN__LICENSES_GROUP_URL= file:///shared/public/licenses.json
CKAN__DISPLAY_TIMEZONE=Australia/Sydney

# Extensions
# CKAN__PLUGINS="envvars oidc_pkce contact auscope_theme scheming_datasets composite image_view text_view recline_view datastore datapusher spatial_metadata spatial_query doi s3filestore"
CKAN__PLUGINS="envvars oidc_pkce contact igsn_theme scheming_datasets composite image_view text_view recline_view datastore datapusher spatial_metadata spatial_query doi s3filestore"
CKAN__PLUGINS="envvars oidc_pkce auscope_theme contact scheming_datasets composite image_view text_view recline_view datastore datapusher spatial_metadata spatial_query doi s3filestore"
# CKAN__PLUGINS="envvars oidc_pkce igsn_theme contact scheming_datasets composite image_view text_view recline_view datastore datapusher spatial_metadata spatial_query doi s3filestore"

CKAN__HARVEST__MQ__TYPE=redis
CKAN__HARVEST__MQ__HOSTNAME=redis
Expand Down
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ CKAN__LICENSES_GROUP_URL= file:///shared/public/licenses.json
# To switch themes between igsn-theme and auscope-theme,
# comment out one CKAN__PLUGINS line and uncomment the other.
# For Auscope Theme
CKAN__PLUGINS="envvars contact oidc_pkce auscope_theme scheming_datasets composite zip_view image_view text_view recline_view datastore datapusher spatial_metadata spatial_query doi"
CKAN__PLUGINS="envvars oidc_pkce auscope_theme contact scheming_datasets composite zip_view image_view text_view recline_view datastore datapusher spatial_metadata spatial_query doi"

# For IGSN Theme
# CKAN__PLUGINS="envvars contact oidc_pkce igsn_theme scheming_datasets composite zip_view image_view text_view recline_view datastore datapusher spatial_metadata spatial_query doi"
# CKAN__PLUGINS="envvars oidc_pkce igsn_theme contact scheming_datasets composite zip_view image_view text_view recline_view datastore datapusher spatial_metadata spatial_query doi"

CKAN__HARVEST__MQ__TYPE=redis
CKAN__HARVEST__MQ__HOSTNAME=redis
Expand Down
2 changes: 1 addition & 1 deletion ckan/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[bumpversion]
current_version = 0.1.9
current_version = 0.2.1
commit = True
tag = True
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ def package_update(next_action, context, data_dict):
return next_action(context, data_dict)


@tk.chained_action
def package_search(next_action, context, data_dict):
"""
Overwrite package_search so that it will ignore auth so all results are returned
"""
context['ignore_auth'] = True
return next_action(context, data_dict)


@tk.chained_action
def user_create(next_action, context, data_dict):
user = ckan_user_create(context, data_dict)
Expand Down Expand Up @@ -104,4 +113,5 @@ def get_actions():
'organization_list_for_user': organization_list_for_user,
'package_create': package_create,
'package_update': package_update,
'package_search': package_search,
}
17 changes: 13 additions & 4 deletions ckan/src/ckanext-auscope-theme/ckanext/auscope_theme/logic/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def resource_view_create(next_auth, context, data_dict):
elif user_role == 'member' and package.creator_user_id and package.creator_user_id == user.id:
return {'success': True}
# Member is an editing collaborator
elif authz.user_is_collaborator_on_dataset(user.id, package.id, ['editor']):
elif hasattr(user, 'id') and authz.user_is_collaborator_on_dataset(user.id, package.id, ['editor']):
return {'success': True}
else:
return {'success': False, 'msg': 'Unauthorized to view dataset'}
Expand All @@ -94,7 +94,7 @@ def package_update(next_auth, context, data_dict):
elif user_role == 'member' and package.creator_user_id and package.creator_user_id == user.id and package.private:
return {'success': True}
# Member is an editing collaborator and package has not been published
elif authz.user_is_collaborator_on_dataset(user.id, package.id, ['editor']) and package.private:
elif hasattr(user, 'id') and authz.user_is_collaborator_on_dataset(user.id, package.id, ['editor']) and package.private:
return {'success': True}
else:
return {'success': False, 'msg': 'Unauthorized to update dataset'}
Expand Down Expand Up @@ -126,7 +126,7 @@ def resource_update(next_auth, context, data_dict):
elif (user_role == 'member' or user_role=='editor') and package.creator_user_id and package.creator_user_id == user.id:
return {'success': True}
# Member is an editing collaborator and package has not been published
elif authz.user_is_collaborator_on_dataset(user.id, package.id, ['editor']):
elif hasattr(user, 'id') and authz.user_is_collaborator_on_dataset(user.id, package.id, ['editor']):
return {'success': True}

return next_auth(context, data_dict)
Expand Down Expand Up @@ -226,13 +226,21 @@ def package_show(next_auth, context, data_dict):

if package and package.owner_org:
user_role = authz.users_role_for_group_or_org(package.owner_org, user.name)
if user_role == 'member' and package.private and package.creator_user_id != user.id \
if (user_role != 'admin' and user_role != 'editor') and package.private and hasattr(user, 'id') and package.creator_user_id != user.id \
and not authz.user_is_collaborator_on_dataset(user.id, package.id):
return {'success': False, 'msg': 'This dataset is private.'}

return next_auth(context, data_dict)


@tk.chained_auth_function
def package_list(next_auth, context, data_dict):
"""
Let any user bring up a package list
"""
return {'success': True}


def get_auth_functions():
return {
"auscope_theme_get_sum": auscope_theme_get_sum,
Expand All @@ -246,5 +254,6 @@ def get_auth_functions():
"resource_delete": resource_delete,
"resource_view_delete": resource_view_delete,
"package_show": package_show,
"package_list": package_list,
}

Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,42 @@ def after_dataset_show(context, pkg_dict):
pkg_dict['citation'] = citation


#@tk.chained_action
#def after_dataset_search(search_results, search_params):
# """
# Filter returned search results so that members do not see other user's private datasets.
# Editors and admins will still see all datasets.
#
# Note: We now want everyone to see all private datasets, just not access them. Have left
# this method here in case users don't want datasets advertised before release.
#
# """
# result_count = search_results['count']
# if result_count > 0:
# user = tk.g.userobj
# if user:
# filtered_results = search_results['results'].copy()
# for package in search_results['results']:
# if 'owner_org' in package:
# # There's only one org so we could probably get away with only doing this once
# user_role = authz.users_role_for_group_or_org(package['owner_org'], user.name)
# # Filter out any private datasets that the user did not create themselves if they are only a member
# if user_role == 'member' and package['private'] and user.id != package['creator_user_id']:
# filtered_results.remove(package)
# result_count -= 1
# search_results['results'] = filtered_results
# search_results['count'] = result_count
#
# return search_results


@tk.chained_action
def after_dataset_search(search_results, search_params):
def before_dataset_search(search_params):
"""
Filtered returned search results so that members do not see other user's private datasets.
Editors and admins will still see all datasets.
Force private datasets appear in search results
"""
result_count = search_results['count']
if result_count > 0:
user = tk.g.userobj
if user:
filtered_results = search_results['results'].copy()
for package in search_results['results']:
if 'owner_org' in package:
# There's only one org so we could probably get away with only doing this once
user_role = authz.users_role_for_group_or_org(package['owner_org'], user.name)
# Filter out any private datasets that the user did not create themselves if they are only a member
if user_role == 'member' and package['private'] and user.id != package['creator_user_id']:
filtered_results.remove(package)
result_count -= 1
search_results['results'] = filtered_results
search_results['count'] = result_count

return search_results
search_params['include_private'] = 'True'
return search_params


def get_admin_dataset_notification_body(context, pkg_dict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def update_config(self, config_):
def after_dataset_show(self, *args, **kwargs):
return schema.after_dataset_show(*args, **kwargs)

def after_dataset_search(self, *args, **kwargs):
return schema.after_dataset_search(*args, **kwargs)

def after_dataset_update(self, *args, **kwargs):
return schema.after_dataset_update(*args, **kwargs)

def before_dataset_search(self, *args, **kwargs):
return schema.before_dataset_search(*args, **kwargs)

# IAuthFunctions

def get_auth_functions(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% ckan_extends %}

{% block contact_form_fields %}

{{ form.select('subject', label=_('Subject'), id='field-subject',
selected=data.subject, error=errors.subject, classes=['control-medium'],
options=[
{'text': _('General/Other Enquiry'), 'value': 'General/Other Enquiry'},
{'text': _('Large Data Upload'), 'value': 'Large Data Upload'},
{'text': _('Data Updates'), 'value': 'Data Updates'},
{'text': _('Data Access'), 'value': 'Data Access'}
],
is_required=true) }}


{{ form.input('name', label=_('Contact Name'), id='field-name', value=data.name,
error=errors.name, classes=['control-medium'], is_required=true) }}

{{ form.input('email', label=_('Email'), id='field-email', type='email',
value=data.email, error=errors.email, classes=['control-medium'],
is_required=true) }}

{{ form.textarea('content', label=_('Your Request'), id='field-content',
value=data.content, error=errors.content,
placeholder=_('What do you have to tell us?'), is_required=true) }}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{% ckan_extends %}

<a class="btn btn-primary" data-module="modal-contact" data-module-template="" href="" title="">
<i class="fas fa-envelope"></i>
</a>

{% asset 'ckanext-contact/main' %}


{% block header_logo %}
<a class="logo" href="{{ h.url_for('home.index') }}">
<img src="{{ h.url_for_static_or_external('/base/images/AuScope Logo Icon.png') }}" alt="Auscope Logo" title="AuScope Data Repository" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% ckan_extends %}

{% block contact_form_fields %}

{{ form.select('subject', label=_('Subject'), id='field-subject',
selected=data.subject, error=errors.subject, classes=['control-medium'],
options=[
{'text': _('General/Other Enquiry'), 'value': 'General/Other Enquiry'},
{'text': _('Bulk Sample Upload'), 'value': 'Bulk Sample Upload'},
{'text': _('Collection/Samples Updates'), 'value': 'Collection/Samples Updates'},
{'text': _('Collection Creation/Access'), 'value': 'Collection Creation/Access'}
],
is_required=true) }}


{{ form.input('name', label=_('Contact Name'), id='field-name', value=data.name,
error=errors.name, classes=['control-medium'], is_required=true) }}

{{ form.input('email', label=_('Email'), id='field-email', type='email',
value=data.email, error=errors.email, classes=['control-medium'],
is_required=true) }}

{{ form.textarea('content', label=_('Your Request'), id='field-content',
value=data.content, error=errors.content,
placeholder=_('What do you have to tell us?'), is_required=true) }}
{% endblock %}
84 changes: 44 additions & 40 deletions ckan/src/shared/public/base/js/map-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ckan.module('map-module', function ($, _) {

var customIconPath = 'base/vendor/leaflet/images/';
L.Icon.Default.imagePath = this.options.site_url + customIconPath;

this.map = L.map('map-container').setView([-31.9505, 115.8605], 3);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
Expand Down Expand Up @@ -131,28 +131,26 @@ ckan.module('map-module', function ($, _) {
if (!this.rectangleDrawer) {
this.rectangleDrawer = new L.Draw.Rectangle(this.map, this.drawControl.options.draw.rectangle);
}
this.rectangleDrawer.enable();

// this.rectangleDrawer.enable();
var self = this;
this.map.off(L.Draw.Event.CREATED);
this.map.on(L.Draw.Event.CREATED, function (event) {
var layer = event.layer;
var id = L.stamp(layer);
if (self.singleMode) {
self.drawnItems.clearLayers();
self.drawnItemsMap = {};

document.getElementById('bounds-table-body').innerHTML = '';

}
self.drawnItems.addLayer(layer);

if (layer instanceof L.Rectangle) {
var bounds = self.adjustBounds(layer.getBounds());
self.drawnItemsMap[id] = { type: 'rectangle', bbox: bounds.toBBoxString() };
self.updateBoundsTable();

}
});

this.map.off(L.Draw.Event.DELETED);
this.map.on(L.Draw.Event.DELETED, function (event) {
event.layers.eachLayer(function (layer) {
var id = L.stamp(layer);
Expand All @@ -161,6 +159,7 @@ ckan.module('map-module', function ($, _) {
self.updateBoundsTable();
});

this.map.off(L.Draw.Event.EDITED);
this.map.on(L.Draw.Event.EDITED, function (event) {
event.layers.eachLayer(function (layer) {
var id = L.stamp(layer);
Expand Down Expand Up @@ -190,44 +189,49 @@ ckan.module('map-module', function ($, _) {
},
edit: {
featureGroup: this.markerItems,
edit: false,
edit: true,
remove: true
}

});

}
this.map.addControl(this.markerControl);
this.map.addControl(this.markerControl);

var self = this;

this.map.off(L.Draw.Event.CREATED);
this.map.on(L.Draw.Event.CREATED, function (event) {
var layer = event.layer;
if (event.layerType === 'marker') {
// Check if singleMode is enabled
if (self.singleMode) {
self.markerItems.clearLayers();
self.drawnItemsMap = {};
document.getElementById('points-table-body').innerHTML = '';
}
var wrappedLatLng = layer.getLatLng().wrap();
self.markerItems.addLayer(layer);
var id = L.stamp(layer);
self.drawnItemsMap[id] = { type: 'marker', lat: wrappedLatLng.lat, lng: wrappedLatLng.lng };
self.updateMarkerTable();
layer.on('dragend', function (event) {
var marker = event.target;
var position = marker.getLatLng().wrap();
self.drawnItemsMap[id] = { type: 'marker', lat: position.lat, lng: position.lng };
self.updateMarkerTable();
});
}
});

var self = this;
this.map.off('click').on('click', function (e) {
if (self.singleMode) {
self.markerItems.clearLayers();
self.drawnItemsMap = {};
document.getElementById('points-table-body').innerHTML = '';
}
var wrappedLatLng = e.latlng.wrap();
var newMarker = L.marker(e.latlng, { draggable: true });
self.markerItems.addLayer(newMarker);
var id = L.stamp(newMarker);
self.drawnItemsMap[id] = { type: 'marker', lat: wrappedLatLng.lat, lng: wrappedLatLng.lng };
self.updateMarkerTable();
newMarker.on('dragend', function (event) {
var marker = event.target;
var position = marker.getLatLng().wrap();;
self.drawnItemsMap[id] = { type: 'marker', lat: position.lat, lng: position.lng };
this.map.off(L.Draw.Event.DELETED);
this.map.on(L.Draw.Event.DELETED, function (event) {
event.layers.eachLayer(function (layer) {
var id = L.stamp(layer);
if (self.drawnItemsMap[id]) {
delete self.drawnItemsMap[id];
}
});
self.updateMarkerTable();
});
});
this.map.on(L.Draw.Event.DELETED, function (event) {
event.layers.eachLayer(function (layer) {
var id = L.stamp(layer);
if (self.drawnItemsMap[id]) {
delete self.drawnItemsMap[id];
}
});
self.updateMarkerTable();
});
}
},

updateMarkerTable: function () {
Expand Down Expand Up @@ -426,7 +430,7 @@ ckan.module('map-module', function ($, _) {
console.error("Invalid GeoJSON data type:", typeof geoJSONStr);
return;
}


geoJSONObject.features.forEach((feature, index) => {
let id = `feature-${index}`;
Expand Down
Loading

0 comments on commit 530dc03

Please sign in to comment.