[gen] Allow Managers to delete data change events if things go wrong.
This commit is contained in:
		
							parent
							
								
									90e46f11e7
								
							
						
					
					
						commit
						b76af3e0c2
					
				
					 3 changed files with 40 additions and 2 deletions
				
			
		|  | @ -102,7 +102,7 @@ class BaseMixin: | ||||||
|         return obj, msg |         return obj, msg | ||||||
| 
 | 
 | ||||||
|     def delete(self): |     def delete(self): | ||||||
|         '''This methods is self's suicide.''' |         '''This method is self's suicide.''' | ||||||
|         # Call a custom "onDelete" if it exists |         # Call a custom "onDelete" if it exists | ||||||
|         appyObj = self.appy() |         appyObj = self.appy() | ||||||
|         if hasattr(appyObj, 'onDelete'): appyObj.onDelete() |         if hasattr(appyObj, 'onDelete'): appyObj.onDelete() | ||||||
|  | @ -129,6 +129,26 @@ class BaseMixin: | ||||||
|         self.say(self.translate('delete_done')) |         self.say(self.translate('delete_done')) | ||||||
|         self.goto(urlBack) |         self.goto(urlBack) | ||||||
| 
 | 
 | ||||||
|  |     def onDeleteEvent(self): | ||||||
|  |         '''Called when an event (from object history) deletion is triggered | ||||||
|  |            from the ui.''' | ||||||
|  |         rq = self.REQUEST | ||||||
|  |         # Re-create object history, but without the event corresponding to | ||||||
|  |         # rq['eventTime'] | ||||||
|  |         history = [] | ||||||
|  |         from DateTime import DateTime | ||||||
|  |         eventToDelete = DateTime(rq['eventTime']) | ||||||
|  |         key = self.workflow_history.keys()[0] | ||||||
|  |         for event in self.workflow_history[key]: | ||||||
|  |             if (event['action'] != '_datachange_') or \ | ||||||
|  |                (event['time'] != eventToDelete): | ||||||
|  |                 history.append(event) | ||||||
|  |         self.workflow_history[key] = tuple(history) | ||||||
|  |         appy = self.appy() | ||||||
|  |         self.log('Data change event deleted by %s for %s (UID=%s).' % \ | ||||||
|  |                  (appy.user.getId(), appy.klass.__name__, appy.uid)) | ||||||
|  |         self.goto(self.getUrl(rq['HTTP_REFERER'])) | ||||||
|  | 
 | ||||||
|     def onUnlink(self): |     def onUnlink(self): | ||||||
|         '''Called when an object unlinking is triggered from the ui.''' |         '''Called when an object unlinking is triggered from the ui.''' | ||||||
|         rq = self.REQUEST |         rq = self.REQUEST | ||||||
|  |  | ||||||
|  | @ -351,6 +351,13 @@ function onDeleteObject(objectUid) { | ||||||
|   askConfirm('form', 'deleteForm', delete_confirm); |   askConfirm('form', 'deleteForm', delete_confirm); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function onDeleteEvent(objectUid, eventTime) { | ||||||
|  |   f = document.getElementById('deleteEventForm'); | ||||||
|  |   f.objectUid.value = objectUid; | ||||||
|  |   f.eventTime.value = eventTime; | ||||||
|  |   askConfirm('form', 'deleteEventForm', delete_confirm); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function onUnlinkObject(sourceUid, fieldName, targetUid) { | function onUnlinkObject(sourceUid, fieldName, targetUid) { | ||||||
|   f = document.getElementById('unlinkForm'); |   f = document.getElementById('unlinkForm'); | ||||||
|   f.sourceUid.value = sourceUid; |   f.sourceUid.value = sourceUid; | ||||||
|  |  | ||||||
|  | @ -18,6 +18,12 @@ | ||||||
|     <input type="hidden" name="action" value="Delete"/> |     <input type="hidden" name="action" value="Delete"/> | ||||||
|     <input type="hidden" name="objectUid"/> |     <input type="hidden" name="objectUid"/> | ||||||
|   </form> |   </form> | ||||||
|  |   <tal:comment replace="nothing">Global form for deleting an event from an object's history</tal:comment> | ||||||
|  |   <form id="deleteEventForm" method="post" action="do"> | ||||||
|  |     <input type="hidden" name="action" value="DeleteEvent"/> | ||||||
|  |     <input type="hidden" name="objectUid"/> | ||||||
|  |     <input type="hidden" name="eventTime"/> | ||||||
|  |   </form> | ||||||
|   <tal:comment replace="nothing">Global form for unlinking an object</tal:comment> |   <tal:comment replace="nothing">Global form for unlinking an object</tal:comment> | ||||||
|   <form id="unlinkForm" method="post" action="do"> |   <form id="unlinkForm" method="post" action="do"> | ||||||
|     <input type="hidden" name="action" value="Unlink"/> |     <input type="hidden" name="action" value="Unlink"/> | ||||||
|  | @ -98,7 +104,12 @@ | ||||||
|                     state event/review_state|nothing; |                     state event/review_state|nothing; | ||||||
|                     isDataChange python: event['action'] == '_datachange_'" |                     isDataChange python: event['action'] == '_datachange_'" | ||||||
|         tal:attributes="class python:test(odd, 'even', 'odd')" valign="top"> |         tal:attributes="class python:test(odd, 'even', 'odd')" valign="top"> | ||||||
|       <td tal:condition="isDataChange" tal:content="python: _('data_change')"></td> |       <td tal:condition="isDataChange"> | ||||||
|  |         <span tal:content="python: _('data_change')"></span> | ||||||
|  |         <img tal:condition="python: user.has_role('Manager')" style="cursor:pointer" | ||||||
|  |              tal:attributes="src string:$appUrl/ui/delete.png; | ||||||
|  |                              onClick python: 'onDeleteEvent(\'%s\', \'%s\')' % (contextObj.UID(), event['time'])"/> | ||||||
|  |       </td> | ||||||
|       <td tal:condition="not: isDataChange" |       <td tal:condition="not: isDataChange" | ||||||
|           tal:content="python: _(contextObj.getWorkflowLabel(event['action']))"/> |           tal:content="python: _(contextObj.getWorkflowLabel(event['action']))"/> | ||||||
|       <td tal:define="actorId python:event.get('actor')" |       <td tal:define="actorId python:event.get('actor')" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Gaetan Delannay
						Gaetan Delannay