From f8506c322074edb907eb2163f1dbcd0dc01d5f97 Mon Sep 17 00:00:00 2001 From: Omar Al-Ithawi Date: Wed, 2 Jun 2021 14:38:59 +0300 Subject: [PATCH] Remove unused SiteMemberBackend and its model The SiteMemberBackend and the model UserSiteMapping were added in 2016 but never used. In Tahoe we always use UserOrganizationMapping and its backend. The two backends are sort-of redaudant and adds maintainance cost even if its very small. --- organizations/backends.py | 22 ------------------- .../migrations/0012_delete_usersitemapping.py | 16 ++++++++++++++ organizations/models.py | 13 ----------- 3 files changed, 16 insertions(+), 35 deletions(-) create mode 100644 organizations/migrations/0012_delete_usersitemapping.py diff --git a/organizations/backends.py b/organizations/backends.py index e23d6a36..4d0164cd 100644 --- a/organizations/backends.py +++ b/organizations/backends.py @@ -70,25 +70,3 @@ def authenticate(self, *args, **kwargs): # pylint: disable=arguments-differ if site_organization in user_organizations: return user return None - - -class SiteMemberBackend(ModelBackend): - """ - Extension of the regular ModelBackend that will check whether the user is a member of the currently - active site. - - Deprecated: Should be removed because `UserSiteMapping` should be removed. - """ - - def authenticate(self, *args, **kwargs): # pylint: disable=arguments-differ - """ - Authenticate organization learners. - """ - user = super(SiteMemberBackend, self).authenticate(*args, **kwargs) - # superuser can log into any microsite - site = get_current_site() - is_default_site = site.id == settings.SITE_ID - if not is_default_site and is_site_configuration_enabled() and user and not user.is_superuser: - if user.id in site.usersitemapping_set.select_related('user').values_list('user__id', flat=True): - return user - return None diff --git a/organizations/migrations/0012_delete_usersitemapping.py b/organizations/migrations/0012_delete_usersitemapping.py new file mode 100644 index 00000000..bc081192 --- /dev/null +++ b/organizations/migrations/0012_delete_usersitemapping.py @@ -0,0 +1,16 @@ +# Generated by Django 2.2.12 on 2021-06-02 06:38 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('organizations', '0011_historicalorganization_edx_uuid'), + ] + + operations = [ + migrations.DeleteModel( + name='UserSiteMapping', + ), + ] diff --git a/organizations/models.py b/organizations/models.py index 1109aa52..686847e4 100644 --- a/organizations/models.py +++ b/organizations/models.py @@ -121,16 +121,3 @@ def __str__(self): email=self.user.email, # pylint: disable=no-member organization=org.short_name, ) - - -class UserSiteMapping(models.Model): - """ - User membership in a site. - - Deprecated: Not used by Tahoe. Should be removed. - """ - - user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) - site = models.ForeignKey(Site, on_delete=models.CASCADE) - is_active = models.BooleanField(default=True) - is_amc_admin = models.BooleanField(default=False)