William Grant has proposed merging lp:~wgrant/launchpad/suspend-bot-account into lp:launchpad.
Commit message: Add a suspend-bot-account.py script to suspend an account by email address. Requested reviews: Launchpad code reviewers (launchpad-reviewers) For more details, see: https://code.launchpad.net/~wgrant/launchpad/suspend-bot-account/+merge/349392 -- Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/suspend-bot-account into lp:launchpad.
=== added file 'lib/lp/registry/scripts/suspendbotaccount.py' --- lib/lp/registry/scripts/suspendbotaccount.py 1970-01-01 00:00:00 +0000 +++ lib/lp/registry/scripts/suspendbotaccount.py 2018-07-12 06:15:20 +0000 @@ -0,0 +1,44 @@ +# Copyright 2018 Canonical Ltd. This software is licensed under the +# GNU Affero General Public License version 3 (see the file LICENSE). + +"""Suspend a bot account.""" + +from zope.component import getUtility + +from lp.registry.interfaces.person import IPersonSet +from lp.services.identity.interfaces.account import AccountStatus +from lp.services.scripts.base import ( + LaunchpadScript, + LaunchpadScriptFailure, + ) +from lp.services.webapp import canonical_url + + +class SuspendBotAccountScript(LaunchpadScript): + + description = "Suspend a bot account." + output = None + + def add_my_options(self): + self.parser.add_option( + '-e', '--email', metavar='ADDR', action='store', + type='string', dest='email', default='', + help='Email address. Defaults to [email protected]') + + def main(self): + emailaddress = unicode(self.options.email) + if not emailaddress: + raise LaunchpadScriptFailure('--email is required') + + person = getUtility(IPersonSet).getByEmail(emailaddress) + if person is None: + raise LaunchpadScriptFailure( + 'Account with email address {} does not exist'.format( + emailaddress)) + + person.account.setStatus( + AccountStatus.SUSPENDED, None, + 'Suspended by suspend-bot-account.py') + + self.logger.info('Suspended {}'.format(canonical_url(person))) + self.txn.commit() === added file 'lib/lp/registry/scripts/tests/test_suspendbotaccount.py' --- lib/lp/registry/scripts/tests/test_suspendbotaccount.py 1970-01-01 00:00:00 +0000 +++ lib/lp/registry/scripts/tests/test_suspendbotaccount.py 2018-07-12 06:15:20 +0000 @@ -0,0 +1,33 @@ +# Copyright 2017 Canonical Ltd. This software is licensed under the +# GNU Affero General Public License version 3 (see the file LICENSE). + +"""Test the suspend-bot-account script.""" + +__metaclass__ = type + +from lp.registry.scripts.suspendbotaccount import SuspendBotAccountScript +from lp.services.identity.interfaces.account import AccountStatus +from lp.services.log.logger import DevNullLogger +from lp.testing import TestCaseWithFactory +from lp.testing.faketransaction import FakeTransaction +from lp.testing.layers import ZopelessDatabaseLayer + + +class TestSuspendBotAccount(TestCaseWithFactory): + """Test `suspend-bot-account`.""" + + layer = ZopelessDatabaseLayer + + def makeScript(self, test_args): + script = SuspendBotAccountScript(test_args=test_args) + script.logger = DevNullLogger() + script.txn = FakeTransaction() + return script + + def test_suspendbotaccount(self): + bot = self.factory.makePerson(email='[email protected]') + script = self.makeScript(['--email', '[email protected]']) + script.main() + self.assertEqual(AccountStatus.SUSPENDED, bot.account_status) + + self.assertEqual(1, script.txn.commit_count) === added file 'scripts/suspend-bot-account.py' --- scripts/suspend-bot-account.py 1970-01-01 00:00:00 +0000 +++ scripts/suspend-bot-account.py 2018-07-12 06:15:20 +0000 @@ -0,0 +1,13 @@ +#!/usr/bin/python -S +# +# Copyright 2018 Canonical Ltd. This software is licensed under the +# GNU Affero General Public License version 3 (see the file LICENSE). + +import _pythonpath + +from lp.registry.scripts.createbotaccount import SuspendBotAccountScript + + +if __name__ == '__main__': + script = SuspendBotAccountScript('suspend-bot-account', dbuser='launchpad') + script.run()
_______________________________________________ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : [email protected] Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp

