Skip to content

Commit

Permalink
Merge pull request #8006 from ccataalin/bugfix/new-resource-changes
Browse files Browse the repository at this point in the history
[activity plugin] fix server error on changes page for new resource
  • Loading branch information
tino097 committed Feb 26, 2024
2 parents 132b96e + d1684df commit 81db9f6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ul>
{% for change in changes %}
{% snippet "snippets/changes/{}.html".format(
change.type), change=change, pkg_dict=pkg_dict %}
change.type), change=change, pkg_dict=pkg_dict, dataset_type=activity_diff.activities[1].data.package.type %}
<br>
{% endfor %}
</ul>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% set dataset_type = request.view_args.package_type or pkg_dict['type'] or 'dataset' %}
{% set pkg_url = h.url_for(dataset_type ~ '.read', id=change.pkg_id) %}
{% set resource_url = h.url_for(dataset_type ~ '_resource.read', id=change.pkg_id, resource_id = change.resource_id, qualified=True) %}

Expand Down
27 changes: 27 additions & 0 deletions ckanext/activity/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,33 @@ def test_changes(self, app):
assert helpers.body_contains(response, "First")
assert helpers.body_contains(response, "Second")

def test_changes_with_new_resource(self, app):
user = factories.User()
dataset = factories.Dataset(title="First title", user=user)
resource_name = "Image 1"
helpers.call_action(
"package_patch",
id=dataset["id"],
resources=[
{
"url": "http://example.com/image.png",
"format": "png",
"name": resource_name,
}
],
)

activity = activity_model.package_activity_list(
dataset["id"], limit=1, offset=0
)[0]
env = {"REMOTE_USER": user["name"]}
response = app.get(
url_for("activity.package_changes", id=activity.id),
extra_environ=env,
)
assert helpers.body_contains(response, "Added resource")
assert helpers.body_contains(response, resource_name)

@pytest.mark.ckan_config("ckan.activity_list_limit", "3")
def test_invalid_get_params(self, app):

Expand Down

0 comments on commit 81db9f6

Please sign in to comment.