Commit d3d43c85 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

astakos: Move migration script to tools dir

Put the migration script that suspends projects of deactivated users
under astakos/tools, rather than providing it as an snf-manage
command.
parent cad2572f
......@@ -14,8 +14,9 @@ v0.18.1
Astakos
-------
* Fix a bug in `user-check` management command, where the list of deactivated
users was computed wrongly.
* Move script that suspends projects for deactivated users under
/usr/lib/astakos/tools and fix a bug on the computation of the list
of deactivated users.
.. _Changelog-0.18:
......
......@@ -14,8 +14,7 @@ Release: UNRELEASED
The Synnefo 0.18.1 release resolves the following issue.
* Fixed a bug in `user-check` management command, where the list of
deactivated users was computed wrongly.
* Fixed a bug on the script that suspends projects for deactivated users.
.. _NEWS-0.18:
......
......@@ -60,7 +60,7 @@ The upgrade to v0.18 consists of the following steps:
.. code-block:: console
astakos.host$ snf-manage user-check --all-users --suspend-deactivated --noemail --fix
astakos.host$ /usr/lib/astakos/tools/fix_deactivated_users --all-users --noemail --fix
#. Restart services
......
#!/usr/bin/env python
# Copyright (C) 2010-2016 GRNET S.A.
#
# This program is free software: you can redistribute it and/or modify
......@@ -13,8 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import string
from datetime import datetime
import sys
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "synnefo.settings")
from optparse import make_option
......@@ -23,20 +26,17 @@ from snf_django.management.commands import SynnefoCommand, CommandError
from astakos.im.models import AstakosUser
from astakos.im import functions, activation_backends
from astakos.im.management.commands._common import is_uuid
from django.conf import settings
SUSPENSION_REASON = activation_backends.PROJECT_SUSPENSION_REASON
class Command(SynnefoCommand):
help = "Check and fix user state"
help = "Check and fix state of projects for deactivated users"
args = "<user ID> (or --all-users)"
option_list = SynnefoCommand.option_list + (
make_option('--suspend-deactivated',
action="store_true",
default=False,
help="Suspend projects if user is deactivated"),
make_option('--all-users',
action="store_true",
default=False,
......@@ -78,10 +78,7 @@ class Command(SynnefoCommand):
raise CommandError("Need to specify either a userid "
"or option --all-users.")
userid = None if all_users else args[0]
if options["suspend_deactivated"]:
self.suspend_projects(userid, fix)
else:
self.stderr.write("No action specified.\n")
self.suspend_projects(userid, fix)
@transaction.commit_on_success
def suspend_projects(self, userid, fix):
......@@ -103,9 +100,16 @@ class Command(SynnefoCommand):
reason=SUSPENSION_REASON, fix=fix)
if affected:
verb = "Affected" if fix else "Would affect"
self.stderr.write("%s %s (%s)\n" % (verb, user.email, user.uuid))
count +=1
self.stderr.write("%s %s (%s)\n" %
(verb, user.email, user.uuid))
count += 1
if count:
self.stderr.write("Total %s users.\n" % count)
else:
self.stderr.write("No users affected.\n")
command = Command()
args = sys.argv[:]
args.insert(1, 'fix-deactivated-users')
command.run_from_argv(args)
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