diff --git a/admin_login/azure_backend.py b/admin_login/azure_backend.py index e780b18d9..56e9d55b0 100644 --- a/admin_login/azure_backend.py +++ b/admin_login/azure_backend.py @@ -22,43 +22,6 @@ def authenticate(self, request, username=None, password=None, **kwargs): Authenticate user via Azure AD using username (email) and password. """ pass - # azure_details = get_azure_auth_details() - # - # # Initialize MSAL client - # msal_client = PublicClientApplication( - # client_id=azure_details['client_id'], - # authority=azure_details['authority'], - # ) - # - # # Acquire token using username and password - # try: - # token_data = msal_client.acquire_token_by_username_password( - # username=username, - # password=password, - # scopes=azure_details['scope'] - # ) - # - # if 'access_token' in token_data: - # # Token is valid, retrieve or create the user - # user, created = User.objects.get_or_create( - # email=username, defaults={'username': username} - # ) - # return user - # else: - # return None - # except Exception as e: - # # Log or handle error appropriately - # print(f"Error during Azure AD authentication: {e}") - # return None - # - # def get_user(self, user_id): - # """ - # Retrieve user by their ID. - # """ - # try: - # return User.objects.get(pk=user_id) - # except User.DoesNotExist: - # return None class AzureADSignupService: diff --git a/admin_login/azure_utility.py b/admin_login/azure_utility.py index 473ffcaf7..c91f42bc5 100644 --- a/admin_login/azure_utility.py +++ b/admin_login/azure_utility.py @@ -38,4 +38,5 @@ def payload_for_access_token(code): 'client_secret': azure_details['client_secret'], } - return data \ No newline at end of file + return data + diff --git a/admin_login/views.py b/admin_login/views.py index 3dff26b92..eef393acb 100644 --- a/admin_login/views.py +++ b/admin_login/views.py @@ -9,6 +9,7 @@ from django.views import View from django.utils.decorators import method_decorator from django.contrib.auth.decorators import login_required +from django.core.exceptions import PermissionDenied from admin_login.azure_backend import AzureADSignupService, get_azure_auth_details @@ -16,6 +17,7 @@ # Create your views here. + class AzureADSignupView(View): template_name = 'signup.html' @@ -77,20 +79,18 @@ def _save_user_info(self, user_info): name = user_info.get('name') given_name = user_info.get('given_name') + if not User.objects.filter(email=email, is_active=True, is_superuser=True).exists(): + raise PermissionDenied("Access Denied: You are not allowed to sign up.") # Check if the user already exists user, created = User.objects.get_or_create( email=email, defaults={ - 'username': name, + 'username': email, 'first_name': given_name, 'is_staff': True, # Make the user an admin 'is_superuser': True, # Grant superuser permissions }, ) - if not created: - # Update user details if necessary - user.first_name = given_name - user.save() user.is_superuser = True user.is_staff = True diff --git a/iogt/settings/production.py b/iogt/settings/production.py index 0d8d36e9c..a4585ae7c 100644 --- a/iogt/settings/production.py +++ b/iogt/settings/production.py @@ -33,7 +33,7 @@ }, } -SITE_VERSION = '2.13.7' +SITE_VERSION = '2.13.8' try: from .local import * diff --git a/iogt/urls.py b/iogt/urls.py index 55ecbc15f..769f7edbb 100644 --- a/iogt/urls.py +++ b/iogt/urls.py @@ -49,16 +49,18 @@ urlpatterns = api_url_patterns + [ path('django-admin/', admin.site.urls), - # path('admin/logout/', CustomLogoutView.as_view(), name='admin_logout'), - # path('admin/login/', AzureADSignupView.as_view(), name='azure_signup_view'), # Override Wagtail admin login + path('admin/logout/', CustomLogoutView.as_view(), name='admin_logout'), + path('admin/login/', AzureADSignupView.as_view(), name='azure_signup_view'), # Override Wagtail admin login path('admin/', include(wagtailadmin_urls)), path('documents/', include(wagtaildocs_urls)), + # path('admin-login/', include(admin_login_urls), name='admin_login_urls'), *i18n_patterns(path('logout_hack_view', LogoutRedirectHackView.as_view(), name='logout_redirect')), *i18n_patterns(path('search/', search_views.search, name='search')), *i18n_patterns(path('users/', include(users_urls), name='users_urls')), *i18n_patterns(path('accounts/', include('allauth.urls'), name='allauth-urls')), *i18n_patterns(path('comments/', include('django_comments_xtd.urls'))), *i18n_patterns(path('admin-login/', include(admin_login_urls), name='admin_login_urls')), + path( 'sw.js', pwa_views.ServiceWorkerView.as_view(), diff --git a/iogt_users/templates/wagtailusers/users/index.html b/iogt_users/templates/wagtailusers/users/index.html index 0d4814982..2e54a9cc6 100644 --- a/iogt_users/templates/wagtailusers/users/index.html +++ b/iogt_users/templates/wagtailusers/users/index.html @@ -3,48 +3,67 @@ {% block content %} {% trans "Users" as users_str %} - {% url "wagtailusers_users:add" as add_link %} -
-
-
-
-

- Users -

-
- -
- + {% include "wagtailadmin/shared/header.html" with subtitle=group.name title=users_str action_url=add_link action_text=add_a_user_str icon="user" search_url="wagtailusers_users:index" %} +
+
+ + + + Add a user + +
+
+
+
+ {% include "wagtailusers/users/results.html" %}
-
+ {% trans "Select all users in listing" as select_all_text %} + {% include 'wagtailadmin/bulk_actions/footer.html' with select_all_obj_text=select_all_text app_label=app_label model_name=model_name objects=users %} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - {% endblock %} {% block extra_js %} {{ block.super }} + + + + -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/iogt_users/views.py b/iogt_users/views.py index e4f7a75fe..c9b5df5a3 100644 --- a/iogt_users/views.py +++ b/iogt_users/views.py @@ -68,14 +68,6 @@ def post(self, request, *args, **kwargs): if errors: return JsonResponse({'success': False, 'errors': errors}, status=400) - # If no errors, proceed with sending the invitation email - # Assume `User` is your user model and email is unique - # user, created = User.objects.get_or_create( - # email=email, - # defaults={'first_name': first_name, 'last_name': last_name}, - # username=email - # ) - template_name = "email_service/invite_admin.html" # Your template name invitation_link = request.build_absolute_uri('/admin/login/') @@ -97,6 +89,22 @@ def post(self, request, *args, **kwargs): template_name=template_name, context=context, ) + user, created = User.objects.get_or_create( + email=email, + defaults={ + 'username': email, + 'first_name': first_name, + 'last_name': last_name, + 'is_active': True, + 'is_superuser': True + }, + ) + + if not created: + user.is_active = True + user.is_superuser = True + user.save() + except Exception as e: # Handle any email sending errors return JsonResponse({'success': False, 'message': 'Failed to send invitation.', 'error': str(e)}, diff --git a/matomo/templates/matomo_tracking_tags.html b/matomo/templates/matomo_tracking_tags.html index 941c5a69e..61363a438 100644 --- a/matomo/templates/matomo_tracking_tags.html +++ b/matomo/templates/matomo_tracking_tags.html @@ -1,20 +1,52 @@ + {% if tracking_enabled %} - +