Commit ea2e6d93 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

astakos: user-modify command enhancements

New option ``--delete`` to permanently delete a user entry.
New option ``--set-email`` to change user's email address.
parent a8084356
...@@ -35,9 +35,11 @@ import string ...@@ -35,9 +35,11 @@ import string
from optparse import make_option from optparse import make_option
from django.core import management
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from synnefo.util import units from synnefo.util import units
from astakos.im.models import AstakosUser, Resource from astakos.im.models import AstakosUser, Resource
...@@ -140,6 +142,13 @@ class Command(BaseCommand): ...@@ -140,6 +142,13 @@ class Command(BaseCommand):
default=False, default=False,
dest='force', dest='force',
help="Do not ask for confirmation"), help="Do not ask for confirmation"),
make_option('--set-email',
dest='set-email',
help="Change user's email"),
make_option('--delete',
dest='delete',
action='store_true',
help="Delete user"),
) )
@commit_on_success_strict() @commit_on_success_strict()
...@@ -297,6 +306,35 @@ class Command(BaseCommand): ...@@ -297,6 +306,35 @@ class Command(BaseCommand):
resource, capacity = set_base_quota resource, capacity = set_base_quota
self.set_limit(user, resource, capacity, force) self.set_limit(user, resource, capacity, force)
delete = options.get('delete')
if delete:
management.call_command('user-show', str(user.pk),
list_quotas=True)
m = "Are you sure you want to permanently delete the user " \
"(yes/no) ? "
self.stdout.write("\n")
confirm = raw_input(m)
if confirm == "yes":
user.delete()
# Change users email address
newemail = options.get('set-email', None)
if newemail is not None:
newemail = newemail.strip()
try:
validate_email(newemail)
except ValidationError:
m = "Invalid email address."
raise CommandError(m)
if AstakosUser.objects.user_exists(newemail):
m = "A user with this email address already exists."
raise CommandError(m)
user.email = newemail
user.save()
def set_limit(self, user, resource, capacity, force): def set_limit(self, user, resource, capacity, force):
style = None style = None
if capacity != 'default': if capacity != 'default':
......
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