comparison roundup/actions.py @ 5606:5fc476d4e34c

Merge REST API changes
author Ralf Schlatterbeck <rsc@runtux.com>
date Wed, 30 Jan 2019 18:11:02 +0100
parents ed02a1e0aa5d
children 48a1f919f894
comparison
equal deleted inserted replaced
5553:a75285092156 5606:5fc476d4e34c
1 # 1 #
2 # Copyright (C) 2009 Stefan Seefeld 2 # Copyright (C) 2009 Stefan Seefeld
3 # All rights reserved. 3 # All rights reserved.
4 # For license terms see the file COPYING.txt. 4 # For license terms see the file COPYING.txt.
5 # Actions used in REST and XMLRPC APIs
5 # 6 #
6 7
7 from roundup.exceptions import Unauthorised 8 from roundup.exceptions import Unauthorised
8 from roundup import hyperdb 9 from roundup import hyperdb
9 from roundup.i18n import _ 10 from roundup.i18n import _
38 39
39 40
40 _ = gettext 41 _ = gettext
41 42
42 43
43 class Retire(Action): 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):
44 57
45 def handle(self, designator): 58 def handle(self, designator):
46 59
47 classname, itemid = hyperdb.splitDesignator(designator) 60 classname, itemid = hyperdb.splitDesignator(designator)
48 61
55 # do the retire 68 # do the retire
56 self.db.getclass(classname).retire(itemid) 69 self.db.getclass(classname).retire(itemid)
57 self.db.commit() 70 self.db.commit()
58 71
59 72
60 def permission(self, designator): 73 class Restore(PermCheck):
74
75 def handle(self, designator):
61 76
62 classname, itemid = hyperdb.splitDesignator(designator) 77 classname, itemid = hyperdb.splitDesignator(designator)
63 78
64 if not self.db.security.hasPermission('Edit', self.db.getuid(), 79 # do the restore
65 classname=classname, itemid=itemid): 80 self.db.getclass(classname).restore(itemid)
66 raise Unauthorised(self._('You do not have permission to ' 81 self.db.commit()
67 'retire the %(classname)s class.')%classname) 82
68

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