Skip to content

Commit

Permalink
Merge c0b7945 into 586ca88
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastien Délèze committed Jan 15, 2020
2 parents 586ca88 + c0b7945 commit f52ce72
Show file tree
Hide file tree
Showing 37 changed files with 5,491 additions and 1,126 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ target/
.vscode

# MAC
.DS_Store
.DS_Store

# Generated JSON schema
sonar/modules/documents/jsonschemas/documents/document-v1.0.0.json
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ RUN pip install . && \
invenio webpack create && \
# --unsafe needed because we are running as root
invenio webpack install --unsafe && \
invenio webpack build && \
python ./setup.py compile_catalog
python ./setup.py compile_catalog && \
mkdir ${INVENIO_INSTANCE_PATH}/static/sonar-ui && \
cp ${INVENIO_INSTANCE_PATH}/assets/node_modules/@rero/sonar-ui/dist/sonar/* ${INVENIO_INSTANCE_PATH}/static/sonar-ui

ENTRYPOINT [ "bash", "-c"]
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ recursive-include sonar *.eslintignore
recursive-include tests *.json

recursive-include sonar *.txt

exclude sonar/modules/documents/jsonschemas/documents/document-v1.0.0.json
3 changes: 3 additions & 0 deletions scripts/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ fi
# Copy sonar-ui files to static folder to use it with flask-assets
static_folder=$(pipenv run invenio shell --no-term-title -c "print('static_folder:%s' % app.static_folder)"|grep static_folder| cut -d: -f2-)
cp -R ${assets_folder}/node_modules/@rero/sonar-ui/dist/sonar ${static_folder}/sonar-ui

# Compile json schema
pipenv run invenio utils compile-json ./sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json -o ./sonar/modules/documents/jsonschemas/documents/document-v1.0.0.json
2 changes: 1 addition & 1 deletion scripts/setup
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pipenv run invenio shell --no-term-title -c "import redis; redis.StrictRedis.fro
pipenv run invenio db destroy --yes-i-know
pipenv run invenio db init create
pipenv run invenio index destroy --force --yes-i-know
pipenv run invenio index init --force
pipenv run invenio utils es-init --force # To take templates into account
pipenv run invenio index queue init purge

# Create admin role to restrict access
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
'sonar = invenio_app.cli:cli',
],
'flask.commands': [
'fixtures = sonar.modules.cli:fixtures'
'fixtures = sonar.modules.cli:fixtures',
'utils = sonar.modules.cli:utils'
],
'invenio_base.apps': [
'sonar = sonar.modules:Sonar'
Expand Down Expand Up @@ -98,6 +99,9 @@
'users = sonar.modules.users.mappings',
'deposits = sonar.modules.deposits.mappings'
],
'invenio_search.templates': [
'base-record = sonar.es_templates:list_es_templates'
],
'invenio_pidstore.minters': [
'document_id = \
sonar.modules.documents.api:document_pid_minter',
Expand Down
34 changes: 15 additions & 19 deletions sonar/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ def _(x):
'content_security_policy': {
'default-src': ["'self'"],
'object-src': ["'none'"],
'script-src': [
"'self'", "'unsafe-inline'", 'https://code.jquery.com',
'https://cdnjs.cloudflare.com',
'https://stackpath.bootstrapcdn.com'
],
'style-src': [
"'self'", "'unsafe-inline'", 'https://cdnjs.cloudflare.com',
'https://fonts.googleapis.com'
Expand Down Expand Up @@ -213,21 +218,6 @@ def _(x):

PIDSTORE_RECID_FIELD = 'pid'

SEARCH_UI_SEARCH_INDEX = 'documents'
SEARCH_UI_SEARCH_API = '/api/documents/'
SEARCH_UI_SEARCH_TEMPLATE = 'sonar/search.html'

SEARCH_UI_JSTEMPLATE_RESULTS = 'templates/documents/search_ui/results.html'
SEARCH_UI_JSTEMPLATE_COUNT = 'templates/documents/search_ui/count.html'
SEARCH_UI_JSTEMPLATE_PAGINATION = 'templates/documents/search_ui/'\
'pagination.html'
SEARCH_UI_JSTEMPLATE_SORT_ORDER = 'templates/documents/search_ui/'\
'sort_order.html'
SEARCH_UI_JSTEMPLATE_SELECT_BOX = 'templates/documents/search_ui/'\
'select_box.html'
SEARCH_UI_JSTEMPLATE_LOADING = 'templates/documents/search_ui/loading.html'
SEARCH_UI_JSTEMPLATE_FACETS = 'templates/documents/search_ui/facets.html'

SECURITY_LOGIN_USER_TEMPLATE = 'sonar/accounts/login.html'
SECURITY_FORGOT_PASSWORD_TEMPLATE = 'sonar/accounts/forgot_password.html'
SECURITY_REGISTER_USER_TEMPLATE = 'sonar/accounts/signup.html'
Expand Down Expand Up @@ -377,13 +367,19 @@ def _(x):
RECORDS_REST_FACETS = {
'documents':
dict(aggs=dict(institution=dict(terms=dict(field='institution.pid')),
language=dict(terms=dict(field='languages.name')),
author=dict(terms=dict(field='facet_authors')),
language=dict(terms=dict(field='language.value')),
author__en=dict(terms=dict(field='facet_authors_en')),
author__fr=dict(terms=dict(field='facet_authors_fr')),
author__de=dict(terms=dict(field='facet_authors_de')),
author__it=dict(terms=dict(field='facet_authors_it')),
subject=dict(terms=dict(field='facet_subjects'))),
filters={
_('institution'): terms_filter('institution.pid'),
_('language'): terms_filter('languages.name'),
_('author'): terms_filter('facet_authors'),
_('language'): terms_filter('language.value'),
_('author__en'): terms_filter('facet_authors_en'),
_('author__fr'): terms_filter('facet_authors_fr'),
_('author__de'): terms_filter('facet_authors_de'),
_('author__it'): terms_filter('facet_authors_it'),
_('subject'): terms_filter('facet_subjects'),
}),
'deposits':
Expand Down
25 changes: 25 additions & 0 deletions sonar/es_templates/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
#
# Swiss Open Access Repository
# 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/>.

"""Records Templates Elasticsearch."""


def list_es_templates():
"""Elasticsearch Templates path."""
return [
'sonar.es_templates'
]
18 changes: 18 additions & 0 deletions sonar/es_templates/v6/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
#
# Swiss Open Access Repository
# 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/>.

"""Records Templates Elasticsearch."""
26 changes: 26 additions & 0 deletions sonar/es_templates/v6/record.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"index_patterns": "*",
"settings": {
"analysis": {
"tokenizer": {
"char_group_tokenizer": {
"type": "char_group",
"tokenize_on_chars": [
"whitespace",
"punctuation"
]
}
},
"analyzer": {
"global_lowercase_asciifolding": {
"type": "custom",
"tokenizer": "char_group_tokenizer",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
}
}
47 changes: 47 additions & 0 deletions sonar/modules/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@

"""SONAR CLI commands."""

import json
import sys

import click
import jsonref
from flask.cli import with_appcontext
from invenio_search.cli import es_version_check
from invenio_search.proxies import current_search

from .deposits.cli import deposits
from .documents.cli import documents
Expand All @@ -29,7 +36,47 @@
def fixtures():
"""Fixtures management commands."""


fixtures.add_command(documents)
fixtures.add_command(institutions)
fixtures.add_command(users)
fixtures.add_command(deposits)


@click.group()
def utils():
"""Utils commands."""


@utils.command()
@click.option('--force', is_flag=True, default=False)
@with_appcontext
@es_version_check
def es_init(force):
"""Initialize registered templates, aliases and mappings."""
# TODO: to remove once it is fixed in invenio-search module
click.secho('Putting templates...', fg='green', bold=True, file=sys.stderr)
with click.progressbar(
current_search.put_templates(ignore=[400, 404] if force else None),
length=len(current_search.templates)) as item:
for response in item:
item.label = response
click.secho('Creating indexes...', fg='green', bold=True, file=sys.stderr)
with click.progressbar(
current_search.create(ignore=[400] if force else None),
length=len(current_search.mappings)) as item:
for name, response in item:
item.label = name


@utils.command()
@click.argument('src_json_file', type=click.File('r'))
@click.option('-o', '--output', 'output', type=click.File('w'), default=None)
def compile_json(src_json_file, output):
"""Compile source json file (resolve $ref)."""
click.secho('Compile json file (resolve $ref): ', fg='green', nl=False)
click.secho(src_json_file.name)
data = jsonref.load(src_json_file)
if not output:
output = sys.stdout
json.dump(data, fp=output, indent=2)
2 changes: 2 additions & 0 deletions sonar/modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@
SONAR_APP_DISABLE_PERMISSION_CHECKS = False
"""Disable permission checks during API calls. Useful when API is test from
command line or progams like postman."""

SONAR_APP_UI_VERSION = '0.1.4'
Loading

0 comments on commit f52ce72

Please sign in to comment.