Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
adds dataset to "resource type" group if an option is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Souhei committed Oct 10, 2024
1 parent 5db4eab commit 1b73ba6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ckanext/zarr/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,20 @@ def _record_dataset_duplication(dataset_id, new_dataset_id, context):
log.exception(e)


def add_dataset_to_resource_type_group(resource_type, dataset_id):
groups_list = toolkit.get_action('group_list')({})
if resource_type in groups_list:
try:
toolkit.get_action('member_create')(
data_dict={
'id': resource_type,
'object': dataset_id,
'object_type': 'package',
'capacity': 'public'
}
)
except Exception as e:
log.error(f"Failed to add dataset {dataset_id} to group {resource_type}")
log.exception(e)
else:
log.warning(f"Group {resource_type} does not exist. Dataset {dataset_id} not added to any group.")
6 changes: 6 additions & 0 deletions ckanext/zarr/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ def after_dataset_delete(self, context, data_dict):
def after_dataset_update(self, context, data_dict):
if data_dict.get('private'):
zarr_upload.add_activity(context, data_dict, "changed")
resource_type = data_dict.get('resource_type')
if resource_type:
zarr_actions.add_dataset_to_resource_type_group(resource_type, data_dict['id'])

def after_dataset_create(self, context, data_dict):
if data_dict.get('private'):
zarr_upload.add_activity(context, data_dict, "new")
resource_type = data_dict.get('resource_type')
if resource_type:
zarr_actions.add_dataset_to_resource_type_group(resource_type, data_dict['id'])

0 comments on commit 1b73ba6

Please sign in to comment.