forked from rero/sonar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
schemas: remove fields on documents and deposits
Move the schema processing to dedicated classes. * Removes collections and subdivisions on documents and deposits schema. * Closes rero#752. Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
- Loading branch information
1 parent
2422b85
commit d410101
Showing
9 changed files
with
319 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Swiss Open Access Repository | ||
# Copyright (C) 2022 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/>. | ||
|
||
"""Documents JSON schema class.""" | ||
|
||
from sonar.modules.users.api import current_user_record | ||
|
||
from .json_schema_base import JSONSchemaBase | ||
|
||
|
||
class DocumentsJSONSchema(JSONSchemaBase): | ||
"""JSON schema for deposits.""" | ||
|
||
def process(self): | ||
"""Documents JSON schema custom process. | ||
:returns: The processed schema. | ||
""" | ||
schema = super().process() | ||
|
||
if not current_user_record: | ||
return schema | ||
|
||
# Get Organisation for the current logged user | ||
organisation = current_user_record.replace_refs().get('organisation') | ||
# Remove some fields on json for the shared organisation | ||
if organisation.get('isShared'): | ||
for field in ['collections', 'subdivisions']: | ||
schema['properties'].pop(field, None) | ||
if field in schema.get('propertiesOrder', []): | ||
schema['propertiesOrder'].remove(field) | ||
|
||
if not current_user_record.is_superuser: | ||
schema['properties'].pop('organisation', None) | ||
if 'organisation' in schema.get('propertiesOrder', []): | ||
schema['propertiesOrder'].remove('organisation') | ||
|
||
return schema |
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,41 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Swiss Open Access Repository | ||
# Copyright (C) 2022 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/>. | ||
|
||
"""Documents JSON schema class.""" | ||
|
||
from sonar.modules.users.api import current_user_record | ||
|
||
from .json_schema_base import JSONSchemaBase | ||
|
||
|
||
class OrganisationsJSONSchema(JSONSchemaBase): | ||
"""JSON schema for deposits.""" | ||
|
||
def process(self): | ||
"""Documents JSON schema custom process. | ||
:returns: The processed schema. | ||
""" | ||
schema = super().process() | ||
|
||
# Remove modes fields if user does not have superuser role. | ||
if not current_user_record.is_superuser: | ||
propertiesOrder = schema.get('propertiesOrder', []); | ||
for field in ['isDedicated', 'isShared']: | ||
if field in propertiesOrder: | ||
schema['propertiesOrder'].remove(field) | ||
return schema |
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,47 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Swiss Open Access Repository | ||
# Copyright (C) 2022 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/>. | ||
|
||
"""Projects JSON schema class.""" | ||
|
||
from flask_login import current_user | ||
|
||
from sonar.modules.users.api import current_user_record | ||
|
||
from .json_schema_base import JSONSchemaBase | ||
|
||
|
||
class ProjectsJSONSchema(JSONSchemaBase): | ||
"""JSON schema for deposits.""" | ||
|
||
def process(self): | ||
"""Projects JSON schema custom process. | ||
:returns: The processed schema. | ||
""" | ||
schema = super().process() | ||
|
||
# Remove modes fields if user does not have superuser role. | ||
if (current_user and not current_user.is_anonymous) \ | ||
and (current_user_record and not current_user_record.is_superuser): | ||
schema['properties']['metadata']['properties'].pop( | ||
'organisation', None) | ||
if 'organisation' in schema['properties']['metadata']\ | ||
['propertiesOrder']: | ||
schema['properties']['metadata']['propertiesOrder'].remove( | ||
'organisation') | ||
|
||
return schema |
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,60 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Swiss Open Access Repository | ||
# Copyright (C) 2022 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/>. | ||
|
||
"""Users JSON schema class.""" | ||
|
||
from flask_login import current_user | ||
|
||
from sonar.modules.users.api import current_user_record | ||
|
||
from .json_schema_base import JSONSchemaBase | ||
|
||
|
||
class UsersJSONSchema(JSONSchemaBase): | ||
"""JSON schema for deposits.""" | ||
|
||
def process(self): | ||
"""Users JSON schema custom process. | ||
:returns: The processed schema. | ||
""" | ||
schema = super().process() | ||
|
||
# Remove modes fields if user does not have superuser role. | ||
if not current_user.is_anonymous and current_user_record: | ||
if current_user_record.is_admin: | ||
reachable_roles = current_user_record.\ | ||
get_all_reachable_roles() | ||
|
||
schema['properties']['role']['form']['options'] = [{ | ||
'label': 'role_{role}'.format(role=role), | ||
'value': role | ||
} for role in reachable_roles] | ||
schema['properties']['role'][ | ||
'enum'] = current_user_record.get_all_reachable_roles( | ||
) | ||
else: | ||
schema['properties'].pop('role') | ||
if 'role' in schema.get('propertiesOrder', []): | ||
schema['propertiesOrder'].remove('role') | ||
|
||
if not current_user_record.is_superuser: | ||
schema['properties'].pop('organisation') | ||
if 'organisation' in schema.get('propertiesOrder', []): | ||
schema['propertiesOrder'].remove('organisation') | ||
|
||
return schema |
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
Oops, something went wrong.