create separate browser package for security-related views; provide first end-user view: Role Permissions by Type
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@4072 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									ecd69dc7ab
								
							
						
					
					
						commit
						c2ccc9fdb5
					
				
					 10 changed files with 202 additions and 12 deletions
				
			
		|  | @ -81,15 +81,15 @@ fieldset.box table.listing td { | ||||||
|     padding: 0 1px 0 1px; |     padding: 0 1px 0 1px; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| table.listing td.number { | table.listing .number { | ||||||
|     text-align: right; |     text-align: right; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| table.listing td.center { | table.listing .center { | ||||||
|     text-align: center; |     text-align: center; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| table.listing td.nowrap { | table.listing .nowrap { | ||||||
|     white-space: nowrap; |     white-space: nowrap; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -93,15 +93,15 @@ fieldset.box table.listing td { | ||||||
|     padding: 0 1px 0 1px; |     padding: 0 1px 0 1px; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| table.listing td.number { | table.listing .number { | ||||||
|     text-align: right; |     text-align: right; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| table.listing td.center { | table.listing .center { | ||||||
|     text-align: center; |     text-align: center; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| table.listing td.nowrap { | table.listing .nowrap { | ||||||
|     white-space: nowrap; |     white-space: nowrap; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										3
									
								
								security/browser/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								security/browser/__init__.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | """ | ||||||
|  | $Id$ | ||||||
|  | """ | ||||||
							
								
								
									
										58
									
								
								security/browser/audit.pt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								security/browser/audit.pt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,58 @@ | ||||||
|  | <html i18n:domain="loops"> | ||||||
|  | <!-- $Id$ --> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | <metal:macro define-macro="role_permissions"> | ||||||
|  |     <metal:headline use-macro="view/concept_macros/concepttitle" /> | ||||||
|  |     <div> | ||||||
|  |       <form> | ||||||
|  |         <b>Type:</b> | ||||||
|  |         <span tal:condition="python:len(item.types) <= 1"> | ||||||
|  |           <span tal:content="item/selectedType/label" />   </span> | ||||||
|  |         <span tal:condition="python:len(item.types) > 1"> | ||||||
|  |           <select name="selected_type" | ||||||
|  |                   onchange="submit()"> | ||||||
|  |             <option tal:repeat="type item/types" | ||||||
|  |                     tal:content="type/label" | ||||||
|  |                     tal:attributes="value type/token; | ||||||
|  |                                     selected python: | ||||||
|  |                             type['token'] == item.selectedType['token']">View</option> | ||||||
|  |           </select>   </span> | ||||||
|  |         <b>Permission:</b> | ||||||
|  |         <span tal:condition="python:len(item.permissions) <= 1" | ||||||
|  |               tal:content="item/selectedPermission" /> | ||||||
|  |         <select name="selected_permission" | ||||||
|  |                 tal:condition="python:len(item.permissions) > 1" | ||||||
|  |                 onchange="submit()"> | ||||||
|  |             <option tal:repeat="perm item/permissions" | ||||||
|  |                     tal:content="perm" | ||||||
|  |                     tal:attributes="value perm; | ||||||
|  |                                     selected python: | ||||||
|  |                             perm == item.selectedPermission">View</option> | ||||||
|  |         </select> | ||||||
|  |       </form> | ||||||
|  |     </div> | ||||||
|  |     <table class="listing"> | ||||||
|  |       <tr> | ||||||
|  |         <th>Object</th> | ||||||
|  |         <th class="center" | ||||||
|  |             tal:repeat="role item/roles" | ||||||
|  |             tal:content="role" /> | ||||||
|  |       </tr> | ||||||
|  |       <tr tal:repeat="obj item/objects"> | ||||||
|  |         <td tal:content="obj/title" /> | ||||||
|  |         <td class="center" | ||||||
|  |             tal:repeat="setting obj/settings" | ||||||
|  |             tal:content="setting" /> | ||||||
|  |       </tr> | ||||||
|  |     </table> | ||||||
|  | </metal:macro> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | <metal:macro define-macro="workspace_assignments"> | ||||||
|  |     <metal:headline use-macro="view/concept_macros/concepttitle" /> | ||||||
|  |     blubb | ||||||
|  | </metal:macro> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | </html> | ||||||
							
								
								
									
										109
									
								
								security/browser/audit.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								security/browser/audit.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,109 @@ | ||||||
|  | # | ||||||
|  | #  Copyright (c) 2010 Helmut Merz helmutm@cy55.de | ||||||
|  | # | ||||||
|  | #  This program is free software; you can redistribute it and/or modify | ||||||
|  | #  it under the terms of the GNU General Public License as published by | ||||||
|  | #  the Free Software Foundation; either version 2 of the License, or | ||||||
|  | #  (at your option) any later version. | ||||||
|  | # | ||||||
|  | #  This program is distributed in the hope that it will be useful, | ||||||
|  | #  but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | #  GNU General Public License for more details. | ||||||
|  | # | ||||||
|  | #  You should have received a copy of the GNU General Public License | ||||||
|  | #  along with this program; if not, write to the Free Software | ||||||
|  | #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||||
|  | # | ||||||
|  | 
 | ||||||
|  | """ | ||||||
|  | End user views for security audits and similar tasks. | ||||||
|  | 
 | ||||||
|  | $Id$ | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | from zope import interface, component | ||||||
|  | from zope.app.pagetemplate import ViewPageTemplateFile | ||||||
|  | from zope.app.securitypolicy.interfaces import IRolePermissionMap | ||||||
|  | from zope.app.securitypolicy.zopepolicy import SettingAsBoolean | ||||||
|  | from zope.cachedescriptors.property import Lazy | ||||||
|  | from zope.traversing.api import getName, getParent | ||||||
|  | 
 | ||||||
|  | from loops.browser.concept import ConceptView | ||||||
|  | from loops import util | ||||||
|  | from loops.util import _ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class BaseSecurityView(ConceptView): | ||||||
|  | 
 | ||||||
|  |     template = ViewPageTemplateFile('audit.pt') | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class RolePermissionsByType(BaseSecurityView): | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def macro(self): | ||||||
|  |         return self.template.macros['role_permissions'] | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def types(self): | ||||||
|  |         result = [self.conceptManager.get(name) for name in self.options('types')] | ||||||
|  |         return [dict(token=getName(t), label=t.title, object=t) | ||||||
|  |                         for t in result if t is not None] | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def selectedType(self): | ||||||
|  |         if 'selected_type' in self.request.form: | ||||||
|  |             typeName = self.request.form['selected_type'] | ||||||
|  |             type = self.conceptManager.get(typeName) | ||||||
|  |             return dict(token=getName(type), label=type.title, object=type) | ||||||
|  |         if self.types: | ||||||
|  |             return self.types[0] | ||||||
|  |         return dict(token=u'', label=u'', object=None) | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def objects(self): | ||||||
|  |         if not self.selectedType: | ||||||
|  |             return [] | ||||||
|  |         result = self.selectedType['object'].getChildren([self.typePredicate]) | ||||||
|  |         return [dict(title=o.title, settings=self.getPermissionSettings(o)) | ||||||
|  |                         for o in result] | ||||||
|  | 
 | ||||||
|  |     def getPermissionSettings(self, obj): | ||||||
|  |         result = [] | ||||||
|  |         rpm = IRolePermissionMap(obj, None) | ||||||
|  |         for r in self.roles: | ||||||
|  |             if rpm is not None: | ||||||
|  |                 setting = rpm.getSetting(self.selectedPermission, r) | ||||||
|  |                 setting = SettingAsBoolean[setting] | ||||||
|  |                 if setting is not None: | ||||||
|  |                     result.append(setting and '+' or '-') | ||||||
|  |                 else: | ||||||
|  |                     result.append(u'') | ||||||
|  |             else: | ||||||
|  |                 result.append(u'') | ||||||
|  |         return result | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def permissions(self): | ||||||
|  |         return self.options('permissions') | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def selectedPermission(self): | ||||||
|  |         if 'selected_permission' in self.request.form: | ||||||
|  |             return self.request.form['selected_permission'] | ||||||
|  |         if self.permissions: | ||||||
|  |             return self.permissions[0] | ||||||
|  |         return u'' | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def roles(self): | ||||||
|  |         return self.options('roles') | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class WorkspaceAssignments(BaseSecurityView): | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def macro(self): | ||||||
|  |         return self.template.macros['workspace_assignments'] | ||||||
|  | 
 | ||||||
|  | @ -37,28 +37,48 @@ | ||||||
|   <zope:subscriber handler="loops.security.common.addGroupMembershipOnAssignment" /> |   <zope:subscriber handler="loops.security.common.addGroupMembershipOnAssignment" /> | ||||||
|   <zope:subscriber handler="loops.security.common.removeGroupMembershipOnDeassignment" /> |   <zope:subscriber handler="loops.security.common.removeGroupMembershipOnDeassignment" /> | ||||||
| 
 | 
 | ||||||
|  |   <!-- views --> | ||||||
|  | 
 | ||||||
|   <browser:page |   <browser:page | ||||||
|         for="zope.annotation.interfaces.IAnnotatable" |         for="zope.annotation.interfaces.IAnnotatable" | ||||||
|         name="permissions.html" |         name="permissions.html" | ||||||
|         permission="zope.Security" |         permission="zope.Security" | ||||||
|         template="manage_permissionform.pt" |         template="browser/manage_permissionform.pt" | ||||||
|         class="loops.security.browser.PermissionView" |         class="loops.security.browser.admin.PermissionView" | ||||||
|         menu="zmi_actions" title="Edit Permissions" /> |         menu="zmi_actions" title="Edit Permissions" /> | ||||||
| 
 | 
 | ||||||
|   <browser:page |   <browser:page | ||||||
|         for="loops.interfaces.IConcept" |         for="loops.interfaces.IConcept" | ||||||
|         name="grant.html" |         name="grant.html" | ||||||
|         permission="zope.Security" |         permission="zope.Security" | ||||||
|         template="granting.pt" |         template="browser/granting.pt" | ||||||
|         class="loops.security.browser.Granting" |         class="loops.security.browser.admin.Granting" | ||||||
|         menu="zmi_actions" title="Grant" /> |         menu="zmi_actions" title="Grant" /> | ||||||
| 
 | 
 | ||||||
|   <browser:page |   <browser:page | ||||||
|         for="loops.interfaces.IConcept" |         for="loops.interfaces.IConcept" | ||||||
|         name="manage_workspace.html" |         name="manage_workspace.html" | ||||||
|         permission="zope.Security" |         permission="zope.Security" | ||||||
|         template="manage_workspace.pt" |         template="browser/manage_workspace.pt" | ||||||
|         class="loops.security.browser.ManageWorkspaceView" |         class="loops.security.browser.admin.ManageWorkspaceView" | ||||||
|         menu="zmi_actions" title="Manage Workspace" /> |         menu="zmi_actions" title="Manage Workspace" /> | ||||||
| 
 | 
 | ||||||
|  |   <!-- end user (audit) views --> | ||||||
|  | 
 | ||||||
|  |   <zope:adapter | ||||||
|  |       name="role_permission_by_type.html" | ||||||
|  |       for="loops.interfaces.IConcept | ||||||
|  |            zope.publisher.interfaces.browser.IBrowserRequest" | ||||||
|  |       provides="zope.interface.Interface" | ||||||
|  |       factory="loops.security.browser.audit.RolePermissionsByType" | ||||||
|  |       permission="loops.ManageSite" /> | ||||||
|  | 
 | ||||||
|  |   <zope:adapter | ||||||
|  |       name="workspace_assignments.html" | ||||||
|  |       for="loops.interfaces.IConcept | ||||||
|  |            zope.publisher.interfaces.browser.IBrowserRequest" | ||||||
|  |       provides="zope.interface.Interface" | ||||||
|  |       factory="loops.security.browser.audit.WorkspaceAssignments" | ||||||
|  |       permission="loops.ManageSite" /> | ||||||
|  | 
 | ||||||
| </configure> | </configure> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm