@@ -86,22 +86,22 @@ def register_command_info(aliases, command_info):
86
86
share_record_parser .add_argument ('record' , nargs = '?' , type = str , action = 'store' , help = 'record/shared folder path/UID' )
87
87
88
88
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' )
91
91
share_folder_parser .add_argument ('-e' , '--email' , dest = 'user' , action = 'append' ,
92
92
help = 'account email, team, @existing for all users and teams in the folder, '
93
93
'or \' *\' as default folder permission' )
94
94
share_folder_parser .add_argument ('-r' , '--record' , dest = 'record' , action = 'append' ,
95
95
help = 'record name, record UID, @existing for all records in the folder,'
96
96
' 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.' )
105
105
share_folder_parser .add_argument ('-f' , '--force' , dest = 'force' , action = 'store_true' ,
106
106
help = 'Apply permission changes ignoring default folder permissions. Used on the '
107
107
'initial sharing action' )
@@ -423,13 +423,13 @@ def prepare_request(params, kwargs, curr_sf, users, teams, rec_uids, *,
423
423
action = kwargs .get ('action' ) or 'grant'
424
424
mr = kwargs .get ('manage_records' )
425
425
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
429
429
else :
430
430
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
433
433
else :
434
434
rq .defaultManageUsers = folder_pb2 .BOOLEAN_NO_CHANGE
435
435
@@ -446,12 +446,8 @@ def prepare_request(params, kwargs, curr_sf, users, teams, rec_uids, *,
446
446
uo .expiration = - 1
447
447
if email in existing_users :
448
448
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
455
451
rq .sharedFolderUpdateUser .append (uo )
456
452
elif action == 'remove' :
457
453
rq .sharedFolderRemoveUser .append (uo .username )
@@ -463,8 +459,8 @@ def prepare_request(params, kwargs, curr_sf, users, teams, rec_uids, *,
463
459
logging .warning ('Please repeat this command when invitation is accepted.' )
464
460
keys = params .key_cache .get (email )
465
461
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
468
464
sf_key = curr_sf .get ('shared_folder_key_unencrypted' ) # type: Optional[bytes]
469
465
if sf_key :
470
466
if params .forbid_rsa and keys .ec :
@@ -494,12 +490,8 @@ def prepare_request(params, kwargs, curr_sf, users, teams, rec_uids, *,
494
490
if team_uid in existing_teams :
495
491
team = existing_teams [team_uid ]
496
492
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'
503
495
rq .sharedFolderUpdateTeam .append (to )
504
496
elif action == 'remove' :
505
497
rq .sharedFolderRemoveTeam .append (to .teamUid )
@@ -537,15 +529,9 @@ def prepare_request(params, kwargs, curr_sf, users, teams, rec_uids, *,
537
529
ce = kwargs .get ('can_edit' )
538
530
cs = kwargs .get ('can_share' )
539
531
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
549
535
550
536
if len (rec_uids ) > 0 :
551
537
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, *,
561
547
562
548
if record_uid in existing_records :
563
549
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
570
552
rq .sharedFolderUpdateRecord .append (ro )
571
553
elif action == 'remove' :
572
554
rq .sharedFolderRemoveRecord .append (ro .recordUid )
573
555
else :
574
556
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
577
559
sf_key = curr_sf .get ('shared_folder_key_unencrypted' )
578
560
if sf_key :
579
561
rec = params .record_cache [record_uid ]
0 commit comments