comparison roundup/actions.py @ 4083:bbab97f8ffb2

XMLRPC improvements: * Add support for actions to XMLRPC interface. * Provide bridge so user actions may be executed either via CGI or XMLRPC. * Adjust XMLRPC tests to recent work. * Cleanup.
author Stefan Seefeld <stefan@seefeld.name>
date Fri, 27 Feb 2009 17:46:47 +0000
parents
children d499c3499d18
comparison
equal deleted inserted replaced
4082:5eb5f7e66c37 4083:bbab97f8ffb2
1 #
2 # Copyright (C) 2009 Stefan Seefeld
3 # All rights reserved.
4 # For license terms see the file COPYING.txt.
5 #
6
7 from roundup.exceptions import *
8 from roundup import hyperdb
9 from roundup.i18n import _
10
11 class Action:
12 def __init__(self, db, translator):
13 self.db = db
14 self.translator = translator
15
16 def handle(self, *args):
17 """Action handler procedure"""
18 raise NotImplementedError
19
20 def execute(self, *args):
21 """Execute the action specified by this object."""
22
23 self.permission(*args)
24 return self.handle(*args)
25
26
27 def permission(self, *args):
28 """Check whether the user has permission to execute this action.
29
30 If not, raise Unauthorised."""
31
32 pass
33
34
35 def gettext(self, msgid):
36 """Return the localized translation of msgid"""
37 return self.translator.gettext(msgid)
38
39
40 _ = gettext
41
42
43 class Retire(Action):
44
45 def handle(self, designator):
46
47 classname, itemid = hyperdb.splitDesignator(designator)
48
49 # make sure we don't try to retire admin or anonymous
50 if (classname == 'user' and
51 self.db.user.get(itemid, 'username') in ('admin', 'anonymous')):
52 raise ValueError, self._(
53 'You may not retire the admin or anonymous user')
54
55 # do the retire
56 self.db.getclass(classname).retire(itemid)
57 self.db.commit()
58
59
60 def permission(self, designator):
61
62 classname, itemid = hyperdb.splitDesignator(designator)
63
64 if not self.db.security.hasPermission('Edit', self.db.getuid(),
65 classname=classname, itemid=itemid):
66 raise Unauthorised(self._('You do not have permission to '
67 '%(action)s the %(classname)s class.')%info)
68

Roundup Issue Tracker: http://roundup-tracker.org/