[gen] Add the possibility, for an admin, to unlock a page that was locked for too long by some user.

This commit is contained in:
Gaetan Delannay 2013-05-22 10:27:31 +02:00
parent 89c961c5c5
commit fd33e73efa
7 changed files with 46 additions and 11 deletions

View file

@ -19,7 +19,7 @@ except ImportError:
# Errors ----------------------------------------------------------------------- # Errors -----------------------------------------------------------------------
jsMessages = ('no_elem_selected', 'delete_confirm', 'unlink_confirm', jsMessages = ('no_elem_selected', 'delete_confirm', 'unlink_confirm',
'warn_leave_form') 'unlock_confirm', 'warn_leave_form')
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
class ToolMixin(BaseMixin): class ToolMixin(BaseMixin):

View file

@ -229,12 +229,16 @@ class BaseMixin:
if hasattr(self.aq_base, 'locks') and (page in self.locks): if hasattr(self.aq_base, 'locks') and (page in self.locks):
if (user.getId() != self.locks[page][0]): return self.locks[page] if (user.getId() != self.locks[page][0]): return self.locks[page]
def removeLock(self, page): def removeLock(self, page, force=False):
'''Removes the lock on the current page. This happens after the page has '''Removes the lock on the current page. This happens:
been saved: the lock must be released.''' - after the page has been saved: the lock must be released;
- or when an admin wants to force the deletion of a lock that was
left on p_page for too long (p_force=True).
'''
if page not in self.locks: return if page not in self.locks: return
# Raise an error if the user that saves changes is not the one that # Raise an error if the user that saves changes is not the one that
# has locked the page. # has locked the page (excepted if p_force is True)
if not force:
userId = self.getUser().getId() userId = self.getUser().getId()
if self.locks[page][0] != userId: if self.locks[page][0] != userId:
from AccessControl import Unauthorized from AccessControl import Unauthorized
@ -251,6 +255,17 @@ class BaseMixin:
(user.getId() == self.locks[page][0]): (user.getId() == self.locks[page][0]):
del self.locks[page] del self.locks[page]
def onUnlock(self):
'''Called when an admin wants to remove a lock that was left for too
long by some user.'''
rq = self.REQUEST
tool = self.getTool()
obj = tool.getObject(rq['objectUid'])
obj.removeLock(rq['pageName'], force=True)
urlBack = self.getUrl(rq['HTTP_REFERER'])
self.say(self.translate('unlock_done'))
self.goto(urlBack)
def onCreateWithoutForm(self): def onCreateWithoutForm(self):
'''This method is called when a user wants to create a object from a '''This method is called when a user wants to create a object from a
reference field, automatically (without displaying a form).''' reference field, automatically (without displaying a form).'''

View file

@ -73,10 +73,13 @@ appyLabels = [
('object_edit', 'Edit'), ('object_edit', 'Edit'),
('object_delete', 'Delete'), ('object_delete', 'Delete'),
('object_unlink', 'Unlink'), ('object_unlink', 'Unlink'),
('page_unlock', 'Unlock'),
('delete_confirm', 'Are you sure you want to delete this element?'), ('delete_confirm', 'Are you sure you want to delete this element?'),
('unlink_confirm', 'Are you sure you want to unlink this element?'), ('unlink_confirm', 'Are you sure you want to unlink this element?'),
('unlock_confirm', 'Are you sure you want to unlock this page?'),
('delete_done', 'The element has been deleted.'), ('delete_done', 'The element has been deleted.'),
('unlink_done', 'The element has been unlinked.'), ('unlink_done', 'The element has been unlinked.'),
('unlock_done', 'The page has been unlocked.'),
('goto_first', 'Go to top'), ('goto_first', 'Go to top'),
('goto_previous', 'Go to previous'), ('goto_previous', 'Go to previous'),
('goto_next', 'Go to next'), ('goto_next', 'Go to next'),

View file

@ -403,6 +403,13 @@ function onUnlinkObject(sourceUid, fieldName, targetUid) {
askConfirm('form', 'unlinkForm', unlink_confirm); askConfirm('form', 'unlinkForm', unlink_confirm);
} }
function onUnlockPage(objectUid, pageName) {
f = document.getElementById('unlockForm');
f.objectUid.value = objectUid;
f.pageName.value = pageName;
askConfirm('form', 'unlockForm', unlock_confirm);
}
function createCookie(name, value, days) { function createCookie(name, value, days) {
if (days) { if (days) {
var date = new Date(); var date = new Date();

View file

@ -31,6 +31,12 @@
<input type="hidden" name="fieldName"/> <input type="hidden" name="fieldName"/>
<input type="hidden" name="targetUid"/> <input type="hidden" name="targetUid"/>
</form> </form>
<tal:comment replace="nothing">Global form for unlocking a page</tal:comment>
<form id="unlockForm" method="post" action="do">
<input type="hidden" name="action" value="Unlock"/>
<input type="hidden" name="objectUid"/>
<input type="hidden" name="pageName"/>
</form>
<tal:comment replace="nothing">Global form for generating a document from a pod template</tal:comment> <tal:comment replace="nothing">Global form for generating a document from a pod template</tal:comment>
<form id="podTemplateForm" name="podTemplateForm" method="post" <form id="podTemplateForm" name="podTemplateForm" method="post"
tal:attributes="action python: tool.absolute_url() + '/generateDocument'"> tal:attributes="action python: tool.absolute_url() + '/generateDocument'">

View file

@ -163,8 +163,12 @@
<img style="cursor: help" <img style="cursor: help"
tal:define="lockDate python: tool.formatDate(locked[1]); tal:define="lockDate python: tool.formatDate(locked[1]);
lockMsg python: _('page_locked', mapping={'user':tool.getUserName(locked[0]), 'date': lockDate})" lockMsg python: _('page_locked', mapping={'user':tool.getUserName(locked[0]), 'date': lockDate})"
tal:attributes="src string: $appUrl/ui/locked.png; title lockMsg"/> tal:attributes="src string: $appUrl/ui/locked.png; title lockMsg"/></a>
</a> <a tal:condition="python: editable and locked and user.has_role('Manager')">
<img style="cursor: pointer"
tal:attributes="src string: $appUrl/ui/unlock.png;
title python: _('page_unlock');
onclick python: 'onUnlockPage(\'%s\',\'%s\')' % (contextObj.UID(), aPage)"/></a>
</tal:icons> </tal:icons>
</div> </div>
<tal:comment replace="nothing">Next lines: links</tal:comment> <tal:comment replace="nothing">Next lines: links</tal:comment>

BIN
gen/ui/unlock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 649 B