-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
permissions: refactoring organisation permissions
* Refactoring the permissions process using a permission factory and permission classes for any resource instead of resources shared functions. This way is the same way used by SONAR & Zenodo project * Creates permission factory method * Creates basic permission classes * Create Organisation permission class * Fixes unitests Co-Authored-by: Renaud Michotte <renaud.michotte@gmail.com>
- Loading branch information
Showing
9 changed files
with
448 additions
and
104 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
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,96 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# RERO ILS | ||
# Copyright (C) 2019 RERO | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Permissions for organisations.""" | ||
|
||
from rero_ils.modules.organisations.api import current_organisation | ||
from rero_ils.modules.permissions import RecordPermission | ||
from rero_ils.modules.patrons.api import current_patron | ||
|
||
|
||
class OrganisationPermission(RecordPermission): | ||
"""Organisations permissions.""" | ||
|
||
@classmethod | ||
def list(cls, user, record=None): | ||
"""List permission check. | ||
:param user: Logged user. | ||
:param record: Record to check. | ||
:returns: True is action can be done. | ||
""" | ||
# List organisation allowed only for staff members (lib, sys_lib) | ||
if not current_patron or not current_patron.is_librarian: | ||
return False | ||
return True | ||
|
||
@classmethod | ||
def create(cls, user, record=None): | ||
"""Create permission check. | ||
:param user: Logged user. | ||
:param record: Record to check. | ||
:returns: True is action can be done. | ||
""" | ||
# Nobody can create an organisation. To create a new organisation, use | ||
# the CLI interface | ||
return False | ||
|
||
@classmethod | ||
def read(cls, user, record): | ||
"""Read permission check. | ||
:param user: Logged user. | ||
:param record: Record to check. | ||
:returns: True is action can be done. | ||
""" | ||
# user should be authenticated | ||
if not current_patron: | ||
return False | ||
# Super user is allowed | ||
if current_patron.is_superuser: | ||
return True | ||
# only staff members (lib, sys_lib) are allowed to read an organisation | ||
if not current_patron.is_librarian: | ||
return False | ||
# For staff users, they can read only their own organisation. | ||
return current_organisation['pid'] == record['pid'] | ||
|
||
@classmethod | ||
def update(cls, user, record): | ||
"""Update permission check. | ||
:param user: Logged user. | ||
:param record: Record to check. | ||
:returns: True is action can be done. | ||
""" | ||
# user should be authenticated | ||
if not current_patron or not current_patron.is_system_librarian: | ||
return False | ||
# super user is allowed | ||
if current_patron.is_superuser: | ||
return True | ||
# only 'system_librarian' user allowed to update their own organisation | ||
if not current_patron.is_system_librarian: | ||
return False | ||
return current_organisation['pid'] == record['pid'] | ||
|
||
@classmethod | ||
def delete(cls, user, record): | ||
"""Delete permission check. | ||
:param user: Logged user. | ||
:param record: Record to check. | ||
:returns: True if action can be done. | ||
""" | ||
# Nobody can remove an organisation | ||
return False |
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
Oops, something went wrong.