Skip to content

Commit

Permalink
Remove unused SiteMemberBackend and its model
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OmarIthawi committed Jun 2, 2021
1 parent 466abb8 commit f8506c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
22 changes: 0 additions & 22 deletions organizations/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions organizations/migrations/0012_delete_usersitemapping.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
13 changes: 0 additions & 13 deletions organizations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f8506c3

Please sign in to comment.