Mercurial > p > roundup > code
annotate roundup/actions.py @ 5729:9ea2ce9d10cf
A few internet references report that etags for the same underlying
resource but with different representation (xml, json ...) should have
different etags.
That is currently not the case. Added code to allow incorporation of
representation info into the etag. By default the representation is
"json", but future patches can pass the representation down and modify
flow to match requested representation.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 25 May 2019 14:23:16 -0400 |
| parents | ed02a1e0aa5d |
| children | 48a1f919f894 |
| rev | line source |
|---|---|
| 4083 | 1 # |
| 2 # Copyright (C) 2009 Stefan Seefeld | |
| 3 # All rights reserved. | |
| 4 # For license terms see the file COPYING.txt. | |
| 5604 | 5 # Actions used in REST and XMLRPC APIs |
| 4083 | 6 # |
| 7 | |
|
5071
a7541077cf12
Remove 'import *' statement from actions.py
John Kristensen <john@jerrykan.com>
parents:
4357
diff
changeset
|
8 from roundup.exceptions import Unauthorised |
| 4083 | 9 from roundup import hyperdb |
| 10 from roundup.i18n import _ | |
| 11 | |
| 12 class Action: | |
| 13 def __init__(self, db, translator): | |
| 14 self.db = db | |
| 15 self.translator = translator | |
| 16 | |
| 17 def handle(self, *args): | |
| 18 """Action handler procedure""" | |
| 19 raise NotImplementedError | |
| 20 | |
| 21 def execute(self, *args): | |
| 22 """Execute the action specified by this object.""" | |
| 23 | |
| 24 self.permission(*args) | |
| 25 return self.handle(*args) | |
| 26 | |
| 27 | |
| 28 def permission(self, *args): | |
| 29 """Check whether the user has permission to execute this action. | |
| 30 | |
| 31 If not, raise Unauthorised.""" | |
| 32 | |
| 33 pass | |
| 34 | |
| 35 | |
| 36 def gettext(self, msgid): | |
| 37 """Return the localized translation of msgid""" | |
| 38 return self.translator.gettext(msgid) | |
| 39 | |
| 40 | |
| 41 _ = gettext | |
| 42 | |
| 43 | |
| 5604 | 44 class PermCheck(Action): |
| 45 def permission(self, designator): | |
| 46 | |
| 47 classname, itemid = hyperdb.splitDesignator(designator) | |
| 48 perm = self.db.security.hasPermission | |
| 49 | |
| 50 if not perm('Retire', self.db.getuid(), classname=classname | |
| 51 , itemid=itemid): | |
| 52 raise Unauthorised(self._('You do not have permission to retire ' | |
| 53 'or restore the %(classname)s class.') | |
| 54 %locals()) | |
| 55 | |
| 56 class Retire(PermCheck): | |
| 4083 | 57 |
| 58 def handle(self, designator): | |
| 59 | |
| 60 classname, itemid = hyperdb.splitDesignator(designator) | |
| 61 | |
| 62 # make sure we don't try to retire admin or anonymous | |
| 63 if (classname == 'user' and | |
| 64 self.db.user.get(itemid, 'username') in ('admin', 'anonymous')): | |
|
4357
13b3155869e0
Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents:
4125
diff
changeset
|
65 raise ValueError(self._( |
|
13b3155869e0
Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents:
4125
diff
changeset
|
66 'You may not retire the admin or anonymous user')) |
| 4083 | 67 |
| 68 # do the retire | |
| 69 self.db.getclass(classname).retire(itemid) | |
| 70 self.db.commit() | |
| 71 | |
| 72 | |
| 5604 | 73 class Restore(PermCheck): |
| 74 | |
| 75 def handle(self, designator): | |
| 4083 | 76 |
| 77 classname, itemid = hyperdb.splitDesignator(designator) | |
| 78 | |
| 5604 | 79 # do the restore |
| 80 self.db.getclass(classname).restore(itemid) | |
| 81 self.db.commit() | |
| 82 |
