You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2022/01/12 20:25:16 UTC

[airavata-django-portal] branch develop updated: AIRAVATA-3319 Only send email to admin when username is not the same as email and it is invalid

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git


The following commit(s) were added to refs/heads/develop by this push:
     new 120a3ad  AIRAVATA-3319 Only send email to admin when username is not the same as email and it is invalid
120a3ad is described below

commit 120a3ad8ae6b8d613d446bdba21cacc1800d246b
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Jan 12 15:23:59 2022 -0500

    AIRAVATA-3319 Only send email to admin when username is not the same as email and it is invalid
---
 .../src/components/users/UserDetailsContainer.vue             |  1 +
 django_airavata/apps/auth/backends.py                         |  2 +-
 django_airavata/apps/auth/models.py                           |  3 +--
 django_airavata/apps/auth/utils.py                            | 11 ++++++-----
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/UserDetailsContainer.vue b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/UserDetailsContainer.vue
index bc27702..d735160 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/UserDetailsContainer.vue
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/UserDetailsContainer.vue
@@ -60,6 +60,7 @@
         they can complete their user profile.
       </b-alert>
       <change-username-panel
+        v-if="isUsernameInvalid"
         :username="iamUserProfile.userId"
         :email="iamUserProfile.email"
         :airavata-user-profile-exists="iamUserProfile.airavataUserProfileExists"
diff --git a/django_airavata/apps/auth/backends.py b/django_airavata/apps/auth/backends.py
index b6e6edf..3a59fb6 100644
--- a/django_airavata/apps/auth/backends.py
+++ b/django_airavata/apps/auth/backends.py
@@ -330,7 +330,7 @@ class KeycloakBackend(object):
 
         # TODO: also check idp_userinfo.preferred_username if it exists
 
-        if not user_profile.username_initialized:
+        if not user_profile.username_initialized and not user_profile.is_username_valid:
             try:
                 utils.send_admin_alert_about_uninitialized_username(
                     request, user.username, user.email, user.first_name, user.last_name)
diff --git a/django_airavata/apps/auth/models.py b/django_airavata/apps/auth/models.py
index 65ee94e..54395e0 100644
--- a/django_airavata/apps/auth/models.py
+++ b/django_airavata/apps/auth/models.py
@@ -74,8 +74,7 @@ class UserProfile(models.Model):
         if self.username_initialized:
             return True
 
-        # use forms.USERNAME_VALIDATOR with an exception when the username is
-        # equal to the email
+        # use forms.USERNAME_VALIDATOR
         try:
             forms.USERNAME_VALIDATOR(self.user.username)
             validates = True
diff --git a/django_airavata/apps/auth/utils.py b/django_airavata/apps/auth/utils.py
index 7c29731..d7ebda8 100644
--- a/django_airavata/apps/auth/utils.py
+++ b/django_airavata/apps/auth/utils.py
@@ -166,11 +166,12 @@ def send_admin_alert_about_uninitialized_username(request, username, email, firs
     <p>Email: {{email}}</p>
 
     <p>
-    This likely happened because there was no appropriate user attribute to use
-    for the user's username when the user logged in through an external identity
-    provider.  Please update the username to the user's email address or some
-    other appropriate value in the <a href="https://{{http_host}}/admin/users/">Manage
-    Users</a> view in the portal.
+    This likely happened because there was no appropriate user attribute
+    (typically email address) to use for the user's username when the user
+    logged in through an external identity provider.  Please update the username
+    to the user's email address or some other appropriate value in the <a
+    href="https://{{http_host}}/admin/users/">Manage Users</a> view in the
+    portal.
     </p>
     """.strip()).render(context)
     msg = EmailMessage(subject=subject,