Skip to content

Commit

Permalink
Template: remove pid from template record
Browse files Browse the repository at this point in the history
* Closes rero#2269

Co-Authored-by: Aly Badr <aly.badr@rero.ch>
  • Loading branch information
Aly Badr committed Aug 5, 2021
1 parent 2cca223 commit d4bc0a5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rero_ils/modules/templates/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from functools import partial

from .extensions import RemoveDataPidExtension
from .models import TemplateIdentifier, TemplateMetadata
from ..api import IlsRecord, IlsRecordsIndexer, IlsRecordsSearch
from ..fetchers import id_fetcher
Expand Down Expand Up @@ -56,6 +57,8 @@ class Meta:
class Template(IlsRecord):
"""Templates class."""

_extensions = [RemoveDataPidExtension()]

minter = template_id_minter
fetcher = template_id_fetcher
provider = TemplateProvider
Expand Down
32 changes: 32 additions & 0 deletions rero_ils/modules/templates/extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2021 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/>.

"""Template record extensions."""

from invenio_records.extensions import RecordExtension


class RemoveDataPidExtension(RecordExtension):
"""Defines the methods needed by an extension."""

def pre_create(self, record):
"""Called before a template record is created.
:param record: the record metadata.
"""
# force removing of record pid
record.get('data', {}).pop('pid', None)
4 changes: 4 additions & 0 deletions tests/api/templates/test_templates_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,16 @@ def test_template_secure_api_create(client, json_header,
post_entrypoint = 'invenio_records_rest.tmpl_list'

del templ_doc_public_martigny_data['pid']
# add a pid to the record data
templ_doc_public_martigny_data['data']['pid'] = 'toto'
res, _ = postdata(
client,
post_entrypoint,
templ_doc_public_martigny_data
)
assert res.status_code == 201
# ensure that pid is removed from records data
assert 'pid' not in res.json['metadata']['data']

# Sion
login_user_via_session(client, system_librarian_sion.user)
Expand Down

0 comments on commit d4bc0a5

Please sign in to comment.