-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Files refactor to include repositories logic (#1560)
* remove unneeded provider methods * create access policies file * refactor get_functions repository method * refactor groups and repositories * repository refactor from files * fix some linter problems * fixed a bug when the user retrieves a function * fix lint * refactor of get_function method * remove artifact test file * remove programs access policies * refactor programs references to functions * group repository refactor * rename groups repository into user repository * simplified get_function methods * fix query * adapt get_functions methods * updated comments * create path if doesn't exist * remove some unused code * fix files client * fix typos * fixed the creation of the directory * added a test for the provider end-points * fix some typos from the provider end-points * fix black on tests
- Loading branch information
Showing
13 changed files
with
497 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Access policies implementation for Provider access | ||
""" | ||
import logging | ||
|
||
from api.models import Provider | ||
|
||
|
||
logger = logging.getLogger("gateway") | ||
|
||
|
||
class ProviderAccessPolicy: # pylint: disable=too-few-public-methods | ||
""" | ||
The main objective of this class is to manage the access for the user | ||
to the Provider entities. | ||
""" | ||
|
||
@staticmethod | ||
def can_access(user, provider: Provider) -> bool: | ||
""" | ||
Checks if the user has access to a Provider: | ||
Args: | ||
user: Django user from the request | ||
provider: Provider instance against to check the access | ||
Returns: | ||
bool: True or False in case the user has access | ||
""" | ||
|
||
user_groups = user.groups.all() | ||
admin_groups = provider.admin_groups.all() | ||
has_access = any(group in admin_groups for group in user_groups) | ||
if not has_access: | ||
logger.warning( | ||
"User [%s] has no access to provider [%s].", user.id, provider.name | ||
) | ||
return has_access |
Oops, something went wrong.