Auto-apply 'mit' and 'autocreated' groups
authorAlex Dehnert <adehnert@mit.edu>
Fri, 2 Apr 2010 15:21:11 +0000 (11:21 -0400)
committerAlex Dehnert <adehnert@mit.edu>
Mon, 6 Jun 2011 05:57:09 +0000 (01:57 -0400)
This resolves the "we need rope" part of Trac #20.

django/mit/__init__.py

index fd8d4529fb1ecfc81ae9ddd67213b0398e1cd5ab..ff296a890c366166b4d6a9f5dde2b33a52d81888 100644 (file)
@@ -1,6 +1,7 @@
 from django.contrib.auth.middleware import RemoteUserMiddleware
 from django.contrib.auth.backends import RemoteUserBackend
 from django.contrib import auth
+from django.core.exceptions import ObjectDoesNotExist
 
 def zephyr(msg, clas='remit', instance='log', rcpt='adehnert',):
     import os
@@ -29,5 +30,13 @@ class ScriptsRemoteUserBackend(RemoteUserBackend):
             user.first_name = result[0][1]['givenName'][0]
             user.last_name = result[0][1]['sn'][0]
             user.email = result[0][1]['mail'][0]
+            try:
+                user.groups.add(auth.models.Group.objects.get(name='mit'))
+            except ObjectDoesNotExist:
+                print "Failed to retrieve mit group"
             user.save()
+        try:
+            user.groups.add(auth.models.Group.objects.get(name='autocreated'))
+        except ObjectDoesNotExist:
+            print "Failed to retrieve autocreated group"
         return user