@@ -68,20 +68,13 @@ def __require_privilaged_access(self):
6868 "The server must be start by using privilaged access to "
6969 "execute this action." )
7070
71- def __has_permission (self , permission ) -> bool :
72- """ True if the current user has given permission rights. """
73- if self .__manager .is_enabled and not self .__auth_session :
74- return False
75-
76- return self .hasPermission (permission , None )
77-
7871 def __require_permission_view (self ):
7972 """
8073 Checks if the curret user has PERMISSION_VIEW rights. Throws an
8174 exception if it is not.
8275 """
8376 permission = codechecker_api_shared .ttypes .Permission .PERMISSION_VIEW
84- if not self .__has_permission (permission ):
77+ if not self .hasPermission (permission , None ):
8578 raise codechecker_api_shared .ttypes .RequestFailed (
8679 codechecker_api_shared .ttypes .ErrorCode .UNAUTHORIZED ,
8780 "You are not authorized to execute this action." )
@@ -598,21 +591,23 @@ def getPermissionsForUser(self, scope, extra_params, perm_filter):
598591 # handler.
599592 params = ThriftAuthHandler .__unpack_extra_params (extra_params ,
600593 session )
594+ is_auth_enabled = self .__manager .is_enabled
601595
602596 perms = []
603597 for perm in permissions .get_permissions (scope ):
604598 should_return = True
605599 handler = make_handler (perm , params )
606600
607601 if should_return and perm_filter .given :
608- should_return = handler .has_permission (self .__auth_session )
602+ should_return = handler .has_permission (self .__auth_session ,
603+ is_auth_enabled )
609604
610605 if should_return and perm_filter .canManage :
611606 # If the user has any of the permissions that are
612607 # authorised to manage the currently iterated permission,
613608 # the filter passes.
614609 should_return = require_manager (
615- perm , params , self .__auth_session )
610+ perm , params , self .__auth_session , is_auth_enabled )
616611
617612 if should_return :
618613 perms .append (perm )
@@ -631,7 +626,8 @@ def getAuthorisedNames(self, permission, extra_params):
631626 perm , params = ThriftAuthHandler .__create_permission_args (
632627 permission , extra_params , session )
633628
634- if not require_manager (perm , params , self .__auth_session ):
629+ if not require_manager (perm , params , self .__auth_session ,
630+ self .__manager .is_enabled ):
635631 raise codechecker_api_shared .ttypes .RequestFailed (
636632 codechecker_api_shared .ttypes .ErrorCode .UNAUTHORIZED ,
637633 f"You can not manage the permission '{ perm .name } '" )
@@ -654,7 +650,8 @@ def addPermission(self, permission, auth_name, is_group, extra_params):
654650 perm , params = ThriftAuthHandler .__create_permission_args (
655651 permission , extra_params , session )
656652
657- if not require_manager (perm , params , self .__auth_session ):
653+ if not require_manager (perm , params , self .__auth_session ,
654+ self .__manager .is_enabled ):
658655 raise codechecker_api_shared .ttypes .RequestFailed (
659656 codechecker_api_shared .ttypes .ErrorCode .UNAUTHORIZED ,
660657 f"You can not manage the permission '{ perm .name } '" )
@@ -677,7 +674,8 @@ def removePermission(self, permission, auth_name, is_group, extra_params):
677674 perm , params = ThriftAuthHandler .__create_permission_args (
678675 permission , extra_params , session )
679676
680- if not require_manager (perm , params , self .__auth_session ):
677+ if not require_manager (perm , params , self .__auth_session ,
678+ self .__manager .is_enabled ):
681679 raise codechecker_api_shared .ttypes .RequestFailed (
682680 codechecker_api_shared .ttypes .ErrorCode .UNAUTHORIZED ,
683681 f"You can not manage the permission '{ perm .name } '" )
@@ -703,7 +701,8 @@ def hasPermission(self, permission, extra_params):
703701 permission , extra_params , session )
704702
705703 return require_permission (perm , params ,
706- self .__auth_session )
704+ self .__auth_session ,
705+ self .__manager .is_enabled )
707706
708707 # ============= Authorization, permission management =============
709708
0 commit comments