Back to index

moin  1.9.0~rc2
disable.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003 MoinMoin - disable a user account
00004 
00005 @copyright: 2006 MoinMoin:ThomasWaldmann
00006 @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 from MoinMoin.script import MoinScript
00010 
00011 class PluginScript(MoinScript):
00012     """\
00013 Purpose:
00014 ========
00015 This tool allows you to disable user accounts via a command line interface.
00016 
00017 Detailed Instructions:
00018 ======================
00019 General syntax: moin [options] account disable [disable-options]
00020 
00021 [options] usually should be:
00022     --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
00023 
00024 [disable-options] see below:
00025     0. Verify that you really want to disable the account.
00026        While there is a disable script, no such enable script exists.
00027 
00028     1. To disable the user 'JohnSmith':
00029        moin ... account disable --name JohnSmith
00030 
00031     2. To disable the user 'JohnSmith', based on his UID '1198872910.78.56322':
00032        moin ... account disable --uid 1198872910.78.56322
00033 """
00034 
00035     def __init__(self, argv, def_values):
00036         MoinScript.__init__(self, argv, def_values)
00037         self.parser.add_option(
00038             "--uid", metavar="UID", dest="uid",
00039             help="Disable the user with user id UID."
00040         )
00041         self.parser.add_option(
00042             "--name", metavar="NAME", dest="uname",
00043             help="Disable the user with user name NAME."
00044         )
00045 
00046     def mainloop(self):
00047         # we don't expect non-option arguments
00048         if len(self.args) != 0:
00049             self.parser.error("incorrect number of arguments")
00050 
00051         flags_given = self.options.uid or self.options.uname
00052         if not flags_given:
00053             self.parser.print_help()
00054             import sys
00055             sys.exit(1)
00056 
00057         self.init_request()
00058         request = self.request
00059 
00060         from MoinMoin import user
00061         if self.options.uid:
00062             u = user.User(request, self.options.uid)
00063         elif self.options.uname:
00064             u = user.User(request, None, self.options.uname)
00065 
00066         if not u.exists():
00067             print 'This user "%s" does not exists!' % u.name
00068             return
00069 
00070         print " %-20s %-25s %-35s" % (u.id, u.name, u.email),
00071         if not u.disabled: # only disable once
00072             u.disabled = 1
00073             u.name = "%s-%s" % (u.name, u.id)
00074             if u.email:
00075                 u.email = "%s-%s" % (u.email, u.id)
00076             u.subscribed_pages = "" # avoid using email
00077             u.save()
00078             print "- disabled."
00079         else:
00080             print "- is already disabled."