Commit 39033d38 authored by Hanno Schlichting's avatar Hanno Schlichting

Raise BadRequest instead of returning MessageDialog.

parent 0947e7fd
...@@ -30,6 +30,8 @@ Features Added ...@@ -30,6 +30,8 @@ Features Added
Restructuring Restructuring
+++++++++++++ +++++++++++++
- Raise BadRequest instead of returning MessageDialog.
- Remove property management ZMI screens. - Remove property management ZMI screens.
- Remove ZMI copy/cut/paste/rename and re-ordering features. - Remove ZMI copy/cut/paste/rename and re-ordering features.
......
...@@ -37,7 +37,6 @@ from Acquisition import aq_base, aq_parent ...@@ -37,7 +37,6 @@ from Acquisition import aq_base, aq_parent
from Acquisition import Implicit from Acquisition import Implicit
from App.Common import is_acquired from App.Common import is_acquired
from App.config import getConfiguration from App.config import getConfiguration
from App.Dialogs import MessageDialog
from App.FactoryDispatcher import ProductDispatcher from App.FactoryDispatcher import ProductDispatcher
from App.Management import Navigation from App.Management import Navigation
from App.Management import Tabs from App.Management import Tabs
...@@ -522,20 +521,14 @@ class ObjectManager(CopyContainer, ...@@ -522,20 +521,14 @@ class ObjectManager(CopyContainer,
if isinstance(ids, basestring): if isinstance(ids, basestring):
ids = [ids] ids = [ids]
if not ids: if not ids:
return MessageDialog( raise BadRequest('No items specified')
title='No items specified',
message='No items were specified!',
action='./manage_main',)
try: try:
p = self._reserved_names p = self._reserved_names
except: except:
p = () p = ()
for n in ids: for n in ids:
if n in p: if n in p:
return MessageDialog( raise BadRequest('Not Deletable')
title='Not Deletable',
message='<EM>%s</EM> cannot be deleted.' % escape(n),
action='./manage_main',)
while ids: while ids:
id = ids[-1] id = ids[-1]
v = self._getOb(id, self) v = self._getOb(id, self)
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
from cgi import escape from cgi import escape
from App.Dialogs import MessageDialog
from App.special_dtml import DTMLFile from App.special_dtml import DTMLFile
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
...@@ -26,6 +25,7 @@ from AccessControl.Permission import Permission ...@@ -26,6 +25,7 @@ from AccessControl.Permission import Permission
from AccessControl.Permissions import change_permissions from AccessControl.Permissions import change_permissions
from AccessControl.requestmethod import requestmethod from AccessControl.requestmethod import requestmethod
from AccessControl.rolemanager import _string_hash from AccessControl.rolemanager import _string_hash
from zExceptions import BadRequest
class RoleManager(BaseRoleManager): class RoleManager(BaseRoleManager):
...@@ -122,15 +122,10 @@ class RoleManager(BaseRoleManager): ...@@ -122,15 +122,10 @@ class RoleManager(BaseRoleManager):
fails.append(name) fails.append(name)
if fails: if fails:
return MessageDialog( raise BadRequest('Some permissions had errors: ' +
title="Warning!", escape(', '.join(fails)))
message="Some permissions had errors: " + if REQUEST is not None:
escape(', '.join(fails)), return self.manage_access(REQUEST)
action='manage_access')
return MessageDialog(
title='Success!',
message='Your changes have been saved',
action='manage_access')
security.declareProtected(change_permissions, 'manage_listLocalRoles') security.declareProtected(change_permissions, 'manage_listLocalRoles')
manage_listLocalRoles = DTMLFile('dtml/listLocalRoles', globals(), manage_listLocalRoles = DTMLFile('dtml/listLocalRoles', globals(),
...@@ -184,15 +179,9 @@ class RoleManager(BaseRoleManager): ...@@ -184,15 +179,9 @@ class RoleManager(BaseRoleManager):
@requestmethod('POST') @requestmethod('POST')
def _addRole(self, role, REQUEST=None): def _addRole(self, role, REQUEST=None):
if not role: if not role:
return MessageDialog( raise BadRequest('You must specify a role name')
title='Incomplete',
message='You must specify a role name',
action='manage_access')
if role in self.__ac_roles__: if role in self.__ac_roles__:
return MessageDialog( raise BadRequest('The given role is already defined')
title='Role Exists',
message='The given role is already defined',
action='manage_access')
data = list(self.__ac_roles__) data = list(self.__ac_roles__)
data.append(role) data.append(role)
self.__ac_roles__ = tuple(data) self.__ac_roles__ = tuple(data)
...@@ -202,10 +191,7 @@ class RoleManager(BaseRoleManager): ...@@ -202,10 +191,7 @@ class RoleManager(BaseRoleManager):
@requestmethod('POST') @requestmethod('POST')
def _delRoles(self, roles, REQUEST=None): def _delRoles(self, roles, REQUEST=None):
if not roles: if not roles:
return MessageDialog( raise BadRequest('You must specify a role name')
title='Incomplete',
message='You must specify a role name',
action='manage_access')
data = list(self.__ac_roles__) data = list(self.__ac_roles__)
for role in roles: for role in roles:
try: try:
......
...@@ -20,9 +20,9 @@ from Acquisition import aq_base ...@@ -20,9 +20,9 @@ from Acquisition import aq_base
from App.Management import Navigation from App.Management import Navigation
from App.Management import Tabs from App.Management import Tabs
from App.special_dtml import DTMLFile from App.special_dtml import DTMLFile
from App.Dialogs import MessageDialog
from OFS.role import RoleManager from OFS.role import RoleManager
from OFS.SimpleItem import Item from OFS.SimpleItem import Item
from zExceptions import BadRequest
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl.class_init import InitializeClass from AccessControl.class_init import InitializeClass
...@@ -141,27 +141,15 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager, ...@@ -141,27 +141,15 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager,
@requestmethod('POST') @requestmethod('POST')
def _addUser(self, name, password, confirm, roles, domains, REQUEST=None): def _addUser(self, name, password, confirm, roles, domains, REQUEST=None):
if not name: if not name:
return MessageDialog( raise BadRequest('A username must be specified')
title='Illegal value',
message='A username must be specified',
action='manage_main')
if not password or not confirm: if not password or not confirm:
if not domains: if not domains:
return MessageDialog( raise BadRequest('Password and confirmation must be specified')
title='Illegal value',
message='Password and confirmation must be specified',
action='manage_main')
if self.getUser(name) or (self._emergency_user and if self.getUser(name) or (self._emergency_user and
name == self._emergency_user.getUserName()): name == self._emergency_user.getUserName()):
return MessageDialog( raise BadRequest('A user with the specified name already exists')
title='Illegal value',
message='A user with the specified name already exists',
action='manage_main')
if (password or confirm) and (password != confirm): if (password or confirm) and (password != confirm):
return MessageDialog( raise BadRequest('Password and confirmation do not match')
title='Illegal value',
message='Password and confirmation do not match',
action='manage_main')
if not roles: if not roles:
roles = [] roles = []
...@@ -169,10 +157,7 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager, ...@@ -169,10 +157,7 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager,
domains = [] domains = []
if domains and not self.domainSpecValidate(domains): if domains and not self.domainSpecValidate(domains):
return MessageDialog( raise BadRequest('Illegal domain specification')
title='Illegal value',
message='Illegal domain specification',
action='manage_main')
self._doAddUser(name, password, roles, domains) self._doAddUser(name, password, roles, domains)
if REQUEST: if REQUEST:
return self._mainUser(self, REQUEST) return self._mainUser(self, REQUEST)
...@@ -184,26 +169,14 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager, ...@@ -184,26 +169,14 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager,
# Protocol for editUser.dtml to indicate unchanged password # Protocol for editUser.dtml to indicate unchanged password
password = confirm = None password = confirm = None
if not name: if not name:
return MessageDialog( raise BadRequest('A username must be specified')
title='Illegal value',
message='A username must be specified',
action='manage_main')
if password == confirm == '': if password == confirm == '':
if not domains: if not domains:
return MessageDialog( raise BadRequest('Password and confirmation must be specified')
title='Illegal value',
message='Password and confirmation must be specified',
action='manage_main')
if not self.getUser(name): if not self.getUser(name):
return MessageDialog( raise BadRequest('Unknown user')
title='Illegal value',
message='Unknown user',
action='manage_main')
if (password or confirm) and (password != confirm): if (password or confirm) and (password != confirm):
return MessageDialog( raise BadRequest('Password and confirmation do not match')
title='Illegal value',
message='Password and confirmation do not match',
action='manage_main')
if not roles: if not roles:
roles = [] roles = []
...@@ -211,10 +184,7 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager, ...@@ -211,10 +184,7 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager,
domains = [] domains = []
if domains and not self.domainSpecValidate(domains): if domains and not self.domainSpecValidate(domains):
return MessageDialog( raise BadRequest('Illegal domain specification')
title='Illegal value',
message='Illegal domain specification',
action='manage_main')
self._doChangeUser(name, password, roles, domains) self._doChangeUser(name, password, roles, domains)
if REQUEST: if REQUEST:
return self._mainUser(self, REQUEST) return self._mainUser(self, REQUEST)
...@@ -222,10 +192,7 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager, ...@@ -222,10 +192,7 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager,
@requestmethod('POST') @requestmethod('POST')
def _delUsers(self, names, REQUEST=None): def _delUsers(self, names, REQUEST=None):
if not names: if not names:
return MessageDialog( raise BadRequest('No users specified')
title='Illegal value',
message='No users specified',
action='manage_main')
self._doDelUsers(names) self._doDelUsers(names)
if REQUEST: if REQUEST:
return self._mainUser(self, REQUEST) return self._mainUser(self, REQUEST)
...@@ -242,11 +209,8 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager, ...@@ -242,11 +209,8 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager,
if submit == 'Edit': if submit == 'Edit':
try: try:
user = self.getUser(reqattr(REQUEST, 'name')) user = self.getUser(reqattr(REQUEST, 'name'))
except: except Exception:
return MessageDialog( raise BadRequest('The specified user does not exist')
title='Illegal value',
message='The specified user does not exist',
action='manage_main')
return self._editUser(self, REQUEST, user=user, password=user.__) return self._editUser(self, REQUEST, user=user, password=user.__)
if submit == 'Add': if submit == 'Add':
...@@ -287,10 +251,7 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager, ...@@ -287,10 +251,7 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager,
def _setId(self, id): def _setId(self, id):
if id != self.id: if id != self.id:
raise ValueError(MessageDialog( raise ValueError('Cannot change the id of a UserFolder')
title='Invalid Id',
message='Cannot change the id of a UserFolder',
action='./manage_main'))
InitializeClass(BasicUserFolder) InitializeClass(BasicUserFolder)
...@@ -341,11 +302,8 @@ def manage_addUserFolder(self, dtself=None, REQUEST=None, **ignored): ...@@ -341,11 +302,8 @@ def manage_addUserFolder(self, dtself=None, REQUEST=None, **ignored):
self = self.this() self = self.this()
try: try:
self._setObject('acl_users', f) self._setObject('acl_users', f)
except: except Exception:
return MessageDialog( raise BadRequest('This object already contains a User Folder')
title='Item Exists',
message='This object already contains a User Folder',
action='%s/manage_main' % REQUEST['URL1'])
self.__allow_groups__ = f self.__allow_groups__ = f
if REQUEST is not None: if REQUEST is not None:
REQUEST['RESPONSE'].redirect(self.absolute_url() + '/manage_main') REQUEST['RESPONSE'].redirect(self.absolute_url() + '/manage_main')
...@@ -3,10 +3,9 @@ ...@@ -3,10 +3,9 @@
Defines the VirtualHostMonster class Defines the VirtualHostMonster class
""" """
from AccessControl.class_init import InitializeClass from AccessControl.class_init import InitializeClass
from AccessControl.Permissions import view as View from AccessControl.Permissions import view as View # NOQA
from AccessControl.SecurityInfo import ClassSecurityInfo from AccessControl.SecurityInfo import ClassSecurityInfo
from Acquisition import Implicit from Acquisition import Implicit
from App.Dialogs import MessageDialog
from App.special_dtml import DTMLFile from App.special_dtml import DTMLFile
from OFS.SimpleItem import Item from OFS.SimpleItem import Item
from Persistence import Persistent from Persistence import Persistent
...@@ -116,11 +115,6 @@ class VirtualHostMonster(Persistent, Item, Implicit): ...@@ -116,11 +115,6 @@ class VirtualHostMonster(Persistent, Item, Implicit):
def manage_addToContainer(self, container, nextURL=''): def manage_addToContainer(self, container, nextURL=''):
self.addToContainer(container) self.addToContainer(container)
if nextURL:
return MessageDialog(
title='Item Added',
message='This object now has a %s' % self.meta_type,
action=nextURL)
def manage_beforeDelete(self, item, container): def manage_beforeDelete(self, item, container):
if item is self: if item is self:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment