@@ -60,14 +60,27 @@ def list_my_collections(
6060 .scalars ()
6161 .all ()
6262 )
63- # filter score sets and experiments based on user permissions
63+
6464 for item in collection_bundle [role .value ]:
65+ # filter score sets and experiments based on user permissions
6566 item .score_sets = [
6667 score_set for score_set in item .score_sets if has_permission (user_data , score_set , Action .READ )
6768 ]
6869 item .experiments = [
6970 experiment for experiment in item .experiments if has_permission (user_data , experiment , Action .READ )
7071 ]
72+ # unless user is admin of this collection, filter users to only admins
73+ # the rationale is that all collection contributors should be able to see admins
74+ # to know who to contact, but only collection admins should be able to see viewers and editors
75+ if role in (ContributionRole .viewer , ContributionRole .editor ):
76+ admins = []
77+ for user_assoc in item .user_associations :
78+ if user_assoc .contribution_role == ContributionRole .admin :
79+ admin = user_assoc .user
80+ # role must be set in order to assign users to collection
81+ setattr (admin , "role" , ContributionRole .admin )
82+ admins .append (admin )
83+ item .users = admins
7184
7285 return collection_bundle
7386
@@ -101,6 +114,20 @@ def fetch_collection(
101114 item .experiments = [
102115 experiment for experiment in item .experiments if has_permission (user_data , experiment , Action .READ )
103116 ]
117+ # unless user is admin of this collection, filter users to only admins
118+ # the rationale is that all collection contributors should be able to see admins
119+ # to know who to contact, but only collection admins should be able to see viewers and editors
120+ # TODO either create permissions action for this or look up user's role outside of the permissions module
121+ # for now, just assume that if user has permission to add role, they are a collection admin
122+ if not has_permission (user_data , item , Action .ADD_ROLE ):
123+ admins = []
124+ for user_assoc in item .user_associations :
125+ if user_assoc .contribution_role == ContributionRole .admin :
126+ admin = user_assoc .user
127+ # role must be set in order to assign users to collection
128+ setattr (admin , "role" , ContributionRole .admin )
129+ admins .append (admin )
130+ item .users = admins
104131
105132 return item
106133
@@ -270,6 +297,20 @@ async def update_collection(
270297 item .experiments = [
271298 experiment for experiment in item .experiments if has_permission (user_data , experiment , Action .READ )
272299 ]
300+ # unless user is admin of this collection, filter users to only admins
301+ # the rationale is that all collection contributors should be able to see admins
302+ # to know who to contact, but only collection admins should be able to see viewers and editors
303+ # TODO either create permissions action for this or look up user's role outside of the permissions module
304+ # for now, just assume that if user has permission to add role, they are a collection admin
305+ if not has_permission (user_data , item , Action .ADD_ROLE ):
306+ admins = []
307+ for user_assoc in item .user_associations :
308+ if user_assoc .contribution_role == ContributionRole .admin :
309+ admin = user_assoc .user
310+ # role must be set in order to assign users to collection
311+ setattr (admin , "role" , ContributionRole .admin )
312+ admins .append (admin )
313+ item .users = admins
273314
274315 return item
275316
@@ -325,6 +366,20 @@ async def add_score_set_to_collection(
325366 item .experiments = [
326367 experiment for experiment in item .experiments if has_permission (user_data , experiment , Action .READ )
327368 ]
369+ # unless user is admin of this collection, filter users to only admins
370+ # the rationale is that all collection contributors should be able to see admins
371+ # to know who to contact, but only collection admins should be able to see viewers and editors
372+ # TODO either create permissions action for this or look up user's role outside of the permissions module
373+ # for now, just assume that if user has permission to add role, they are a collection admin
374+ if not has_permission (user_data , item , Action .ADD_ROLE ):
375+ admins = []
376+ for user_assoc in item .user_associations :
377+ if user_assoc .contribution_role == ContributionRole .admin :
378+ admin = user_assoc .user
379+ # role must be set in order to assign users to collection
380+ setattr (admin , "role" , ContributionRole .admin )
381+ admins .append (admin )
382+ item .users = admins
328383
329384 return item
330385
@@ -390,6 +445,20 @@ async def delete_score_set_from_collection(
390445 item .experiments = [
391446 experiment for experiment in item .experiments if has_permission (user_data , experiment , Action .READ )
392447 ]
448+ # unless user is admin of this collection, filter users to only admins
449+ # the rationale is that all collection contributors should be able to see admins
450+ # to know who to contact, but only collection admins should be able to see viewers and editors
451+ # TODO either create permissions action for this or look up user's role outside of the permissions module
452+ # for now, just assume that if user has permission to add role, they are a collection admin
453+ if not has_permission (user_data , item , Action .ADD_ROLE ):
454+ admins = []
455+ for user_assoc in item .user_associations :
456+ if user_assoc .contribution_role == ContributionRole .admin :
457+ admin = user_assoc .user
458+ # role must be set in order to assign users to collection
459+ setattr (admin , "role" , ContributionRole .admin )
460+ admins .append (admin )
461+ item .users = admins
393462
394463 return item
395464
@@ -445,6 +514,20 @@ async def add_experiment_to_collection(
445514 item .experiments = [
446515 experiment for experiment in item .experiments if has_permission (user_data , experiment , Action .READ )
447516 ]
517+ # unless user is admin of this collection, filter users to only admins
518+ # the rationale is that all collection contributors should be able to see admins
519+ # to know who to contact, but only collection admins should be able to see viewers and editors
520+ # TODO either create permissions action for this or look up user's role outside of the permissions module
521+ # for now, just assume that if user has permission to add role, they are a collection admin
522+ if not has_permission (user_data , item , Action .ADD_ROLE ):
523+ admins = []
524+ for user_assoc in item .user_associations :
525+ if user_assoc .contribution_role == ContributionRole .admin :
526+ admin = user_assoc .user
527+ # role must be set in order to assign users to collection
528+ setattr (admin , "role" , ContributionRole .admin )
529+ admins .append (admin )
530+ item .users = admins
448531
449532 return item
450533
@@ -508,6 +591,20 @@ async def delete_experiment_from_collection(
508591 item .experiments = [
509592 experiment for experiment in item .experiments if has_permission (user_data , experiment , Action .READ )
510593 ]
594+ # unless user is admin of this collection, filter users to only admins
595+ # the rationale is that all collection contributors should be able to see admins
596+ # to know who to contact, but only collection admins should be able to see viewers and editors
597+ # TODO either create permissions action for this or look up user's role outside of the permissions module
598+ # for now, just assume that if user has permission to add role, they are a collection admin
599+ if not has_permission (user_data , item , Action .ADD_ROLE ):
600+ admins = []
601+ for user_assoc in item .user_associations :
602+ if user_assoc .contribution_role == ContributionRole .admin :
603+ admin = user_assoc .user
604+ # role must be set in order to assign users to collection
605+ setattr (admin , "role" , ContributionRole .admin )
606+ admins .append (admin )
607+ item .users = admins
511608
512609 return item
513610
@@ -594,6 +691,8 @@ async def add_user_to_collection_role(
594691 item .experiments = [
595692 experiment for experiment in item .experiments if has_permission (user_data , experiment , Action .READ )
596693 ]
694+ # TODO only collection admins can get to this point in the function, so shouldn't need to filter out
695+ # viewers and editors before returning item, but should check with others
597696
598697 return item
599698
@@ -669,6 +768,8 @@ async def remove_user_from_collection_role(
669768 item .experiments = [
670769 experiment for experiment in item .experiments if has_permission (user_data , experiment , Action .READ )
671770 ]
771+ # TODO only collection admins can get to this point in the function, so shouldn't need to filter out
772+ # viewers and editors before returning item, but should check with others
672773
673774 return item
674775
0 commit comments