diff --git a/openlcs/authentication/admin.py b/openlcs/authentication/admin.py index a01f2cbc..f889ee30 100644 --- a/openlcs/authentication/admin.py +++ b/openlcs/authentication/admin.py @@ -12,7 +12,7 @@ class RedHatProfileInline(admin.StackedInline): can_delete = True verbose_name_plural = 'RedHatProfile' fk_name = 'user' - fields = ('sub', 'roles', 'full_name') + fields = ('sub', 'full_name') # Define a new User admin diff --git a/openlcs/authentication/backend.py b/openlcs/authentication/backend.py index 1caee3d0..b59f5e6f 100644 --- a/openlcs/authentication/backend.py +++ b/openlcs/authentication/backend.py @@ -17,9 +17,7 @@ 'name', 'given_name', 'family_name', - 'email', - 'groups', - 'realm_access' + 'email' ] @@ -85,14 +83,6 @@ def create_user(self, claims: Any) -> User: # Create a Red Hat Profile for this user redhat_profile = user.redhatprofile redhat_profile.sub = user_detail[0] - # kerberos user exist "groups", but client user exist "realm_access" - if groups := claims.get("groups"): - roles = groups - elif realm_access := claims.get("realm_access"): - roles = realm_access.get("roles") - else: - roles = "" - redhat_profile.roles = roles redhat_profile.full_name = user_detail[2] redhat_profile.save() @@ -102,15 +92,8 @@ def update_user(self, user: User, claims: Any) -> User: """ Update user settings. """ - if groups := claims.get("groups"): - roles = groups - elif realm_access := claims.get("realm_access"): - roles = realm_access.get("roles") - else: - roles = "" RedHatProfile.objects.filter(user=user).update( sub=claims.get("sub", ""), - roles=roles, full_name=claims.get("name", ""), ) return user diff --git a/openlcs/authentication/migrations/0003_remove_redhatprofile_roles.py b/openlcs/authentication/migrations/0003_remove_redhatprofile_roles.py new file mode 100644 index 00000000..97469eb1 --- /dev/null +++ b/openlcs/authentication/migrations/0003_remove_redhatprofile_roles.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.19 on 2023-07-11 08:50 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0002_auto_20230621_1610'), + ] + + operations = [ + migrations.RemoveField( + model_name='redhatprofile', + name='roles', + ), + ] diff --git a/openlcs/authentication/mixins.py b/openlcs/authentication/mixins.py index 17f878cb..37553d4c 100644 --- a/openlcs/authentication/mixins.py +++ b/openlcs/authentication/mixins.py @@ -37,13 +37,6 @@ def get_or_create_user(self, access_token): # Create a Red Hat Profile for this user redhat_profile = user.redhatprofile redhat_profile.sub = claims.get('sub') - if groups := claims.get("groups"): - roles = groups - elif realm_access := claims.get("realm_access"): - roles = realm_access.get("roles") - else: - roles = "" - redhat_profile.roles = roles redhat_profile.full_name = claims.get('name') redhat_profile.save() return user diff --git a/openlcs/authentication/models.py b/openlcs/authentication/models.py index 580aad2e..a1227cf6 100644 --- a/openlcs/authentication/models.py +++ b/openlcs/authentication/models.py @@ -3,7 +3,6 @@ from django.conf import settings from django.db import models from django.contrib.auth import get_user_model -from django.contrib.postgres.fields import ArrayField from django.db.models.signals import post_save User = get_user_model() @@ -19,12 +18,6 @@ class RedHatProfile(models.Model): on_delete=models.CASCADE ) sub = models.UUIDField(default=uuid.uuid4) - roles = ArrayField( - models.CharField(max_length=1024), - default=list, - blank=True, - null=True, - ) # Storing CN instead of trying to split it into Django's given/first/family/last # noqa # bc https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ # noqa full_name = models.CharField(max_length=256, blank=True, null=True) diff --git a/tests/integration/test_autoimport_workflow.py b/tests/integration/test_autoimport_workflow.py index 98748634..db7bcde0 100644 --- a/tests/integration/test_autoimport_workflow.py +++ b/tests/integration/test_autoimport_workflow.py @@ -139,5 +139,6 @@ def test_autoimport_workflow(client): f"mins.", error) # Check if the scan result was synced to corgi + time.sleep(10) # waiting for syncing result to corgi openlcs_scan_url = get_the_openlcs_scan_url(test_data_src) assert os.getenv('OPENLCS_TEST_URL') in openlcs_scan_url