Commit 31f07c85 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki Committed by Georgios D. Tsoukalas
Browse files

Fix user-add management command

set-password & active options
parent 451b4cba
......@@ -46,6 +46,7 @@ from astakos.im.api.backends.base import (
BaseBackend, SuccessResult, FailureResult)
from astakos.im.api.backends.errors import (
ItemNotExists, ItemExists, MissingIdentifier, MultipleItemsExist)
from astakos.im.functions import activate
from astakos.im.util import reserved_email, model_to_dict
from astakos.im.functions import get_quota
......@@ -144,11 +145,14 @@ class DjangoBackend(BaseBackend):
groups = kwargs.pop('groups', ())
password = kwargs.pop('password', None)
provider = kwargs.pop('provider', 'local')
active = kwargs.pop('active', False)
u = self._create_object(AstakosUser, **kwargs)
if password:
u.set_password(password)
u.save()
u.permissions = permissions
u.policies = policies
u.extended_groups = groups
......@@ -156,6 +160,9 @@ class DjangoBackend(BaseBackend):
if not u.has_auth_provider(provider):
u.add_auth_provider(provider)
if active:
activate(u)
return self._details(u)
@safe
......@@ -185,7 +192,7 @@ class DjangoBackend(BaseBackend):
except ObjectDoesNotExist, e:
append((service, resource, e))
return rejected
@safe
def add_permissions(self, user_id, permissions=()):
user = self._lookup_user(user_id)
......
......@@ -98,7 +98,6 @@ class Command(BaseCommand):
'last_name':last_name
}
u.update(filter_custom_options(options))
u.pop('active')
if not u.get('password'):
u['password'] = AstakosUser.objects.make_random_password()
......@@ -111,10 +110,6 @@ class Command(BaseCommand):
if not r.is_success:
raise CommandError(r.reason)
else:
if options['active']:
user_id = r.data.get('id')
user = AstakosUser.objects.get(id = user_id)
activate(user)
self.stdout.write('User created successfully ')
if not options.get('password'):
self.stdout.write('with password: %s\n' % u['password'])
......
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