From f8506c322074edb907eb2163f1dbcd0dc01d5f97 Mon Sep 17 00:00:00 2001 From: Omar Al-Ithawi Date: Wed, 2 Jun 2021 14:38:59 +0300 Subject: [PATCH 1/2] 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) From 784235524137a3188c8950441d66acd63ee1e56d Mon Sep 17 00:00:00 2001 From: Omar Al-Ithawi Date: Wed, 2 Jun 2021 14:41:36 +0300 Subject: [PATCH 2/2] add app_label to models: fix breaking tests tests in Open edX `common` don't have the `organizations` in the INSTALLED_APPS this change and throws an error like: "Model xyz is not in INSTALLED_APP and doesn't declare `app_label`" This fixes it by adding app_label. Also, removing unneeded @python_2_unicode_compatible now we're past Python 2. --- organizations/models.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/organizations/models.py b/organizations/models.py index 686847e4..0582304d 100644 --- a/organizations/models.py +++ b/organizations/models.py @@ -48,6 +48,9 @@ class Organization(TimeStampedModel): history = HistoricalRecords() + class Meta: + app_label = 'organizations' + def __str__(self): return u"{name} ({short_name})".format(name=self.name, short_name=self.short_name) @@ -76,7 +79,6 @@ def clean(self): 'and underscore (_).')) -@python_2_unicode_compatible class OrganizationCourse(TimeStampedModel): """ An OrganizationCourse represents the link between an Organization and a @@ -93,6 +95,7 @@ class Meta: unique_together = (('course_id', 'organization'),) verbose_name = _('Link Course') verbose_name_plural = _('Link Courses') + app_label = 'organizations' def __str__(self): org = self.organization @@ -102,7 +105,6 @@ def __str__(self): ) -@python_2_unicode_compatible class UserOrganizationMapping(models.Model): """ User membership in an organization. @@ -115,6 +117,9 @@ class UserOrganizationMapping(models.Model): is_active = models.BooleanField(default=True) is_amc_admin = models.BooleanField(default=False) + class Meta: + app_label = 'organizations' + def __str__(self): org = self.organization return 'UserOrganizationMapping<{email}, {organization}>'.format(