diff --git a/g3w-admin/base/settings/base.py b/g3w-admin/base/settings/base.py index 9b42c437e..fcf39d36d 100644 --- a/g3w-admin/base/settings/base.py +++ b/g3w-admin/base/settings/base.py @@ -48,7 +48,7 @@ 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.gis', - #'django.contrib.sites', + 'django.contrib.sites', ] THIRD_PARTY_APPS = [ @@ -75,7 +75,13 @@ 'about', 'django_bleach', 'django_registration', - 'captcha' + 'captcha', + "allauth", + "allauth.account", + "allauth.socialaccount", + "allauth.socialaccount.providers.microsoft", + "allauth.socialaccount.providers.google", + "allauth.usersessions" ] G3WADMIN_APPS = [ @@ -104,6 +110,10 @@ 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.contrib.sites.middleware.CurrentSiteMiddleware', 'qdjango.process_events_middleware.process_events_middleware', + + # Allauth middleware + 'allauth.account.middleware.AccountMiddleware', + 'allauth.usersessions.middleware.UserSessionsMiddleware' ] @@ -127,10 +137,6 @@ 'loaders': [ 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader' - #('django.template.loaders.cached.Loader', [ - # 'django.template.loaders.filesystem.Loader', - # 'django.template.loaders.app_directories.Loader' - #]), ], }, }, @@ -142,7 +148,6 @@ ATOMIC_REQUESTS = True # Password validation -# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { @@ -162,6 +167,7 @@ AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', 'guardian.backends.ObjectPermissionBackend', + 'allauth.account.auth_backends.AuthenticationBackend' ) GUARDIAN_RAISE_403 = True @@ -241,8 +247,6 @@ # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.9/howto/static-files/ - STATIC_URL = '/static/' SITE_TITLE = 'g3w-admin' @@ -252,7 +256,7 @@ QDJANGO_PRJ_CACHE = True QDJANGO_PRJ_CACHE_KEY = 'qdjango_prj_' -# data for proxy server +# Data for proxy server PROXY_SERVER = False # LOGGING_CONFIG = None @@ -303,7 +307,6 @@ SITE_ID = 1 - INTERNAL_IPS = [ '127.0.0.1', ] @@ -344,7 +347,6 @@ # QPLOTLY DEFAULT SETTINGS # ------------------------ - LOAD_QPLOTLY_FROM_PROJECT = False # VENDOR KEYS SETTINGS @@ -387,4 +389,16 @@ # Settings for ReCaptcha v2. Default checkbox RECAPTCHA_VERSION2_TYPE = 'checkbox' # or 'invisible' -SILENCED_SYSTEM_CHECKS = ['captcha.recaptcha_test_key_error'] \ No newline at end of file +SILENCED_SYSTEM_CHECKS = ['captcha.recaptcha_test_key_error'] + +# SOCIAL ACCOUNT LOGIN SETTINGS +# ----------------------------- +SOCIALACCOUNT_LOGIN_ON_GET = True +SOCIALACCOUNT_ADAPTER = 'usersmanage.vendors.allauth.adapter.G3WSocialAccountAdapter' + +# Activate/deactivate user login session tracking +USERSESSIONS_TRACK_ACTIVITY = False + +SOCIALACCOUNT_ONLY = True +SOCIALACCOUNT_USER_ROLE = 'Viewer Level 1' +ACCOUNT_EMAIL_VERIFICATION = 'none' \ No newline at end of file diff --git a/g3w-admin/base/settings/local_settings_example.py b/g3w-admin/base/settings/local_settings_example.py index c4589d510..4b124f9b3 100644 --- a/g3w-admin/base/settings/local_settings_example.py +++ b/g3w-admin/base/settings/local_settings_example.py @@ -163,3 +163,7 @@ 'worker_type': 'process', }, } + +# For social login +# Activate/deactivate user login session tracking +USERSESSIONS_TRACK_ACTIVITY = False \ No newline at end of file diff --git a/g3w-admin/base/urls.py b/g3w-admin/base/urls.py index 4bea8cf2c..541c84fba 100644 --- a/g3w-admin/base/urls.py +++ b/g3w-admin/base/urls.py @@ -168,8 +168,11 @@ ), name="django_registration_disallowed", ), + path('allauthg/', include('allauth.urls')), ] + + ############################################################# # PASSWORD RESET (user password reset by email) # USERNAME RECOVERY (username recovery by email) diff --git a/g3w-admin/core/utils/vector.py b/g3w-admin/core/utils/vector.py index 2d6a02318..44cc340b6 100644 --- a/g3w-admin/core/utils/vector.py +++ b/g3w-admin/core/utils/vector.py @@ -89,6 +89,15 @@ def get_domain(self): else: return '{}://{}'.format(schema, self.request.get_host()) + def _new_path(self, file_name): + """ Build new path to save media file """ + + return reverse('user-media', kwargs={ + 'project_type': self.type, + 'layer_id': self.layer.pk, + 'file_name': file_name + }) + def new_value(self, change=False): """ Build and save media value from client """ @@ -162,11 +171,17 @@ def new_value(self, change=False): # build new value self.feature_properties[field] = '{}{}'.format(self.get_domain(), - reverse('user-media', kwargs={ - 'project_type': self.type, - 'layer_id': self.layer.pk, - 'file_name': file_name - })) + self._new_path(file_name)) + else: + if is_media_view: + + value = current_field_value + # Try to fix old record saved with temp_uploads path + if os.path.exists(path_file_to_save): + value = self._new_path(file_name) + + # Restore to current_feature value + self.feature_properties[field] = value if delete_old: to_delete = '{}/{}'.format(path_to_save, current_file_name) diff --git a/g3w-admin/qplotly/utils/qplotly_factory.py b/g3w-admin/qplotly/utils/qplotly_factory.py index 6ba862235..971433ecf 100644 --- a/g3w-admin/qplotly/utils/qplotly_factory.py +++ b/g3w-admin/qplotly/utils/qplotly_factory.py @@ -44,6 +44,12 @@ GeoConstraintsFilter, ) +from qgis.PyQt.QtCore import ( + QDate, + QDateTime, + QTime +) + class QplotlyFactoring(PlotFactory): @@ -92,6 +98,22 @@ def build_layout(self): self.layout = self._build_layout() + def _pyqt2py(self, value): + """ + Check if the value is a PyQT object and translate it in native python object + """ + + tp = type(value) + if tp in (QDate, QDateTime, QTime): + if tp == QDate: + value = value.toPyDate() + if tp == QDateTime: + value = value.toPyDateTime() + if tp == QTime: + value = value.toPyTime() + + return value + def fetch_values_from_layer(self): """ (Re)fetches plot values from the source layer. @@ -238,7 +260,7 @@ def add_source_field_or_expression(field_or_expression): if x == NULL or x is None: continue elif self.settings.properties['x_name']: - x = f[self.settings.properties['x_name']] + x = self._pyqt2py(f[self.settings.properties['x_name']]) if x == NULL or x is None: continue @@ -248,7 +270,7 @@ def add_source_field_or_expression(field_or_expression): if y == NULL or y is None: continue elif self.settings.properties['y_name']: - y = f[self.settings.properties['y_name']] + y = self._pyqt2py(f[self.settings.properties['y_name']]) if y == NULL or y is None: continue @@ -258,7 +280,7 @@ def add_source_field_or_expression(field_or_expression): if z == NULL or z is None: continue elif self.settings.properties['z_name']: - z = f[self.settings.properties['z_name']] + z = self._pyqt2py(f[self.settings.properties['z_name']]) if z == NULL or z is None: continue diff --git a/g3w-admin/templates/login.html b/g3w-admin/templates/login.html index f66ccc7de..78c0fc87f 100644 --- a/g3w-admin/templates/login.html +++ b/g3w-admin/templates/login.html @@ -1,4 +1,5 @@ {% extends "base_login.html" %} +{% load socialaccount %} {% load static %} {% load i18n %} @@ -22,42 +23,47 @@