Skip to content

Commit

Permalink
Added ability to search for worksheets shared with you through groups (
Browse files Browse the repository at this point in the history
…#914)

* Added ability to search for worksheets shared with you through groups

* fixing errors, also adding condition that permission must be greater than or equal to GROUP_OBJECT_PERMISSION_READ (there are not any permission objects with permission value GROUP_OBJECT_PERMISSION_NONE, since they are just removed instead, but just making sure.)
  • Loading branch information
w0nche0l authored May 19, 2018
1 parent 7086232 commit f78efb5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions codalab/lib/bundle_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2378,8 +2378,10 @@ def display_interpreted(self, client, worksheet_info, interpreted):
aliases=('wsearch', 'ws'),
help=[
'List worksheets on the current instance matching the given keywords.',
' wls tag=paper : List worksheets tagged as "paper".',
' wls .mine : List my worksheets.',
' wls tag=paper : List worksheets tagged as "paper".',
' wls group=<group_spec> : List worksheets shared with the group identfied by group_spec.',
' wls .mine : List my worksheets.',
' wls .shared : List worksheets that have been shared with any of the groups I am in.',
],
arguments=(
Commands.Argument('keywords', help='Keywords to search for.', nargs='*'),
Expand Down
20 changes: 20 additions & 0 deletions codalab/model/bundle_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
from codalab.objects.user import (
User,
)
from codalab.rest.util import (
get_group_info
)

SEARCH_KEYWORD_REGEX = re.compile('^([\.\w/]*)=(.*)$')

Expand Down Expand Up @@ -1001,6 +1004,8 @@ def make_condition(field, value):
keyword = 'owner_id=' + (user_id or '')
elif keyword == '.last':
keyword = 'id=.sort-'
elif keyword == '.shared':
keyword = '.shared=True'

m = SEARCH_KEYWORD_REGEX.match(keyword) # key=value
if m:
Expand All @@ -1016,6 +1021,14 @@ def make_condition(field, value):
offset = int(value)
elif key == '.limit':
limit = int(value)
elif key == '.shared': # shared with any group I am in with read or all permission?
clause = cl_worksheet.c.uuid.in_(select([cl_group_worksheet_permission.c.object_uuid]).where(
and_(
cl_group_worksheet_permission.c.group_uuid.in_(
alias(select([cl_user_group.c.group_uuid]).where(cl_user_group.c.user_id == user_id))),
cl_group_worksheet_permission.c.permission >= GROUP_OBJECT_PERMISSION_READ
)
))
# Bundle fields
elif key == 'id':
clause = make_condition(cl_worksheet.c.id, value)
Expand All @@ -1027,6 +1040,13 @@ def make_condition(field, value):
clause = make_condition(cl_worksheet.c.title, value)
elif key == 'owner_id':
clause = make_condition(cl_worksheet.c.owner_id, value)
elif key == 'group': # shared with group with read or all permissions?
group_uuid = get_group_info(value, False)['uuid']
clause = cl_worksheet.c.uuid.in_(
select([cl_group_worksheet_permission.c.object_uuid])
.where(and_(
cl_group_worksheet_permission.c.group_uuid == group_uuid,
cl_group_worksheet_permission.c.permission >= GROUP_OBJECT_PERMISSION_READ)))
elif key == 'bundle': # contains bundle?
condition = make_condition(cl_worksheet_item.c.bundle_uuid, value)
if condition is None: # top-level
Expand Down

0 comments on commit f78efb5

Please sign in to comment.