Skip to content

Commit

Permalink
Merge pull request #15 from appsembler/omar/model-cleanup
Browse files Browse the repository at this point in the history
Models cleanup: add `app_label`; remove `SiteMemberBackend`
  • Loading branch information
OmarIthawi authored Jun 11, 2021
2 parents d9273d9 + 7842355 commit dfe755a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 37 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',
),
]
22 changes: 7 additions & 15 deletions organizations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -102,7 +105,6 @@ def __str__(self):
)


@python_2_unicode_compatible
class UserOrganizationMapping(models.Model):
"""
User membership in an organization.
Expand All @@ -115,22 +117,12 @@ 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(
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 dfe755a

Please sign in to comment.