Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

organisation: standardize name #199

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data/complete_document_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"Note 1",
"Note 2"
],
"institution": {
"$ref": "https://sonar.ch/api/institutions/org"
"organisation": {
"$ref": "https://sonar.ch/api/organisations/org"
}
}
16 changes: 8 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@
],
'invenio_base.api_apps': [
'documents = sonar.modules.documents:Documents',
'institutions = sonar.modules.institutions:Institutions',
'organisations = sonar.modules.organisations:Organisations',
'sonar = sonar.modules:Sonar'
],
'invenio_jsonschemas.schemas': [
'documents = sonar.modules.documents.jsonschemas',
'institutions = sonar.modules.institutions.jsonschemas',
'organisations = sonar.modules.organisations.jsonschemas',
'users = sonar.modules.users.jsonschemas',
'deposits = sonar.modules.deposits.jsonschemas',
'common = sonar.common.jsonschemas'
],
'invenio_search.mappings': [
'documents = sonar.modules.documents.mappings',
'institutions = sonar.modules.institutions.mappings',
'organisations = sonar.modules.organisations.mappings',
'users = sonar.modules.users.mappings',
'deposits = sonar.modules.deposits.mappings'
],
Expand All @@ -113,8 +113,8 @@
'invenio_pidstore.minters': [
'document_id = \
sonar.modules.documents.api:document_pid_minter',
'institution_id = \
sonar.modules.institutions.api:institution_pid_minter',
'organisation_id = \
sonar.modules.organisations.api:organisation_pid_minter',
'user_id = \
sonar.modules.users.api:user_pid_minter',
'deposit_id = \
Expand All @@ -123,15 +123,15 @@
'invenio_pidstore.fetchers': [
'document_id = \
sonar.modules.documents.api:document_pid_fetcher',
'institution_id = \
sonar.modules.institutions.api:institution_pid_fetcher',
'organisation_id = \
sonar.modules.organisations.api:organisation_pid_fetcher',
'user_id = \
sonar.modules.users.api:user_pid_fetcher',
'deposit_id = \
sonar.modules.deposits.api:deposit_pid_fetcher'
],
"invenio_records.jsonresolver": [
"institution = sonar.modules.institutions.jsonresolvers",
"organisation = sonar.modules.organisations.jsonresolvers",
"user = sonar.modules.users.jsonresolvers",
"document = sonar.modules.documents.jsonresolvers"
],
Expand Down
33 changes: 17 additions & 16 deletions sonar/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

from sonar.modules.deposits.api import DepositRecord, DepositSearch
from sonar.modules.documents.api import DocumentRecord, DocumentSearch
from sonar.modules.institutions.api import InstitutionRecord, InstitutionSearch
from sonar.modules.organisations.api import OrganisationRecord, \
OrganisationSearch
from sonar.modules.permissions import can_create_record_factory, \
can_delete_record_factory, can_list_record_factory, \
can_read_record_factory, can_update_record_factory, wiki_edit_permission
Expand Down Expand Up @@ -240,7 +241,7 @@ def _(x):
RECORDS_UI_ENDPOINTS = {
'document': {
'pid_type': 'doc',
'route': '/organization/<ir>/documents/<pid_value>',
'route': '/organisation/<ir>/documents/<pid_value>',
'view_imp': 'sonar.modules.documents.views:detail'
},
'doc_previewer': {
Expand Down Expand Up @@ -304,30 +305,30 @@ def _(x):
update_permission_factory_imp=can_update_record_factory,
delete_permission_factory_imp=can_delete_record_factory,
list_permission_factory_imp=can_list_record_factory),
'inst':
dict(pid_type='inst',
pid_minter='institution_id',
pid_fetcher='institution_id',
'org':
dict(pid_type='org',
pid_minter='organisation_id',
pid_fetcher='organisation_id',
default_endpoint_prefix=True,
record_class=InstitutionRecord,
search_class=InstitutionSearch,
record_class=OrganisationRecord,
search_class=OrganisationSearch,
indexer_class=RecordIndexer,
search_index='institutions',
search_index='organisations',
search_type=None,
record_serializers={
'application/json': ('sonar.modules.institutions.serializers'
'application/json': ('sonar.modules.organisations.serializers'
':json_v1_response'),
},
search_serializers={
'application/json': ('sonar.modules.institutions.serializers'
'application/json': ('sonar.modules.organisations.serializers'
':json_v1_search'),
},
record_loaders={
'application/json': ('sonar.modules.institutions.loaders'
'application/json': ('sonar.modules.organisations.loaders'
':json_v1'),
},
list_route='/institutions/',
item_route='/institutions/<pid(inst):pid_value>',
list_route='/organisations/',
item_route='/organisations/<pid(org):pid_value>',
default_media_type='application/json',
max_result_window=10000,
error_handlers=dict(),
Expand Down Expand Up @@ -403,13 +404,13 @@ def _(x):
RECORDS_REST_FACETS = {
'documents':
dict(aggs=dict(
institution=dict(terms=dict(field='institution.pid')),
organisation=dict(terms=dict(field='organisation.pid')),
language=dict(terms=dict(field='language.value')),
subject=dict(terms=dict(field='facet_subjects')),
specific_collections=dict(terms=dict(field='specificCollections')),
document_type=dict(terms=dict(field='documentType'))),
filters={
_('institution'): terms_filter('institution.pid'),
_('organisation'): terms_filter('organisation.pid'),
_('language'): terms_filter('language.value'),
_('subject'): terms_filter('facet_subjects'),
_('specific_collections'): terms_filter('specificCollections'),
Expand Down
4 changes: 2 additions & 2 deletions sonar/modules/deposits/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def create_document(self):
if file.get('embargo', False) and file.get('embargoDate'):
kwargs['embargo_date'] = file['embargoDate']

if file.get('exceptInInstitution'):
kwargs['restricted'] = 'institution'
if file.get('exceptInOrganisation'):
kwargs['restricted'] = 'organisation'

document.add_file(content, file['key'], **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
"format": "date",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}?$"
},
"exceptInInstitution": {
"title": "Except within institution",
"exceptInOrganisation": {
"title": "Except within organisation",
"type": "boolean",
"default": false
}
Expand Down Expand Up @@ -354,7 +354,7 @@
},
"specificCollections": {
"title": "Specific collections",
"description": "The names of the institution's specific/patrimonial collections to which this document belongs",
"description": "The names of the organisation's specific/patrimonial collections to which this document belongs",
"type": "array",
"items": {
"type": "string",
Expand Down
8 changes: 4 additions & 4 deletions sonar/modules/documents/cli/rerodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,25 @@ def save_records(ids):
if matches:
# If status if RERO or INTERNAL, file must not be
# displayed, otherwise file is restricted within
# institution
# organisation
if matches.group(1) in ['RERO', 'INTERNAL']:
current_app.logger.warning(
'Access restricted to {status} for file '
'{record}'.format(status=matches.group(1),
record=row))
record_file['restricted'] = 'internal'
else:
record_file['restricted'] = 'institution'
record_file['restricted'] = 'organisation'
else:
# permissions contains a date
matches = re.search(
r'allow roles \/\.\*,(\w+),\.\*\/\n\s+.+(\d{4}-'
r'\d{2}-\d{2})', row[1])

if matches:
# file is restricted to institution
# file is restricted to organisation
if matches.group(1) != 'INTERNAL':
record_file['restricted'] = 'institution'
record_file['restricted'] = 'organisation'

record_file['embargo_date'] = matches.group(2)

Expand Down
4 changes: 2 additions & 2 deletions sonar/modules/documents/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
SONAR_DOCUMENTS_GENERATE_THUMBNAIL = True
"""Automatically generate a thumbnail when a file is imported."""

SONAR_DOCUMENTS_INSTITUTIONS_EXTERNAL_FILES = ['csal']
"""Display external files URL for these institutions."""
SONAR_DOCUMENTS_ORGANISATIONS_EXTERNAL_FILES = ['csal']
"""Display external files URL for these organisations."""
21 changes: 11 additions & 10 deletions sonar/modules/documents/dojson/rerodoc/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from sonar.modules.documents.api import DocumentRecord
from sonar.modules.documents.dojson.rerodoc.overdo import Overdo
from sonar.modules.institutions.api import InstitutionRecord
from sonar.modules.organisations.api import OrganisationRecord
from sonar.modules.utils import remove_trailing_punctuation

marc21tojson = Overdo()
Expand Down Expand Up @@ -53,18 +53,19 @@

@marc21tojson.over('type', '^980')
@utils.ignore_value
def marc21_to_type_and_institution(self, key, value):
"""Get document type and institution from 980 field."""
# institution
def marc21_to_type_and_organisation(self, key, value):
"""Get document type and organisation from 980 field."""
# organisation
if value.get('b'):
institution = value.get('b').lower()
organisation = value.get('b').lower()

if institution not in marc21tojson.registererd_organizations:
marc21tojson.create_institution(institution)
marc21tojson.registererd_organizations.append(institution)
if organisation not in marc21tojson.registererd_organisations:
marc21tojson.create_organisation(organisation)
marc21tojson.registererd_organisations.append(organisation)

self['institution'] = {
'$ref': InstitutionRecord.get_ref_link('institutions', institution)
self['organisation'] = {
'$ref': OrganisationRecord.get_ref_link('organisations',
organisation)
}

# get doc type by mapping
Expand Down
28 changes: 14 additions & 14 deletions sonar/modules/documents/dojson/rerodoc/overdo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,35 @@
from flask import current_app

from sonar.modules.documents.dojson.overdo import Overdo as BaseOverdo
from sonar.modules.institutions.api import InstitutionRecord
from sonar.modules.organisations.api import OrganisationRecord


class Overdo(BaseOverdo):
"""Overdo specialized class for RERODOC DOJSON transformation."""

registererd_organizations = []
registererd_organisations = []

@staticmethod
def create_institution(institution_key):
"""Create institution if not existing and return it.
def create_organisation(organisation_key):
"""Create organisation if not existing and return it.

:param str institution_key: Key (PID) of the institution.
:param str organisation_key: Key (PID) of the organisation.
"""
if not institution_key:
if not organisation_key:
raise Exception('No key provided')

# Get institution record from database
organization = InstitutionRecord.get_record_by_pid(institution_key)
# Get organisation record from database
organisation = OrganisationRecord.get_record_by_pid(organisation_key)

if not organization:
# Create organization record
organization = InstitutionRecord.create(
if not organisation:
# Create organisation record
organisation = OrganisationRecord.create(
{
'pid': institution_key,
'name': institution_key
'pid': organisation_key,
'name': organisation_key
},
dbcommit=True)
organization.reindex()
organisation.reindex()

@staticmethod
def extract_date(date=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@
"type": "string",
"minLength": 1
},
"institution": {
"title": "Organization",
"description": "Organization linked to document.",
"organisation": {
"title": "Organisation",
"description": "Organisation linked to document.",
"type": "object",
"properties": {
"$ref": {
"title": "Organization",
"title": "Organisation",
"type": "string",
"pattern": "^https://sonar.ch/api/institutions/.*?$",
"pattern": "^https://sonar.ch/api/organisations/.*?$",
"minLength": 1
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"fulltext": {
"type": "text"
},
"institution": {
"organisation": {
"type": "object",
"properties": {
"pid": {
Expand Down
2 changes: 1 addition & 1 deletion sonar/modules/documents/marshmallow/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DocumentMetadataSchemaV1(StrictKeysMixin):
partOf = fields.List(fields.Dict())
abstracts = fields.List(fields.Dict())
contribution = fields.List(fields.Dict())
institution = fields.Dict(dump_only=True)
organisation = fields.Dict(dump_only=True)
_files = fields.Dict(dump_only=True)
language = fields.List(fields.Dict())
copyrightDate = fields.List(fields.String())
Expand Down
4 changes: 2 additions & 2 deletions sonar/modules/documents/templates/documents/record.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
{% set title = record.title[0] | title_format(current_i18n.language) %}

<h1 class="text-primary">{{ title }}</h1>
{% if record.institution %}
<h5 class="text-secondary">{{ _(record.institution.name) }}</h5>
{% if record.organisation %}
<h5 class="text-secondary">{{ _(record.organisation.name) }}</h5>
{% endif %}
<section class="mt-3">
<article class="">
Expand Down
Loading