[gen] When raising Unauthorized, give more explanations.
This commit is contained in:
parent
188fdc9761
commit
b680a5ddcb
|
@ -1993,33 +1993,36 @@ class Ref(Type):
|
|||
def mayAdd(self, obj):
|
||||
'''May the user create a new referred object from p_obj via this Ref?'''
|
||||
# We can't (yet) do that on back references.
|
||||
if self.isBack: return
|
||||
if self.isBack: return No('is_back')
|
||||
# Check if this Ref is addable
|
||||
if callable(self.add):
|
||||
add = self.callMethod(obj, self.add)
|
||||
else:
|
||||
add = self.add
|
||||
if not add: return
|
||||
if not add: return No('no_add')
|
||||
# Have we reached the maximum number of referred elements?
|
||||
if self.multiplicity[1] != None:
|
||||
refCount = len(getattr(obj, self.name, ()))
|
||||
if refCount >= self.multiplicity[1]: return
|
||||
if refCount >= self.multiplicity[1]: return No('max_reached')
|
||||
# May the user edit this Ref field?
|
||||
if not obj.allows(self.writePermission): return
|
||||
if not obj.allows(self.writePermission): return No('no_write_perm')
|
||||
# Have the user the correct add permission?
|
||||
tool = obj.getTool()
|
||||
addPermission = '%s: Add %s' % (tool.getAppName(),
|
||||
tool.getPortalType(self.klass))
|
||||
folder = obj.getCreateFolder()
|
||||
if not obj.getUser().has_permission(addPermission, folder): return
|
||||
if not obj.getUser().has_permission(addPermission, folder):
|
||||
return No('no_add_perm')
|
||||
return True
|
||||
|
||||
def checkAdd(self, obj):
|
||||
'''Compute m_mayAdd above, and raise an Unauthorized exception if
|
||||
m_mayAdd returns False.'''
|
||||
if not self.mayAdd(obj):
|
||||
may = self.mayAdd(obj)
|
||||
if not may:
|
||||
from AccessControl import Unauthorized
|
||||
raise Unauthorized("User can't write Ref field '%s'." % self.name)
|
||||
raise Unauthorized("User can't write Ref field '%s' (%s)." % \
|
||||
(self.name, may.msg))
|
||||
|
||||
class Computed(Type):
|
||||
def __init__(self, validator=None, multiplicity=(0,1), index=None,
|
||||
|
|
|
@ -102,8 +102,8 @@ img { border: 0; vertical-align: middle}
|
|||
.section2 { font-size: 110%; font-style: italic; margin: 0.45em 0em 0.2em 0;
|
||||
border-bottom: 2px solid grey; }
|
||||
.section3 { font-size: 100%; font-style: italic; font-weight: bold;
|
||||
margin: 0.45em 0em 0.1em 0; background-color: #F4F5F6;
|
||||
text-align: center; color: grey; }
|
||||
margin: 0.45em 0em 0.1em 0; background-color: #95a1b3;
|
||||
text-align: center; color: white; }
|
||||
.odd { background-color: white; }
|
||||
.even { background-color: #F4F5F6; }
|
||||
.summary {margin-bottom: 5px;}
|
||||
|
|
Loading…
Reference in a new issue