Provide api calls for permitting helpdesk users to access user information by user...
[astakos] / snf-astakos-app / astakos / im / management / commands / addgroup.py
index b37f89f..25620da 100644 (file)
@@ -39,15 +39,16 @@ from time import time
 from os.path import abspath
 
 from django.core.management.base import BaseCommand, CommandError
-
 from django.contrib.auth.models import Group
 
+from ._common import add_group_permission
+
 class Command(BaseCommand):
-    args = "<name>"
+    args = "<groupname> [<permission> ...]"
     help = "Insert group"
     
     def handle(self, *args, **options):
-        if len(args) != 1:
+        if len(args) < 1:
             raise CommandError("Invalid number of arguments")
         
         name = args[0].decode('utf8')
@@ -58,6 +59,16 @@ class Command(BaseCommand):
         except Group.DoesNotExist, e:
             group = Group(name=name)
             group.save()
-        
-        msg = "Created group id %d" % (group.id,)
-        self.stdout.write(msg + '\n')
+            msg = "Created group id %d" % (group.id,)
+            self.stdout.write(msg + '\n')
+            try:
+                for pname in args[1:]:
+                    r, created = add_group_permission(group, pname)
+                    if created:
+                        self.stdout.write('Permission: %s created successfully\n' % pname)
+                    if r == 0:
+                        self.stdout.write('Group has already permission: %s\n' % pname)
+                    else:
+                        self.stdout.write('Permission: %s added successfully\n' % pname)
+            except Exception, e:
+                raise CommandError(e)
\ No newline at end of file