@@ -49,19 +49,13 @@ def user_permission_list(
49
49
from yunohost .utils .ldap import _get_ldap_interface , _ldap_path_extract
50
50
51
51
ldap = _get_ldap_interface ()
52
- permissions_infos = ldap .search (
52
+ ldap_permissions_infos = ldap .search (
53
53
"ou=permission" ,
54
54
"(objectclass=permissionYnh)" ,
55
55
[
56
56
"cn" ,
57
57
"groupPermission" ,
58
58
"inheritPermission" ,
59
- "URL" ,
60
- "additionalUrls" ,
61
- "authHeader" ,
62
- "label" ,
63
- "showTile" ,
64
- "isProtected" ,
65
59
],
66
60
)
67
61
@@ -78,30 +72,29 @@ def user_permission_list(
78
72
}
79
73
80
74
permissions = {}
81
- for infos in permissions_infos :
75
+ for infos in ldap_permissions_infos :
82
76
name = infos ["cn" ][0 ]
83
- app = name .split ("." )[ 0 ]
77
+ app , subperm = name .split ("." )
84
78
85
79
if ignore_system_perms and app in SYSTEM_PERMS :
86
80
continue
87
81
if filter_ and app not in apps :
88
82
continue
89
83
90
84
perm = {}
91
- perm ["allowed" ] = [
92
- _ldap_path_extract (p , "cn" ) for p in infos .get ("groupPermission" , [])
93
- ]
94
-
95
- if full :
96
- perm ["corresponding_users" ] = [
97
- _ldap_path_extract (p , "uid" ) for p in infos .get ("inheritPermission" , [])
98
- ]
99
- perm ["auth_header" ] = infos .get ("authHeader" , [False ])[0 ] == "TRUE"
100
- perm ["label" ] = infos .get ("label" , [None ])[0 ]
101
- perm ["show_tile" ] = infos .get ("showTile" , [False ])[0 ] == "TRUE"
102
- perm ["protected" ] = infos .get ("isProtected" , [False ])[0 ] == "TRUE"
103
- perm ["url" ] = infos .get ("URL" , [None ])[0 ]
104
- perm ["additional_urls" ] = infos .get ("additionalUrls" , [])
85
+ if full and app not in SYSTEM_PERMS :
86
+ # Default stuff
87
+ perm = {
88
+ "url" : None ,
89
+ "additional_urls" : [],
90
+ "auth_header" : True ,
91
+ "show_tile" : None , # To be automagically set to True by default if an url is defined and show_tile not provided
92
+ "protected" : False ,
93
+ }
94
+ perm_settings = (app_setting (app , "_permissions" ) or {}).get (subperm , {})
95
+ perm .update (perm_settings )
96
+ if perm ["show_tile" ] is None and perm ["url" ] is not None :
97
+ perm ["show_tile" ] = True
105
98
106
99
if absolute_urls :
107
100
app_base_path = (
@@ -113,6 +106,14 @@ def user_permission_list(
113
106
for url in perm ["additional_urls" ]
114
107
]
115
108
109
+ perm ["allowed" ] = [
110
+ _ldap_path_extract (p , "cn" ) for p in infos .get ("groupPermission" , [])
111
+ ]
112
+ if full :
113
+ perm ["corresponding_users" ] = [
114
+ _ldap_path_extract (p , "uid" ) for p in infos .get ("inheritPermission" , [])
115
+ ]
116
+
116
117
permissions [name ] = perm
117
118
118
119
# Make sure labels for sub-permissions are the form " Applabel (Sublabel) "
@@ -414,16 +415,6 @@ def permission_create(
414
415
"objectClass" : ["top" , "permissionYnh" , "posixGroup" ],
415
416
"cn" : str (permission ),
416
417
"gidNumber" : gid ,
417
- "authHeader" : ["TRUE" ],
418
- "label" : [
419
- str (label ) if label else (subperm if subperm != "main" else app .title ())
420
- ],
421
- "showTile" : [
422
- "FALSE"
423
- ], # Dummy value, it will be fixed when we call '_update_ldap_group_permission'
424
- "isProtected" : [
425
- "FALSE"
426
- ], # Dummy value, it will be fixed when we call '_update_ldap_group_permission'
427
418
}
428
419
429
420
if allowed is not None :
@@ -446,6 +437,8 @@ def permission_create(
446
437
"permission_creation_failed" , permission = permission , error = e
447
438
)
448
439
440
+ label = str (label ) if label else (subperm if subperm != "main" else app .title ())
441
+
449
442
try :
450
443
permission_url (
451
444
permission ,
@@ -463,6 +456,7 @@ def permission_create(
463
456
protected = protected ,
464
457
sync_perm = sync_perm ,
465
458
)
459
+
466
460
except Exception :
467
461
permission_delete (permission , force = True )
468
462
raise
@@ -496,15 +490,15 @@ def permission_url(
496
490
clear_urls -- (optional) Clean all urls (url and additional_urls)
497
491
"""
498
492
from yunohost .app import app_setting
499
- from yunohost .utils .ldap import _get_ldap_interface
500
-
501
- ldap = _get_ldap_interface ()
502
493
503
494
# By default, manipulate main permission
504
495
if "." not in permission :
505
496
permission = permission + ".main"
506
497
507
- app = permission .split ("." )[0 ]
498
+ app , sub_permission = permission .split ("." )
499
+
500
+ if app in SYSTEM_PERMS :
501
+ logger .warning (f"Cannot change urls / auth_header for system perm { permission } " )
508
502
509
503
if url or add_url :
510
504
domain = app_setting (app , "domain" )
@@ -573,19 +567,20 @@ def permission_url(
573
567
574
568
# Actually commit the change
575
569
576
- operation_logger .related_to .append (("app" , permission . split ( "." )[ 0 ] ))
570
+ operation_logger .related_to .append (("app" , app ))
577
571
operation_logger .start ()
578
572
579
573
try :
580
- ldap .update (
581
- f"cn={ permission } ,ou=permission" ,
582
- {
583
- "URL" : [url ] if url is not None else [],
584
- "additionalUrls" : new_additional_urls ,
585
- "authHeader" : [str (auth_header ).upper ()],
586
- "showTile" : [str (show_tile ).upper ()],
587
- },
588
- )
574
+ perm_settings = app_setting (app , "_permissions" , {})
575
+ if sub_permission not in perm_settings :
576
+ perm_settings [sub_permission ] = {}
577
+ perm_settings [sub_permission ].update ({
578
+ "url" : url ,
579
+ "additional_urls" : new_additional_urls ,
580
+ "auth_header" : auth_header ,
581
+ "show_tile" : show_tile ,
582
+ })
583
+ app_setting (app , "_permissions" , perm_settings )
589
584
except Exception as e :
590
585
raise YunohostError ("permission_update_failed" , permission = permission , error = e )
591
586
@@ -714,48 +709,65 @@ def _update_ldap_group_permission(
714
709
- the 'allowed' list contains *existing* groups.
715
710
"""
716
711
712
+ from yunohost .app import app_setting
717
713
from yunohost .hook import hook_callback
718
714
from yunohost .utils .ldap import _get_ldap_interface
719
715
720
716
ldap = _get_ldap_interface ()
721
717
718
+ app , sub_permission = permission .split ("." )
722
719
existing_permission = user_permission_info (permission )
723
720
724
- update = {}
721
+ update_ldap = {}
722
+ update_settings = {}
725
723
726
724
if allowed is not None :
727
725
allowed = [allowed ] if not isinstance (allowed , list ) else allowed
728
726
# Guarantee uniqueness of values in allowed, which would otherwise make ldap.update angry.
729
727
allowed = set (allowed )
730
- update ["groupPermission" ] = [
728
+ update_ldap ["groupPermission" ] = [
731
729
"cn=" + g + ",ou=groups,dc=yunohost,dc=org" for g in allowed
732
730
]
733
731
734
732
if label is not None :
735
- update ["label" ] = [str (label )]
733
+ if app in SYSTEM_PERMS :
734
+ logger .warning (f"Can't change 'label' for system permission { permission } " )
735
+ else :
736
+ update_settings ["label" ] = str (label )
736
737
737
738
if protected is not None :
738
- update ["isProtected" ] = [str (protected ).upper ()]
739
+ if app in SYSTEM_PERMS :
740
+ logger .warning (f"Can't change 'protected' for system permission { permission } " )
741
+ else :
742
+ update_settings ["protected" ] = protected
739
743
740
744
if show_tile is not None :
741
- if show_tile is True :
745
+ if app in SYSTEM_PERMS :
746
+ logger .warning (f"Can't change 'show_tile' for system permission { permission } " )
747
+ elif show_tile is True :
742
748
if not existing_permission ["url" ]:
743
749
logger .warning (
744
750
m18n .n (
745
751
"show_tile_cant_be_enabled_for_url_not_defined" ,
746
752
permission = permission ,
747
753
)
748
754
)
749
- show_tile = False
755
+ update_settings [ " show_tile" ] = False
750
756
elif existing_permission ["url" ].startswith ("re:" ):
751
757
logger .warning (
752
758
m18n .n ("show_tile_cant_be_enabled_for_regex" , permission = permission )
753
759
)
754
- show_tile = False
755
- update ["showTile" ] = [str (show_tile ).upper ()]
760
+ update_settings ["show_tile" ] = False
761
+
762
+ if app not in SYSTEM_PERMS :
763
+ perm_settings = app_setting (app , "_permissions" , {})
764
+ if sub_permission not in perm_settings :
765
+ perm_settings [sub_permission ] = {}
766
+ perm_settings [sub_permission ].update (update_settings )
767
+ app_setting (app , "_permissions" , perm_settings )
756
768
757
769
try :
758
- ldap .update (f"cn={ permission } ,ou=permission" , update )
770
+ ldap .update (f"cn={ permission } ,ou=permission" , update_ldap )
759
771
except Exception as e :
760
772
raise YunohostError ("permission_update_failed" , permission = permission , error = e )
761
773
@@ -768,9 +780,6 @@ def _update_ldap_group_permission(
768
780
769
781
# Trigger app callbacks
770
782
771
- app = permission .split ("." )[0 ]
772
- sub_permission = permission .split ("." )[1 ]
773
-
774
783
old_corresponding_users = set (existing_permission ["corresponding_users" ])
775
784
new_corresponding_users = set (new_permission ["corresponding_users" ])
776
785
0 commit comments