Skip to content

Commit

Permalink
records: integrate angular UI
Browse files Browse the repository at this point in the history
* Integrates sonar-ui admin angular application.
* Adds editor form configuration for documents, institutions and users.
* Adds addresses for user in fixtures.
* Adds a "local" option for bootstrap script.
* Build assets in bootstrap script.
* Removes webpack custom project.
* Modifies JSON schemas.

Co-Authored-by: Sébastien Délèze <sebastien.deleze@rero.ch>
  • Loading branch information
Sébastien Délèze committed Dec 5, 2019
1 parent 32aaf18 commit 34c3793
Show file tree
Hide file tree
Showing 31 changed files with 1,287 additions and 769 deletions.
707 changes: 362 additions & 345 deletions Pipfile.lock

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion data/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@
"last_name": "Mueller",
"email": "rero.sonar+superadmin@gmail.com",
"password": "123456",
"roles": ["superadmin"]
"roles": ["superadmin"],
"birth_date": "1978-03-09",
"street": "Sonnenbergstr 39",
"postal_code": "6544",
"city": "Braggio",
"phone": "+41916658961"
},
{
"first_name": "Elia",
"last_name": "Rossi",
"email": "rero.sonar+admin@gmail.com",
"password": "123456",
"roles": ["admin"],
"birth_date": "1971-12-01",
"street": "Brunnacherstrasse 112",
"postal_code": "5330",
"city": "Zurzach",
"phone": "+41625037543",
"institution": {
"$ref": "https://sonar.ch/api/institutions/usi"
}
Expand All @@ -22,6 +32,11 @@
"email": "rero.sonar+moderator@gmail.com",
"password": "123456",
"roles": ["moderator"],
"birth_date": "1964-10-10",
"street": "Lichtmattstrasse 123",
"postal_code": "5736",
"city": "Burg",
"phone": "+41627676171",
"institution": {
"$ref": "https://sonar.ch/api/institutions/usi"
}
Expand All @@ -32,6 +47,11 @@
"email": "rero.sonar+user@gmail.com",
"password": "123456",
"roles": ["user"],
"birth_date": "1984-04-20",
"street": "Rasenstrasse 2",
"postal_code": "4577",
"city": "Hessigkofen",
"phone": "+41323666556",
"institution": {
"$ref": "https://sonar.ch/api/institutions/usi"
}
Expand Down
43 changes: 41 additions & 2 deletions scripts/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@

set -e

local=false
while test $# -gt 0; do
case "$1" in
--local)
local=true
shift
;;
esac
done


script_path=$(dirname "$0")
pipfile_lock_path="$script_path/../Pipfile.lock"
cwd=`pwd`

if [ ! -f $pipfile_lock_path ]; then
echo "'Pipfile.lock' not found. Generating via 'pipenv lock --dev'..."
Expand All @@ -31,8 +42,36 @@ fi
pipenv sync --dev
# Install application code and entrypoints from 'setup.py'
pipenv run pip install -e $script_path/..
# Build assets
# Build webpack assets
pipenv run invenio collect -v
pipenv run invenio webpack buildall

assets_folder=$(pipenv run invenio shell --no-term-title -c "print(app.config.get('WEBPACKEXT_PROJECT_BUILDDIR'))")

if ! $local; then
pipenv run invenio webpack buildall
else
pipenv run invenio webpack create
pipenv run invenio webpack install
cd $assets_folder
if ! npm link @rero/sonar-ui; then
echo "ERROR: npm link failed"
exit 1
fi
cd ${cwd}
pipenv run invenio webpack build
fi

# Build assets
# Get static folder
static_folder=$(pipenv run invenio shell --no-term-title -c "print('static_folder:%s' % app.static_folder)"|grep static_folder| cut -d: -f2-)

# Create package.json
pipenv run invenio npm

# install the npm dependencies
virtualenv_path=`pipenv --venv`
pipenv run npm install --prefix "${virtualenv_path}" --silent -g node-sass@4.9.0 clean-css@3.4.19 uglify-js@2.7.3 requirejs@2.2.0
pipenv run npm install --prefix "${static_folder}"

# build the web assets
pipenv run invenio assets build
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@
sonar.modules.pdf_extractor.views.client:blueprint'
],
'invenio_base.api_blueprints': [
'sonar = sonar.theme.api_views:blueprint',
'pdf_extractor = sonar.modules.pdf_extractor.views.api:blueprint'
],
'invenio_assets.webpack': [
'sonar_theme = sonar.theme.webpack:theme',
'sonar_theme = sonar.theme.webpack:theme'
],
'invenio_assets.bundles': [
'admin_ui_js = sonar.bundles:admin_ui_js',
'admin_ui_css = sonar.bundles:admin_ui_css'
],
'invenio_config.module': [
'sonar = sonar.config',
Expand Down
40 changes: 40 additions & 0 deletions sonar/bundles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- 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/>.

"""JS/CSS bundles for RERO ILS theme."""

from __future__ import absolute_import

from invenio_assets import NpmBundle

admin_ui_js = NpmBundle(
'node_modules/@rero/sonar-ui/dist/admin/runtime.js',
'node_modules/@rero/sonar-ui/dist/admin/polyfills.js',
'node_modules/@rero/sonar-ui/dist/admin/main.js',
output='admin_ui.%(version)s.js',
npm={
'@rero/sonar-ui': '~0.0.1'
}
)

admin_ui_css = NpmBundle(
'node_modules/@rero/sonar-ui/dist/admin/styles.css',
output='admin_ui.%(version)s.css',
npm={
'@rero/sonar-ui': '~0.0.1'
}
)
75 changes: 55 additions & 20 deletions sonar/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,39 @@ def _(x):
#: route correct hosts to the application.
APP_ALLOWED_HOSTS = ['sonar.ch', 'localhost', '127.0.0.1']

APP_DEFAULT_SECURE_HEADERS = {
'force_https': True,
'force_https_permanent': False,
'force_file_save': False,
'frame_options': 'sameorigin',
'frame_options_allow_from': None,
'strict_transport_security': True,
'strict_transport_security_preload': False,
'strict_transport_security_max_age': 31556926, # One year in seconds
'strict_transport_security_include_subdomains': True,
'content_security_policy': {
'default-src': ["'self'"],
'object-src': ["'none'"],
'style-src': [
"'self'",
"'unsafe-inline'",
'https://cdnjs.cloudflare.com',
'https://fonts.googleapis.com'
],
'font-src': [
"'self'",
"'unsafe-inline'",
'https://cdnjs.cloudflare.com',
'https://fonts.gstatic.com'
]
},
'content_security_policy_report_uri': None,
'content_security_policy_report_only': False,
'session_cookie_secure': True,
'session_cookie_http_only': True
}
"""Talisman default Secure Headers configuration."""


# OAI-PMH
# =======
Expand Down Expand Up @@ -230,17 +263,17 @@ def _(x):
search_index='documents',
search_type=None,
record_serializers={
'application/json': ('sonar.modules.documents.serializers'
'application/json': ('invenio_records_rest.serializers'
':json_v1_response'),
},
search_serializers={
'application/json': ('sonar.modules.documents.serializers'
'application/json': ('invenio_records_rest.serializers'
':json_v1_search'),
},
record_loaders={
'application/json': ('sonar.modules.documents.loaders'
':json_v1'),
},
# record_loaders={
# 'application/json': ('sonar.modules.documents.loaders'
# ':json_v1'),
# },
list_route='/documents/',
item_route='/documents/<pid(doc):pid_value>',
default_media_type='application/json',
Expand All @@ -263,17 +296,17 @@ def _(x):
search_index='institutions',
search_type=None,
record_serializers={
'application/json': ('sonar.modules.institutions.serializers'
'application/json': ('invenio_records_rest.serializers'
':json_v1_response'),
},
search_serializers={
'application/json': ('sonar.modules.institutions.serializers'
'application/json': ('invenio_records_rest.serializers'
':json_v1_search'),
},
record_loaders={
'application/json': ('sonar.modules.institutions.loaders'
':json_v1'),
},
# record_loaders={
# 'application/json': ('sonar.modules.institutions.loaders'
# ':json_v1'),
# },
list_route='/institutions/',
item_route='/institutions/<pid(inst):pid_value>',
default_media_type='application/json',
Expand All @@ -296,17 +329,17 @@ def _(x):
search_index='users',
search_type=None,
record_serializers={
'application/json': ('sonar.modules.users.serializers'
'application/json': ('invenio_records_rest.serializers'
':json_v1_response'),
},
search_serializers={
'application/json': ('sonar.modules.users.serializers'
'application/json': ('invenio_records_rest.serializers'
':json_v1_search'),
},
record_loaders={
'application/json': ('sonar.modules.users.loaders'
':json_v1'),
},
# record_loaders={
# 'application/json': ('sonar.modules.users.loaders'
# ':json_v1'),
# },
list_route='/users/',
item_route='/users/<pid(user):pid_value>',
default_media_type='application/json',
Expand Down Expand Up @@ -423,9 +456,11 @@ def _(x):
)
)

WEBPACKEXT_PROJECT = 'sonar.theme.webpack:project'

# Admin layout
# =========================
ADMIN_BASE_TEMPLATE = 'sonar/page_admin.html'
ADMIN_PERMISSION_FACTORY = 'sonar.modules.permissions.admin_permission_factory'

REST_ENABLE_CORS = True
"""Enable CORS to make it possible to do request to API from other
applications."""
2 changes: 2 additions & 0 deletions sonar/modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@
por='pt',
rus='ru'
)

SONAR_APP_ENABLE_CORS = True
16 changes: 11 additions & 5 deletions sonar/modules/documents/jsonschemas/documents/document-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"title": "Authors",
"description": "Author(s) of the resource. Can be either persons or organisations.",
"type": "array",
"minItems": 0,
"minItems": 1,
"items": {
"type": "object",
"required": [
Expand Down Expand Up @@ -226,7 +226,11 @@
"title": "Subjects list",
"description": "A list of subjects.",
"type": "array",
"minLength": 1
"minLength": 1,
"items": {
"type": "string",
"title": "Subject"
}
}
}
}
Expand All @@ -242,12 +246,14 @@
}
},
"institution": {
"title": "Institution",
"description": "Institution linked to document.",
"title": "Organization",
"description": "Organization linked to document.",
"type": "object",
"properties": {
"$ref": {
"type": "string"
"title": "Organization",
"type": "string",
"pattern": "^https://sonar.ch/api/institutions/.*?$"
}
},
"required": ["$ref"]
Expand Down
Loading

0 comments on commit 34c3793

Please sign in to comment.