Skip to content

Commit 72988df

Browse files
committed
share-folder: use 3-state value for permissions
1 parent 9fcb193 commit 72988df

File tree

1 file changed

+28
-46
lines changed

1 file changed

+28
-46
lines changed

Diff for: keepercommander/commands/register.py

+28-46
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,22 @@ def register_command_info(aliases, command_info):
8686
share_record_parser.add_argument('record', nargs='?', type=str, action='store', help='record/shared folder path/UID')
8787

8888
share_folder_parser = argparse.ArgumentParser(prog='share-folder', description='Change a shared folders permissions.')
89-
share_folder_parser.add_argument('-a', '--action', dest='action', choices=['grant', 'revoke', 'remove'], default='grant',
90-
action='store', help='shared folder action. \'grant\' if omitted')
89+
share_folder_parser.add_argument('-a', '--action', dest='action', choices=['grant','remove'],
90+
default='grant', action='store', help='shared folder action. \'grant\' if omitted')
9191
share_folder_parser.add_argument('-e', '--email', dest='user', action='append',
9292
help='account email, team, @existing for all users and teams in the folder, '
9393
'or \'*\' as default folder permission')
9494
share_folder_parser.add_argument('-r', '--record', dest='record', action='append',
9595
help='record name, record UID, @existing for all records in the folder,'
9696
' or \'*\' as default folder permission')
97-
share_folder_parser.add_argument('-p', '--manage-records', dest='manage_records', action='store_true',
98-
help='account permission: can manage records.')
99-
share_folder_parser.add_argument('-o', '--manage-users', dest='manage_users', action='store_true',
100-
help='account permission: can manage users.')
101-
share_folder_parser.add_argument('-s', '--can-share', dest='can_share', action='store_true',
102-
help='record permission: can be shared')
103-
share_folder_parser.add_argument('-d', '--can-edit', dest='can_edit', action='store_true',
104-
help='record permission: can be modified.')
97+
share_folder_parser.add_argument('-p', '--manage-records', dest='manage_records', action='store',
98+
choices=['on', 'off'], help='account permission: can manage records.')
99+
share_folder_parser.add_argument('-o', '--manage-users', dest='manage_users', action='store',
100+
choices=['on', 'off'], help='account permission: can manage users.')
101+
share_folder_parser.add_argument('-s', '--can-share', dest='can_share', action='store',
102+
choices=['on', 'off'], help='record permission: can be shared')
103+
share_folder_parser.add_argument('-d', '--can-edit', dest='can_edit', action='store',
104+
choices=['on', 'off'], help='record permission: can be modified.')
105105
share_folder_parser.add_argument('-f', '--force', dest='force', action='store_true',
106106
help='Apply permission changes ignoring default folder permissions. Used on the '
107107
'initial sharing action')
@@ -423,13 +423,13 @@ def prepare_request(params, kwargs, curr_sf, users, teams, rec_uids, *,
423423
action = kwargs.get('action') or 'grant'
424424
mr = kwargs.get('manage_records')
425425
mu = kwargs.get('manage_users')
426-
if default_account and action != 'remove':
427-
if mr:
428-
rq.defaultManageRecords = folder_pb2.BOOLEAN_TRUE if action == 'grant' else folder_pb2.BOOLEAN_FALSE
426+
if default_account and action == 'grant':
427+
if mr is not None:
428+
rq.defaultManageRecords = folder_pb2.BOOLEAN_TRUE if mr == 'on' else folder_pb2.BOOLEAN_FALSE
429429
else:
430430
rq.defaultManageRecords = folder_pb2.BOOLEAN_NO_CHANGE
431-
if mu:
432-
rq.defaultManageUsers = folder_pb2.BOOLEAN_TRUE if action == 'grant' else folder_pb2.BOOLEAN_FALSE
431+
if mu is not None:
432+
rq.defaultManageUsers = folder_pb2.BOOLEAN_TRUE if mu == 'on' else folder_pb2.BOOLEAN_FALSE
433433
else:
434434
rq.defaultManageUsers = folder_pb2.BOOLEAN_NO_CHANGE
435435

@@ -446,12 +446,8 @@ def prepare_request(params, kwargs, curr_sf, users, teams, rec_uids, *,
446446
uo.expiration = -1
447447
if email in existing_users:
448448
if action == 'grant':
449-
uo.manageRecords = folder_pb2.BOOLEAN_TRUE if mr else folder_pb2.BOOLEAN_NO_CHANGE
450-
uo.manageUsers = folder_pb2.BOOLEAN_TRUE if mu else folder_pb2.BOOLEAN_NO_CHANGE
451-
rq.sharedFolderUpdateUser.append(uo)
452-
elif action == 'revoke':
453-
uo.manageRecords = folder_pb2.BOOLEAN_FALSE if mr else folder_pb2.BOOLEAN_NO_CHANGE
454-
uo.manageUsers = folder_pb2.BOOLEAN_FALSE if mu else folder_pb2.BOOLEAN_NO_CHANGE
449+
uo.manageRecords = folder_pb2.BOOLEAN_NO_CHANGE if mr is None else folder_pb2.BOOLEAN_TRUE if mr == 'on' else folder_pb2.BOOLEAN_FALSE
450+
uo.manageUsers = folder_pb2.BOOLEAN_NO_CHANGE if mu is None else folder_pb2.BOOLEAN_TRUE if mu == 'on' else folder_pb2.BOOLEAN_FALSE
455451
rq.sharedFolderUpdateUser.append(uo)
456452
elif action == 'remove':
457453
rq.sharedFolderRemoveUser.append(uo.username)
@@ -463,8 +459,8 @@ def prepare_request(params, kwargs, curr_sf, users, teams, rec_uids, *,
463459
logging.warning('Please repeat this command when invitation is accepted.')
464460
keys = params.key_cache.get(email)
465461
if keys and keys.rsa:
466-
uo.manageRecords = folder_pb2.BOOLEAN_TRUE if mr or curr_sf.get('default_manage_records') is True else folder_pb2.BOOLEAN_FALSE
467-
uo.manageUsers = folder_pb2.BOOLEAN_TRUE if mu or curr_sf.get('default_manage_users') is True else folder_pb2.BOOLEAN_FALSE
462+
uo.manageRecords = curr_sf.get('default_manage_records') is True if mr is None else folder_pb2.BOOLEAN_TRUE if mr == 'on' else folder_pb2.BOOLEAN_FALSE
463+
uo.manageUsers = curr_sf.get('default_manage_users') is True if mu is None else folder_pb2.BOOLEAN_TRUE if mu == 'on' else folder_pb2.BOOLEAN_FALSE
468464
sf_key = curr_sf.get('shared_folder_key_unencrypted') # type: Optional[bytes]
469465
if sf_key:
470466
if params.forbid_rsa and keys.ec:
@@ -494,12 +490,8 @@ def prepare_request(params, kwargs, curr_sf, users, teams, rec_uids, *,
494490
if team_uid in existing_teams:
495491
team = existing_teams[team_uid]
496492
if action == 'grant':
497-
to.manageRecords = True if mr else team.get('manage_records', False)
498-
to.manageUsers = True if mu else team.get('manage_users', False)
499-
rq.sharedFolderUpdateTeam.append(to)
500-
elif action == 'revoke':
501-
to.manageRecords = False if mr else team.get('manage_records', False)
502-
to.manageUsers = False if mu else team.get('manage_users', False)
493+
to.manageRecords = team.get('manage_records') is True if mr is None else mr == 'on'
494+
to.manageUsers = team.get('manage_users') is True if mu is None else mu == 'on'
503495
rq.sharedFolderUpdateTeam.append(to)
504496
elif action == 'remove':
505497
rq.sharedFolderRemoveTeam.append(to.teamUid)
@@ -537,15 +529,9 @@ def prepare_request(params, kwargs, curr_sf, users, teams, rec_uids, *,
537529
ce = kwargs.get('can_edit')
538530
cs = kwargs.get('can_share')
539531

540-
if default_record:
541-
if ce and action != 'remove':
542-
rq.defaultCanEdit = folder_pb2.BOOLEAN_TRUE if action == 'grant' else folder_pb2.BOOLEAN_FALSE
543-
else:
544-
rq.defaultCanEdit = folder_pb2.BOOLEAN_NO_CHANGE
545-
if cs and action != 'remove':
546-
rq.defaultCanShare = folder_pb2.BOOLEAN_TRUE if action == 'grant' else folder_pb2.BOOLEAN_FALSE
547-
else:
548-
rq.defaultCanShare = folder_pb2.BOOLEAN_NO_CHANGE
532+
if default_record and action == 'grant':
533+
rq.defaultCanEdit = folder_pb2.BOOLEAN_NO_CHANGE if ce is None else folder_pb2.BOOLEAN_TRUE if ce == 'on' else folder_pb2.BOOLEAN_FALSE
534+
rq.defaultCanShare = folder_pb2.BOOLEAN_NO_CHANGE if cs is None else folder_pb2.BOOLEAN_TRUE if cs == 'on' else folder_pb2.BOOLEAN_FALSE
549535

550536
if len(rec_uids) > 0:
551537
existing_records = {x['record_uid'] for x in curr_sf.get('records', [])}
@@ -561,19 +547,15 @@ def prepare_request(params, kwargs, curr_sf, users, teams, rec_uids, *,
561547

562548
if record_uid in existing_records:
563549
if action == 'grant':
564-
ro.canEdit = folder_pb2.BOOLEAN_TRUE if ce else folder_pb2.BOOLEAN_NO_CHANGE
565-
ro.canShare = folder_pb2.BOOLEAN_TRUE if cs else folder_pb2.BOOLEAN_NO_CHANGE
566-
rq.sharedFolderUpdateRecord.append(ro)
567-
elif action == 'revoke':
568-
ro.canEdit = folder_pb2.BOOLEAN_FALSE if ce else folder_pb2.BOOLEAN_NO_CHANGE
569-
ro.canShare = folder_pb2.BOOLEAN_FALSE if cs else folder_pb2.BOOLEAN_NO_CHANGE
550+
ro.canEdit = folder_pb2.BOOLEAN_NO_CHANGE if ce is None else folder_pb2.BOOLEAN_TRUE if ce == 'on' else folder_pb2.BOOLEAN_FALSE
551+
ro.canShare = folder_pb2.BOOLEAN_NO_CHANGE if cs is None else folder_pb2.BOOLEAN_TRUE if cs == 'on' else folder_pb2.BOOLEAN_FALSE
570552
rq.sharedFolderUpdateRecord.append(ro)
571553
elif action == 'remove':
572554
rq.sharedFolderRemoveRecord.append(ro.recordUid)
573555
else:
574556
if action == 'grant':
575-
ro.canEdit = folder_pb2.BOOLEAN_TRUE if ce or curr_sf.get('default_can_edit') is True else folder_pb2.BOOLEAN_FALSE
576-
ro.canShare = folder_pb2.BOOLEAN_TRUE if cs or curr_sf.get('default_can_share') is True else folder_pb2.BOOLEAN_FALSE
557+
ro.canEdit = curr_sf.get('default_can_edit') is True if ce is None else folder_pb2.BOOLEAN_TRUE if ce == 'on' else folder_pb2.BOOLEAN_FALSE
558+
ro.canShare = curr_sf.get('default_can_share') is True if cs is None else folder_pb2.BOOLEAN_TRUE if cs == 'on' else folder_pb2.BOOLEAN_FALSE
577559
sf_key = curr_sf.get('shared_folder_key_unencrypted')
578560
if sf_key:
579561
rec = params.record_cache[record_uid]

0 commit comments

Comments
 (0)