Add --owned_by option to list_resources to debug CZO resources
"""
from django.core.management.base import BaseCommand
+from django.contrib.auth.models import User
from hs_core.models import BaseResource
from hs_core.hydroshare.utils import get_resource_by_shortkey
+from hs_access_control.models import PrivilegeCodes
def has_subfolders(resource):
@@ -80,11 +82,24 @@ class Command(BaseCommand):
help='limit to specific access class (public, discoverable, private)'
)
+ parser.add_argument(
+ '--owned_by',
+ dest='owned_by',
+ help='limit to resources owned by specific user'
+ )
+
parser.add_argument(
'--has_subfolders',
action='store_true', # True for presence, False for absence
dest='has_subfolders', # value is options['has_subfolders']
- help='limit to resources with subfolders',
+ help='limit to resources with subfolders'
+ )
+
+ parser.add_argument(
+ '--brief',
+ action='store_true', # True for presence, False for absence
+ dest='brief', # value is options['brief']
+ help='create brief listing (resource id only)'
)
def measure_filtered_resource(self, resource, options):
@@ -95,13 +110,22 @@ class Command(BaseCommand):
(options['access'] != 'private' or not resource.raccess.discoverable) and \
(not options['has_subfolders'] or has_subfolders(resource)):
storage = resource.get_irods_storage()
+ if options['brief']:
+ print(resource.short_id)
+ else:
if storage.exists(resource.root_path):
measure_resource(resource.short_id)
else:
print("{} does not exist in iRODS".format(resource.short_id))
def handle(self, *args, **options):
- if len(options['resource_ids']) > 0: # an array of resource short_id to check.
+ if options['owned_by'] is not None:
+ owner = User.objects.get(username=options['owned_by'])
+ for r in BaseResource.objects.filter(r2urp__user=owner,
+ r2urp__privilege=PrivilegeCodes.OWNER):
+ self.measure_filtered_resource(r, options)
+
+ elif len(options['resource_ids']) > 0: # an array of resource short_id to check.
for rid in options['resource_ids']:
resource = get_resource_by_shortkey(rid)
self.measure_filtered_resource(resource, options)
