Skip to content

Commit

Permalink
Merge branch 'dev-sample' of https://github.com/AuScope/ckan-docker i…
Browse files Browse the repository at this point in the history
…nto batch-validation
  • Loading branch information
NTaherifar committed Aug 2, 2024
2 parents 3e7b8f1 + 623d9f9 commit 061050f
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ this.ckan.module('jstree-view-module', function (jquery) {
var id = this.el.attr('data-id');
var title = this.el.attr('data-title');

var truncatedTitle = self.truncateText(title, 20);
var truncatedTitle = self.truncateText(title, 20);

var data = [{
"text": truncatedTitle,
"id": id,
"state": {
"opened": true
},
"a_attr": { "title": title }

"a_attr": { "title": title}
}];

$('#tree').jstree({
Expand All @@ -43,22 +42,26 @@ this.ckan.module('jstree-view-module', function (jquery) {
}
}
}).on("select_node.jstree", function (e, data) {
if (data.node.children.length === 0) {
if (data.node.children.length === 0 && data.node.type !== "leaf") {
self.fetchChildren(data.node.id);
}
});

$('#tree').on("dblclick", ".jstree-anchor", function (e) {
var href = $(this).attr('href');
console.log(href);
if (href) {
e.preventDefault();
window.location.href = href;
}).on("click", ".jstree-anchor", function (e) {
e.preventDefault(); // Prevent default behavior

var node = $('#tree').jstree(true).get_node(this.id.replace('_anchor', ''));
console.log( node)
if (node && (node.children.length > 0 || node.type === "leaf")) {
console.log("link");
var href = $(this).attr("href");
if (href) {
window.location.href = href; // Explicitly navigate to the link
}
} else {
e.preventDefault(); // Prevent navigation if the node is not clickable
}
});

self.fetchChildren(id);

self.fetchChildren(id);
},

fetchChildren: function (packageId) {
Expand Down Expand Up @@ -90,7 +93,7 @@ this.ckan.module('jstree-view-module', function (jquery) {
var childrenCount;
var checkedChildren = [];
var self = this;

function verifyChild(child) {
$.ajax({
url: '/api/3/action/package_show',
Expand All @@ -113,8 +116,8 @@ this.ckan.module('jstree-view-module', function (jquery) {
if (--childrenCount === 0) {
if (checkedChildren.length > 0) {
checkedChildren.forEach(function (validChild) {
validChild.a_attr = Object.assign({}, validChild.a_attr, { "title": validChild.text });
validChild.text = self.truncateText(validChild.text, 20);
validChild.a_attr = Object.assign({}, validChild.a_attr, { "title": validChild.text, "href": "/dataset/" + validChild.id.toLowerCase(), "class": "clickable-node" });
validChild.text = self.truncateText(validChild.text, 20);
$('#tree').jstree(true).create_node(packageId, validChild, "last");
$('#tree').jstree(true).open_node(packageId);
});
Expand All @@ -132,13 +135,13 @@ this.ckan.module('jstree-view-module', function (jquery) {
verifyChild({
"text": childData.object,
"id": childData.object,
"a_attr": { href: "/dataset/" + childData.object.toLowerCase(), target: "_blank" }
"a_attr": { href: "/dataset/" + childData.object.toLowerCase(), "class": "clickable-node" }
});
});
}
};
},

truncateText: function (text, maxLength) {
if (text.length <= maxLength) {
return text;
Expand All @@ -148,5 +151,4 @@ this.ckan.module('jstree-view-module', function (jquery) {
return startText + '...' + endText;
}
}

});
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2245,7 +2245,7 @@ msgid ""
" performed while public or private datasets belong to this organization."
msgstr ""
"Are you sure you want to delete this Collection? Note*: Deleting cannot be"
" performed while public or private samples belong to this organization."
" performed while public or private samples belong to this collection."

#: ckan/templates/organization/snippets/organization_form.html:43
msgid "Save Organization"
Expand Down
68 changes: 56 additions & 12 deletions ckan/src/ckanext-igsn-theme/ckanext/igsn_theme/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
import pandas as pd
from ckan.common import _
from ckan.plugins.toolkit import h
from ckan.logic import get_action, ValidationError
from ckanext.igsn_theme.logic import (
email_notifications
)
import ckan.authz as authz

@tk.side_effect_free
def igsn_theme_get_sum(context, data_dict):
tk.check_access(
Expand Down Expand Up @@ -302,6 +305,24 @@ def delete_package_relationship(context, pkg_dict):
except Exception as e:
logger.error(f"Failed to delete package relationship: {str(e)}")

@tk.chained_action
def organization_member_create(next_action, context, data_dict):
logger = logging.getLogger(__name__)
member = None
try:
logger.info("Adding member to collection: %s", data_dict)
member = next_action(context, data_dict)
except tk.ValidationError as e:
logger.error(f'Error during member addition: {e.error_dict}')
raise tk.ValidationError(e.error_dict)
except Exception as e:
logger.error(f'Unexpected error during member addition: {e}')
raise tk.ValidationError({'error': ['Unexpected error during member addition. Please contact support.']})
if member is not None:
email_notifications.organization_member_create_notify_email(context, data_dict)
return member


@tk.chained_action
def organization_create(next_action, context, data_dict):
logger = logging.getLogger(__name__)
Expand All @@ -325,23 +346,45 @@ def organization_create(next_action, context, data_dict):
h.flash_error(_('The collection has been created but there was an error sending the notification email. Please check the email configuration.'), 'error')
return collection



@tk.chained_action
def organization_member_create(next_action, context, data_dict):
def organization_delete(next_action, context, data_dict):
logger = logging.getLogger(__name__)
member = None
collection = None
try:
logger.info("Adding member to collection: %s", data_dict)
member = next_action(context, data_dict)
logger.info("Deleting collection: %s", pformat(data_dict))

org_id = tk.get_or_bust(data_dict, 'id')
organization = get_action('organization_show')({}, {'id': org_id})
logger.info(f'Collection deletion result: %s', pformat(organization))
if not organization:
raise tk.ObjectNotFound('Collection was not found.')
members=organization.get('users')
non_admin_users = []
for member in members:
if not member['sysadmin']:
non_admin_users.append(member)

if non_admin_users:
raise tk.ValidationError('The collection has members and cannot be deleted.')

next_action(context, data_dict)
except tk.ValidationError as e:
logger.error(f'Error during member addition: {e.error_dict}')
logger.error(f'Error during collection deletion: {e.error_dict}')
raise tk.ValidationError(e.error_dict)
except Exception as e:
logger.error(f'Unexpected error during member addition: {e}')
raise tk.ValidationError({'error': ['Unexpected error during member addition. Please contact support.']})
if member is not None:
email_notifications.organization_member_create_notify_email(context, data_dict)
return member
logger.error(f'Unexpected error during collection deletion: {e}')
raise tk.ValidationError({'error': ['Unexpected error during collection deletion. Please contact support.']})

try:
email_notifications.organization_delete_notify_email(organization)
tk.h.flash_success(_('The collection has been deleted and the notification email has been sent successfully.'))
except Exception as e:
logger.error(f'Error during email sending: {e}')
tk.h.flash_error(_('The collection has been deleted but there was an error sending the notification email. Please check the email configuration.'), 'error')


def get_actions():
return {
'igsn_theme_get_sum': igsn_theme_get_sum,
Expand All @@ -353,7 +396,8 @@ def get_actions():
'update_package_relationship' : update_package_relationship,
'delete_package_relationship' : delete_package_relationship,
'package_update' : package_update,
'organization_create' :organization_create,
'organization_member_create' :organization_member_create
'organization_member_create' :organization_member_create,
# 'package_search': package_search,
'organization_create' :organization_create,
"organization_delete" : organization_delete,
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,26 @@ def organization_create_notify_email(data_dict):
"""
mail_recipient(recipient_name, recipient_email, subject, body)

def organization_delete_notify_email(organization):
collection_full_name = organization.get('title')
recipient_email = organization.get('contact_email')
recipient_name = organization.get('contact_name')
site_title = config.get('ckan.site_title')
site_url = config.get('ckan.site_url')

subject = f'Collection Deleted: {collection_full_name}'
body = f"""
Dear {recipient_name},
The collection '{collection_full_name}' has been successfully deleted.
Kind Regards,
AuScope Sample Repository
--
Message sent by {site_title} ({site_url})
"""
mail_recipient(recipient_name, recipient_email, subject, body)

def organization_member_create_notify_email(context, data_dict):
"""
Notify the user and the collection contact when a new member is added to the collection.
Expand Down
Loading

0 comments on commit 061050f

Please sign in to comment.