diff --git a/sonar/config.py b/sonar/config.py
index 2d056797..2b0729d8 100644
--- a/sonar/config.py
+++ b/sonar/config.py
@@ -128,7 +128,7 @@ def _(x):
# User profiles
# =============
-USERPROFILES_EXTEND_SECURITY_FORMS = True
+USERPROFILES = False
# Celery configuration
# ====================
diff --git a/sonar/modules/ext.py b/sonar/modules/ext.py
index e3338cdf..8c0e9cf6 100644
--- a/sonar/modules/ext.py
+++ b/sonar/modules/ext.py
@@ -22,10 +22,13 @@
import jinja2
from flask_assets import Bundle, Environment
from flask_bootstrap import Bootstrap
+from flask_security import user_registered
from flask_wiki import Wiki
from sonar.modules.permissions import has_admin_access, has_publisher_access, \
has_superuser_access
+from sonar.modules.users.api import current_user_record
+from sonar.modules.users.signals import user_registered_handler
from sonar.modules.utils import get_switch_aai_providers, get_view_code
from . import config
@@ -39,7 +42,8 @@ def utility_processor():
has_superuser_access=has_superuser_access,
ui_version=config.SONAR_APP_UI_VERSION,
aai_providers=get_switch_aai_providers,
- view_code=get_view_code())
+ view_code=get_view_code(),
+ current_user_record=current_user_record)
class Sonar(object):
@@ -82,6 +86,9 @@ def init_app(self, app):
app.context_processor(utility_processor)
+ # Connect to signal sent when a user is created in Flask-Security.
+ user_registered.connect(user_registered_handler, weak=False)
+
def init_config(self, app):
"""Initialize configuration."""
for k in dir(config):
diff --git a/sonar/modules/users/cli.py b/sonar/modules/users/cli.py
index 581bd40c..f7f1342b 100644
--- a/sonar/modules/users/cli.py
+++ b/sonar/modules/users/cli.py
@@ -67,9 +67,15 @@ def import_users(infile):
password = hash_password(password)
del user_data['password']
+ if not user_data.get('roles'):
+ user_data['roles'] = [UserRecord.ROLE_USER]
+
roles = user_data.get('roles', []).copy()
- if not roles or not isinstance(roles, list):
- roles = []
+
+ for role in roles:
+ if not datastore.find_role(role):
+ datastore.create_role(name=role)
+ datastore.commit()
# Create account and activate it
datastore.create_user(email=email, password=password, roles=roles)
diff --git a/sonar/modules/users/jsonschemas/users/user-v1.0.0.json b/sonar/modules/users/jsonschemas/users/user-v1.0.0.json
index 55b172aa..f36239a3 100644
--- a/sonar/modules/users/jsonschemas/users/user-v1.0.0.json
+++ b/sonar/modules/users/jsonschemas/users/user-v1.0.0.json
@@ -142,7 +142,6 @@
"full_name",
"email",
"roles",
- "organisation",
"$schema"
]
}
diff --git a/sonar/modules/users/signals.py b/sonar/modules/users/signals.py
new file mode 100644
index 00000000..edf2ec49
--- /dev/null
+++ b/sonar/modules/users/signals.py
@@ -0,0 +1,44 @@
+# -*- 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