{"action":"created","comment":{"url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/comments/56720232","id":56720232,"diff_hunk":"@@ -246,12 +248,39 @@ def delete_file(request, shortkey, f, *args, **kwargs):\n def delete_resource(request, shortkey, *args, **kwargs):\n     res, _, _ = authorize(request, shortkey, needed_permission=ACTION_TO_AUTHORIZE.DELETE_RESOURCE)\n \n+    # downgrade all collections to private if the res being deleted here is the only member resource in these collections\n+    # reverse lookup: find all collections that hold this res being deleted\n+    associated_collection_metadata_obj_list = list(res.collection_set.all())\n+    for collection_metadata_obj in associated_collection_metadata_obj_list:\n+        # if this collection has only one member resource (that is the one being deleted now)\n+        if collection_metadata_obj.resources.all().count() == 1:\n+            # reverse lookup: metadata obj --> resource obj\n+            res_collection = CollectionResource.objects.get(object_id=collection_metadata_obj.object_id)\n+            if res_collection.raccess.public or res_collection.raccess.discoverable:\n+                # downgrade these collections to private\n+                res_collection.raccess.public = False\n+                res_collection.raccess.discoverable = False\n+                res_collection.raccess.save()\n+                # set isPublic metadata AVU accordingly\n+                istorage = IrodsStorage()\n+                istorage.setAVU(res_collection.short_id, \"isPublic\", str(res_collection.raccess.public))\n+\n     try:\n         hydroshare.delete_resource(shortkey)\n     except ValidationError as ex:\n         request.session['validation_error'] = ex.message\n         return HttpResponseRedirect(request.META['HTTP_REFERER'])\n \n+    # the ManyToMany Relationships between this resource and all associated collections have been removed\n+    # that means the metadata of these collection also changed, so we need to update their bags\n+    for collection_metadata_obj in associated_collection_metadata_obj_list:\n+        # tricky issue: the user who deleted this resource may not have permission to access this collection","path":"hs_core/views/__init__.py","position":25,"original_position":39,"commit_id":"6f55bba99442248e992f5fe89c9e812a78d86c6b","original_commit_id":"fd5dc2f0ace25ab109d8a73bf25799620f08c692","user":{"login":"zhiyuli","id":10070599,"avatar_url":"https://avatars.githubusercontent.com/u/10070599?v=3","gravatar_id":"","url":"https://api.github.com/users/zhiyuli","html_url":"https://github.com/zhiyuli","followers_url":"https://api.github.com/users/zhiyuli/followers","following_url":"https://api.github.com/users/zhiyuli/following{/other_user}","gists_url":"https://api.github.com/users/zhiyuli/gists{/gist_id}","starred_url":"https://api.github.com/users/zhiyuli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhiyuli/subscriptions","organizations_url":"https://api.github.com/users/zhiyuli/orgs","repos_url":"https://api.github.com/users/zhiyuli/repos","events_url":"https://api.github.com/users/zhiyuli/events{/privacy}","received_events_url":"https://api.github.com/users/zhiyuli/received_events","type":"User","site_admin":false},"body":"comment on (2): we are using ManyToMany relationship to associate a collection with its contained resources (rather than storing their res_ids in collection), which is recommend by the developer team. Say, collectionA holds resB, that means collectionA object is referencing resB obj. if resB obj gets removed, the tie between colletionA and resB will be gone automatically...so there is no broken link in collection A at all....   ","created_at":"2016-03-18T20:49:36Z","updated_at":"2016-03-18T20:49:36Z","html_url":"https://github.com/hydroshare/hydroshare/pull/1000#discussion_r56720232","pull_request_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000","_links":{"self":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/comments/56720232"},"html":{"href":"https://github.com/hydroshare/hydroshare/pull/1000#discussion_r56720232"},"pull_request":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000"}}},"pull_request":{"url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000","id":60226071,"html_url":"https://github.com/hydroshare/hydroshare/pull/1000","diff_url":"https://github.com/hydroshare/hydroshare/pull/1000.diff","patch_url":"https://github.com/hydroshare/hydroshare/pull/1000.patch","issue_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/1000","number":1000,"state":"open","locked":false,"title":"839 collection resource type phase 1","user":{"login":"zhiyuli","id":10070599,"avatar_url":"https://avatars.githubusercontent.com/u/10070599?v=3","gravatar_id":"","url":"https://api.github.com/users/zhiyuli","html_url":"https://github.com/zhiyuli","followers_url":"https://api.github.com/users/zhiyuli/followers","following_url":"https://api.github.com/users/zhiyuli/following{/other_user}","gists_url":"https://api.github.com/users/zhiyuli/gists{/gist_id}","starred_url":"https://api.github.com/users/zhiyuli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhiyuli/subscriptions","organizations_url":"https://api.github.com/users/zhiyuli/orgs","repos_url":"https://api.github.com/users/zhiyuli/repos","events_url":"https://api.github.com/users/zhiyuli/events{/privacy}","received_events_url":"https://api.github.com/users/zhiyuli/received_events","type":"User","site_admin":false},"body":"just sync'd with latest dev; fixed some conflicts due to recent changes to generic templates\r\n\r\n@alvacouch @danames @SarvaPulla \r\nI think we can start to simplify/refactor the collection. I will write some comments on current code explaining what it is doing. \r\n","created_at":"2016-02-22T19:25:14Z","updated_at":"2016-03-18T20:49:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f6974dd5fb58d095d13cb2a8c9c865fc87e5301c","assignee":{"login":"pkdash","id":2523434,"avatar_url":"https://avatars.githubusercontent.com/u/2523434?v=3","gravatar_id":"","url":"https://api.github.com/users/pkdash","html_url":"https://github.com/pkdash","followers_url":"https://api.github.com/users/pkdash/followers","following_url":"https://api.github.com/users/pkdash/following{/other_user}","gists_url":"https://api.github.com/users/pkdash/gists{/gist_id}","starred_url":"https://api.github.com/users/pkdash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkdash/subscriptions","organizations_url":"https://api.github.com/users/pkdash/orgs","repos_url":"https://api.github.com/users/pkdash/repos","events_url":"https://api.github.com/users/pkdash/events{/privacy}","received_events_url":"https://api.github.com/users/pkdash/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000/commits","review_comments_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000/comments","review_comment_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/1000/comments","statuses_url":"https://api.github.com/repos/hydroshare/hydroshare/statuses/6f55bba99442248e992f5fe89c9e812a78d86c6b","head":{"label":"hydroshare:839-collection-resource-type-phase-1","ref":"839-collection-resource-type-phase-1","sha":"6f55bba99442248e992f5fe89c9e812a78d86c6b","user":{"login":"hydroshare","id":3444493,"avatar_url":"https://avatars.githubusercontent.com/u/3444493?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroshare","html_url":"https://github.com/hydroshare","followers_url":"https://api.github.com/users/hydroshare/followers","following_url":"https://api.github.com/users/hydroshare/following{/other_user}","gists_url":"https://api.github.com/users/hydroshare/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroshare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroshare/subscriptions","organizations_url":"https://api.github.com/users/hydroshare/orgs","repos_url":"https://api.github.com/users/hydroshare/repos","events_url":"https://api.github.com/users/hydroshare/events{/privacy}","received_events_url":"https://api.github.com/users/hydroshare/received_events","type":"Organization","site_admin":false},"repo":{"id":24703136,"name":"hydroshare","full_name":"hydroshare/hydroshare","owner":{"login":"hydroshare","id":3444493,"avatar_url":"https://avatars.githubusercontent.com/u/3444493?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroshare","html_url":"https://github.com/hydroshare","followers_url":"https://api.github.com/users/hydroshare/followers","following_url":"https://api.github.com/users/hydroshare/following{/other_user}","gists_url":"https://api.github.com/users/hydroshare/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroshare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroshare/subscriptions","organizations_url":"https://api.github.com/users/hydroshare/orgs","repos_url":"https://api.github.com/users/hydroshare/repos","events_url":"https://api.github.com/users/hydroshare/events{/privacy}","received_events_url":"https://api.github.com/users/hydroshare/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hydroshare/hydroshare","description":"HydroShare is a collaborative website being developed for better access to data and models in the hydrologic sciences. ","fork":false,"url":"https://api.github.com/repos/hydroshare/hydroshare","forks_url":"https://api.github.com/repos/hydroshare/hydroshare/forks","keys_url":"https://api.github.com/repos/hydroshare/hydroshare/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hydroshare/hydroshare/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hydroshare/hydroshare/teams","hooks_url":"https://api.github.com/repos/hydroshare/hydroshare/hooks","issue_events_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/events{/number}","events_url":"https://api.github.com/repos/hydroshare/hydroshare/events","assignees_url":"https://api.github.com/repos/hydroshare/hydroshare/assignees{/user}","branches_url":"https://api.github.com/repos/hydroshare/hydroshare/branches{/branch}","tags_url":"https://api.github.com/repos/hydroshare/hydroshare/tags","blobs_url":"https://api.github.com/repos/hydroshare/hydroshare/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hydroshare/hydroshare/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hydroshare/hydroshare/git/refs{/sha}","trees_url":"https://api.github.com/repos/hydroshare/hydroshare/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hydroshare/hydroshare/statuses/{sha}","languages_url":"https://api.github.com/repos/hydroshare/hydroshare/languages","stargazers_url":"https://api.github.com/repos/hydroshare/hydroshare/stargazers","contributors_url":"https://api.github.com/repos/hydroshare/hydroshare/contributors","subscribers_url":"https://api.github.com/repos/hydroshare/hydroshare/subscribers","subscription_url":"https://api.github.com/repos/hydroshare/hydroshare/subscription","commits_url":"https://api.github.com/repos/hydroshare/hydroshare/commits{/sha}","git_commits_url":"https://api.github.com/repos/hydroshare/hydroshare/git/commits{/sha}","comments_url":"https://api.github.com/repos/hydroshare/hydroshare/comments{/number}","issue_comment_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/comments{/number}","contents_url":"https://api.github.com/repos/hydroshare/hydroshare/contents/{+path}","compare_url":"https://api.github.com/repos/hydroshare/hydroshare/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hydroshare/hydroshare/merges","archive_url":"https://api.github.com/repos/hydroshare/hydroshare/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hydroshare/hydroshare/downloads","issues_url":"https://api.github.com/repos/hydroshare/hydroshare/issues{/number}","pulls_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls{/number}","milestones_url":"https://api.github.com/repos/hydroshare/hydroshare/milestones{/number}","notifications_url":"https://api.github.com/repos/hydroshare/hydroshare/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hydroshare/hydroshare/labels{/name}","releases_url":"https://api.github.com/repos/hydroshare/hydroshare/releases{/id}","deployments_url":"https://api.github.com/repos/hydroshare/hydroshare/deployments","created_at":"2014-10-02T02:19:41Z","updated_at":"2016-03-01T10:06:38Z","pushed_at":"2016-03-18T19:39:21Z","git_url":"git://github.com/hydroshare/hydroshare.git","ssh_url":"git@github.com:hydroshare/hydroshare.git","clone_url":"https://github.com/hydroshare/hydroshare.git","svn_url":"https://github.com/hydroshare/hydroshare","homepage":"https://www.hydroshare.org","size":84488,"stargazers_count":13,"watchers_count":13,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":228,"forks":2,"open_issues":228,"watchers":13,"default_branch":"develop"}},"base":{"label":"hydroshare:develop","ref":"develop","sha":"b4a28e761e6d3872bc4768df76642880a5bbe918","user":{"login":"hydroshare","id":3444493,"avatar_url":"https://avatars.githubusercontent.com/u/3444493?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroshare","html_url":"https://github.com/hydroshare","followers_url":"https://api.github.com/users/hydroshare/followers","following_url":"https://api.github.com/users/hydroshare/following{/other_user}","gists_url":"https://api.github.com/users/hydroshare/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroshare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroshare/subscriptions","organizations_url":"https://api.github.com/users/hydroshare/orgs","repos_url":"https://api.github.com/users/hydroshare/repos","events_url":"https://api.github.com/users/hydroshare/events{/privacy}","received_events_url":"https://api.github.com/users/hydroshare/received_events","type":"Organization","site_admin":false},"repo":{"id":24703136,"name":"hydroshare","full_name":"hydroshare/hydroshare","owner":{"login":"hydroshare","id":3444493,"avatar_url":"https://avatars.githubusercontent.com/u/3444493?v=3","gravatar_id":"","url":"https://api.github.com/users/hydroshare","html_url":"https://github.com/hydroshare","followers_url":"https://api.github.com/users/hydroshare/followers","following_url":"https://api.github.com/users/hydroshare/following{/other_user}","gists_url":"https://api.github.com/users/hydroshare/gists{/gist_id}","starred_url":"https://api.github.com/users/hydroshare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hydroshare/subscriptions","organizations_url":"https://api.github.com/users/hydroshare/orgs","repos_url":"https://api.github.com/users/hydroshare/repos","events_url":"https://api.github.com/users/hydroshare/events{/privacy}","received_events_url":"https://api.github.com/users/hydroshare/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hydroshare/hydroshare","description":"HydroShare is a collaborative website being developed for better access to data and models in the hydrologic sciences. ","fork":false,"url":"https://api.github.com/repos/hydroshare/hydroshare","forks_url":"https://api.github.com/repos/hydroshare/hydroshare/forks","keys_url":"https://api.github.com/repos/hydroshare/hydroshare/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hydroshare/hydroshare/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hydroshare/hydroshare/teams","hooks_url":"https://api.github.com/repos/hydroshare/hydroshare/hooks","issue_events_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/events{/number}","events_url":"https://api.github.com/repos/hydroshare/hydroshare/events","assignees_url":"https://api.github.com/repos/hydroshare/hydroshare/assignees{/user}","branches_url":"https://api.github.com/repos/hydroshare/hydroshare/branches{/branch}","tags_url":"https://api.github.com/repos/hydroshare/hydroshare/tags","blobs_url":"https://api.github.com/repos/hydroshare/hydroshare/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hydroshare/hydroshare/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hydroshare/hydroshare/git/refs{/sha}","trees_url":"https://api.github.com/repos/hydroshare/hydroshare/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hydroshare/hydroshare/statuses/{sha}","languages_url":"https://api.github.com/repos/hydroshare/hydroshare/languages","stargazers_url":"https://api.github.com/repos/hydroshare/hydroshare/stargazers","contributors_url":"https://api.github.com/repos/hydroshare/hydroshare/contributors","subscribers_url":"https://api.github.com/repos/hydroshare/hydroshare/subscribers","subscription_url":"https://api.github.com/repos/hydroshare/hydroshare/subscription","commits_url":"https://api.github.com/repos/hydroshare/hydroshare/commits{/sha}","git_commits_url":"https://api.github.com/repos/hydroshare/hydroshare/git/commits{/sha}","comments_url":"https://api.github.com/repos/hydroshare/hydroshare/comments{/number}","issue_comment_url":"https://api.github.com/repos/hydroshare/hydroshare/issues/comments{/number}","contents_url":"https://api.github.com/repos/hydroshare/hydroshare/contents/{+path}","compare_url":"https://api.github.com/repos/hydroshare/hydroshare/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hydroshare/hydroshare/merges","archive_url":"https://api.github.com/repos/hydroshare/hydroshare/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hydroshare/hydroshare/downloads","issues_url":"https://api.github.com/repos/hydroshare/hydroshare/issues{/number}","pulls_url":"https://api.github.com/repos/hydroshare/hydroshare/pulls{/number}","milestones_url":"https://api.github.com/repos/hydroshare/hydroshare/milestones{/number}","notifications_url":"https://api.github.com/repos/hydroshare/hydroshare/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hydroshare/hydroshare/labels{/name}","releases_url":"https://api.github.com/repos/hydroshare/hydroshare/releases{/id}","deployments_url":"https://api.github.com/repos/hydroshare/hydroshare/deployments","created_at":"2014-10-02T02:19:41Z","updated_at":"2016-03-01T10:06:38Z","pushed_at":"2016-03-18T19:39:21Z","git_url":"git://github.com/hydroshare/hydroshare.git","ssh_url":"git@github.com:hydroshare/hydroshare.git","clone_url":"https://github.com/hydroshare/hydroshare.git","svn_url":"https://github.com/hydroshare/hydroshare","homepage":"https://www.hydroshare.org","size":84488,"stargazers_count":13,"watchers_count":13,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":228,"forks":2,"open_issues":228,"watchers":13,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000"},"html":{"href":"https://github.com/hydroshare/hydroshare/pull/1000"},"issue":{"href":"https://api.github.com/repos/hydroshare/hydroshare/issues/1000"},"comments":{"href":"https://api.github.com/repos/hydroshare/hydroshare/issues/1000/comments"},"review_comments":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000/comments"},"review_comment":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hydroshare/hydroshare/pulls/1000/commits"},"statuses":{"href":"https://api.github.com/repos/hydroshare/hydroshare/statuses/6f55bba99442248e992f5fe89c9e812a78d86c6b"}}}}