Mercurial > p > roundup > code
annotate roundup/actions.py @ 5937:5d0873a4de4a
fix rate limit headers - were ints/floats need to be strings
Running under gunicorn rest requests were crashing. Not all of the
values for the rate limit headers were strings. Some were
numbers. This caused the header generation for wsgi to fail. Now the
values are all strings.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 20 Oct 2019 20:56:56 -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 |
