Automatically grant access to sandbox fleet on user creation
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 6 Nov 2010 02:49:04 +0000 (02:49 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 6 Nov 2010 02:49:04 +0000 (02:49 +0000)
bin/djais/models.py
bin/djais/views.py

index b67ae2c39ca35f3afcaf5146db516df0575ad8dc..e14c072aac985ec488f2ef1ad4608ac648a70a15 100644 (file)
@@ -77,6 +77,16 @@ class User(models.Model):
     def info(self, message, category_id='info'):
         UserMessage(user_id = self.id, category_id=category_id, txt=message).save()
 
+    def check_sandbox_access(self, source_user=None):
+        try:
+            FleetUser.objects.get(fleet = 'sandbox', user = self)
+        except FleetUser.DoesNotExist:
+            fu = FleetUser()
+            fu.user_id = self.id
+            fu.fleet_id = 'sandbox'
+            fu.save()
+            if source_user:
+                source_user.info("%s was granted access to 'sandbox' fleet" % self.login)
 
 class Vessel(models.Model):
     mmsi = models.IntegerField(primary_key=True)
index 025a8e6defbf0e8e99cc3f2f9d492eb15c02bab9..d94ba5ed59aa2e82d0b92d97ad513e223b71a2fb 100644 (file)
@@ -672,7 +672,7 @@ def user_edit(request, login):
             user.email = form.cleaned_data['email']
             user.phone = form.cleaned_data['phone']
             user.save()
-            #TODO grant access to sandbox fleet
+            user.check_sandbox_access(request.user)
             return HttpResponseRedirect('/user/')
     else: # GET
         form = UserEditForm(initial=initial)