[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:
parent
89c961c5c5
commit
fd33e73efa
|
@ -19,7 +19,7 @@ except ImportError:
|
|||
|
||||
# Errors -----------------------------------------------------------------------
|
||||
jsMessages = ('no_elem_selected', 'delete_confirm', 'unlink_confirm',
|
||||
'warn_leave_form')
|
||||
'unlock_confirm', 'warn_leave_form')
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
class ToolMixin(BaseMixin):
|
||||
|
|
|
@ -229,16 +229,20 @@ class BaseMixin:
|
|||
if hasattr(self.aq_base, 'locks') and (page in self.locks):
|
||||
if (user.getId() != self.locks[page][0]): return self.locks[page]
|
||||
|
||||
def removeLock(self, page):
|
||||
'''Removes the lock on the current page. This happens after the page has
|
||||
been saved: the lock must be released.'''
|
||||
def removeLock(self, page, force=False):
|
||||
'''Removes the lock on the current page. This happens:
|
||||
- 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
|
||||
# Raise an error if the user that saves changes is not the one that
|
||||
# has locked the page.
|
||||
userId = self.getUser().getId()
|
||||
if self.locks[page][0] != userId:
|
||||
from AccessControl import Unauthorized
|
||||
raise Unauthorized('This page was locked by someone else.')
|
||||
# has locked the page (excepted if p_force is True)
|
||||
if not force:
|
||||
userId = self.getUser().getId()
|
||||
if self.locks[page][0] != userId:
|
||||
from AccessControl import Unauthorized
|
||||
raise Unauthorized('This page was locked by someone else.')
|
||||
# Remove the lock
|
||||
del self.locks[page]
|
||||
|
||||
|
@ -251,6 +255,17 @@ class BaseMixin:
|
|||
(user.getId() == self.locks[page][0]):
|
||||
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):
|
||||
'''This method is called when a user wants to create a object from a
|
||||
reference field, automatically (without displaying a form).'''
|
||||
|
|
|
@ -73,10 +73,13 @@ appyLabels = [
|
|||
('object_edit', 'Edit'),
|
||||
('object_delete', 'Delete'),
|
||||
('object_unlink', 'Unlink'),
|
||||
('page_unlock', 'Unlock'),
|
||||
('delete_confirm', 'Are you sure you want to delete 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.'),
|
||||
('unlink_done', 'The element has been unlinked.'),
|
||||
('unlock_done', 'The page has been unlocked.'),
|
||||
('goto_first', 'Go to top'),
|
||||
('goto_previous', 'Go to previous'),
|
||||
('goto_next', 'Go to next'),
|
||||
|
|
|
@ -403,6 +403,13 @@ function onUnlinkObject(sourceUid, fieldName, targetUid) {
|
|||
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) {
|
||||
if (days) {
|
||||
var date = new Date();
|
||||
|
|
|
@ -31,6 +31,12 @@
|
|||
<input type="hidden" name="fieldName"/>
|
||||
<input type="hidden" name="targetUid"/>
|
||||
</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>
|
||||
<form id="podTemplateForm" name="podTemplateForm" method="post"
|
||||
tal:attributes="action python: tool.absolute_url() + '/generateDocument'">
|
||||
|
|
|
@ -163,8 +163,12 @@
|
|||
<img style="cursor: help"
|
||||
tal:define="lockDate python: tool.formatDate(locked[1]);
|
||||
lockMsg python: _('page_locked', mapping={'user':tool.getUserName(locked[0]), 'date': lockDate})"
|
||||
tal:attributes="src string: $appUrl/ui/locked.png; title lockMsg"/>
|
||||
</a>
|
||||
tal:attributes="src string: $appUrl/ui/locked.png; title lockMsg"/></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>
|
||||
</div>
|
||||
<tal:comment replace="nothing">Next lines: links</tal:comment>
|
||||
|
|
BIN
gen/ui/unlock.png
Normal file
BIN
gen/ui/unlock.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 649 B |
Loading…
Reference in a new issue