2 # Copyright (C) 2009 Stefan Seefeld
4 # For license terms see the file COPYING.txt.
7 from roundup
.exceptions
import *
8 from roundup
import hyperdb
9 from roundup
.i18n
import _
12 def __init__(self
, db
, translator
):
14 self
.translator
= translator
16 def handle(self
, *args
):
17 """Action handler procedure"""
18 raise NotImplementedError
20 def execute(self
, *args
):
21 """Execute the action specified by this object."""
23 self
.permission(*args
)
24 return self
.handle(*args
)
27 def permission(self
, *args
):
28 """Check whether the user has permission to execute this action.
30 If not, raise Unauthorised."""
35 def gettext(self
, msgid
):
36 """Return the localized translation of msgid"""
37 return self
.translator
.gettext(msgid
)
45 def handle(self
, designator
):
47 classname
, itemid
= hyperdb
.splitDesignator(designator
)
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'))
56 self
.db
.getclass(classname
).retire(itemid
)
60 def permission(self
, designator
):
62 classname
, itemid
= hyperdb
.splitDesignator(designator
)
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 'retire the %(classname)s class.')%classname
)