Commit 9093a57c authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB

Remove unnecessary AlternateEmail model

parent 62295f4e
from django.core.management.base import BaseCommand, CommandError
import datetime
from ligoauth.models import LigoLdapUser, X509Cert, AlternateEmail
from django.conf import settings
from django.contrib.auth.models import User, Group
import ldap
from django.conf import settings
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand, CommandError
from ligoauth.models import LigoLdapUser, X509Cert, AuthGroup
# Variables for LDAP search
BASE_DN = "ou=people,dc=ligo,dc=org"
SEARCH_SCOPE = ldap.SCOPE_SUBTREE
......@@ -17,8 +19,6 @@ RETRIEVE_ATTRIBUTES = [
"sn",
"mail",
"isMemberOf",
"mailAlternateAddress",
"mailForwardingAddress"
]
LDAP_ADDRESS = "ldap.ligo.org"
LDAP_PORT = 636
......@@ -168,26 +168,3 @@ class Command(BaseCommand):
self.stdout.write("Removing {user} from {group}" \
.format(user=l_user.username,
group=lvc_group.name))
# Get alternate email addresses (for some reason...)
try:
mailForwardingAddress = unicode(ldap_result['mailForwardingAddress'][0])
except:
mailForwardingAddress = None
mailAlternateAddresses = ldap_result.get('mailAlternateAddress', [])
# Finally, deal with alternate emails.
if mailForwardingAddress:
try:
AlternateEmail.objects.get_or_create(l_user=user,
email=mailForwardingAddress)
except:
pass
if len(mailAlternateAddresses) > 0:
for email in mailAlternateAddresses:
try:
AlternateEmail.objects.get_or_create(
l_user=user, email=email)
except:
pass
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-05-31 20:36
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('ligoauth', '0038_populate_authgroup'),
]
operations = [
migrations.RemoveField(
model_name='alternateemail',
name='user',
),
migrations.DeleteModel(
name='AlternateEmail',
),
]
......@@ -64,28 +64,12 @@ class LigoLdapUser(User):
class RobotUser(User):
pass
class X509Cert(models.Model):
"""Model for storing X.509 certificate subjects for API access"""
subject = models.CharField(max_length=300)
users = models.ManyToManyField(User)
class AlternateEmail(models.Model):
user = models.ForeignKey(User)
email = models.EmailField(max_length=254)
def certdn_to_user(dn, username=None):
try:
possible_users = X509Cert.objects.get(subject=dn).users
except:
return None
if username:
possible_users.filter(username=username)
try:
return possible_users.all()[0]
except IndexError:
return None
class AuthGroup(Group):
"""Enhanced version of Django Group model"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment