Skip to content

Commit

Permalink
Allow undo changes on folders when sub-resouces are locked.
Browse files Browse the repository at this point in the history
  • Loading branch information
dSeidel committed Mar 12, 2024
1 parent 37ccb61 commit 477ac68
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ GUI_UNDO_RECURSIVE_SINGLE_FILE_0=.
GUI_UNDO_RECURSIVE_MULTI_FOLDER_0=Für diese Ordner und alle enthaltenen Ressourcen
GUI_UNDO_RECURSIVE_MULTI_FILE_0=.

GUI_UNDO_LOCKS_ON_SUBRESOURCES_WARNING_0=Die Optionen sind deaktiviert, da Ressourcen innerhalb eines Ordners von einem anderen Nutzer gesperrt sind.

GUI_PREF_WORKPLACE_MODE_0=Workplace
GUI_PREF_WORKPLACE_MODE_OLD_0=Traditionell
Expand Down
7 changes: 6 additions & 1 deletion src/org/opencms/db/CmsSecurityManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6489,7 +6489,12 @@ public void undoChanges(CmsRequestContext context, CmsResource resource, CmsReso
CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
try {
checkOfflineProject(dbc);
checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL);
checkPermissions(
dbc,
resource,
CmsPermissionSet.ACCESS_WRITE,
resource.isFile() || mode.isRecursive() || (mode == CmsResource.UNDO_MOVE_CONTENT) ? LockCheck.yes : LockCheck.shallowOnly,
CmsResourceFilter.ALL);
checkSystemLocks(dbc, resource);

m_driverManager.undoChanges(dbc, resource, mode);
Expand Down
3 changes: 3 additions & 0 deletions src/org/opencms/ui/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ public final class Messages extends A_CmsMessageBundle {
/** Message constant for key in the resource bundle. */
public static final String GUI_UNDO_UNDOMOVE_0 = "GUI_UNDO_UNDOMOVE_0";

/** Message constant for key in the resource bundle. */
public static final String GUI_UNDO_LOCKS_ON_SUBRESOURCES_WARNING_0 = "GUI_UNDO_LOCKS_ON_SUBRESOURCES_WARNING_0";

/** Message constant for key in the resource bundle. */
public static final String GUI_UNUSED_CONTENT_FINDER_0 = "GUI_UNUSED_CONTENT_FINDER_0";

Expand Down
58 changes: 36 additions & 22 deletions src/org/opencms/ui/actions/A_CmsWorkplaceAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,37 @@ public String getDialogTitle() {
}

/**
* Returns the workplace message bundle key of the action dialog title.<p>
*
* @return the dialog title message bundle key
* @see org.opencms.ui.actions.I_CmsWorkplaceAction#getTitle(java.util.Locale)
*/
protected String getDialogTitleKey() {
public String getTitle(Locale locale) {

return getTitleKey();
return OpenCms.getWorkplaceManager().getMessages(locale).key(getTitleKey());
}

/**
* @see org.opencms.ui.actions.I_CmsWorkplaceAction#getTitle(java.util.Locale)
* @see org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility#getVisibility(org.opencms.ui.I_CmsDialogContext)
*/
public String getTitle(Locale locale) {
public CmsMenuItemVisibilityMode getVisibility(I_CmsDialogContext context) {

return OpenCms.getWorkplaceManager().getMessages(locale).key(getTitleKey());
return getVisibility(context.getCms(), context.getResources());
}

/**
* @see org.opencms.ui.actions.I_CmsWorkplaceAction#isActive(org.opencms.ui.I_CmsDialogContext)
*/
public boolean isActive(I_CmsDialogContext context) {

return getVisibility(context).isActive();
}

/**
* Returns the workplace message bundle key of the action dialog title.<p>
*
* @return the dialog title message bundle key
*/
protected String getDialogTitleKey() {

return getTitleKey();
}

/**
Expand All @@ -93,22 +109,28 @@ public String getTitle(Locale locale) {
protected abstract String getTitleKey();

/**
* @see org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility#getVisibility(org.opencms.ui.I_CmsDialogContext)
* Returns if there are any blocking locks within the context resources.<p>
* Will open the blocking locks dialog if required.<p>
*
* @param context the dialog context
*
* @return <code>true</code> in case of blocking locks
*/
public CmsMenuItemVisibilityMode getVisibility(I_CmsDialogContext context) {
protected boolean hasBlockingLocks(final I_CmsDialogContext context) {

return getVisibility(context.getCms(), context.getResources());
return hasBlockingLocks(context, true);
}

/**
* Returns if there are any blocking locks within the context resources.<p>
* Will open the blocking locks dialog if required.<p>
*
* @param context the dialog context
* @param showDialog flag, indicating if the dialog should be displayed, hinting to the locked resources.
*
* @return <code>true</code> in case of blocking locks
*/
protected boolean hasBlockingLocks(final I_CmsDialogContext context) {
protected boolean hasBlockingLocks(final I_CmsDialogContext context, boolean showDialog) {

CmsObject cms = context.getCms();
List<CmsResource> resources = context.getResources();
Expand All @@ -122,7 +144,7 @@ protected boolean hasBlockingLocks(final I_CmsDialogContext context) {
}
if (blocked.isEmpty()) {
return false;
} else {
} else if (showDialog) {

CmsLockedResourcesList dialog = new CmsLockedResourcesList(
cms,
Expand All @@ -141,17 +163,9 @@ public void run() {
context.start(
CmsVaadinUtils.getMessageText(org.opencms.workplace.explorer.Messages.GUI_EXPLORER_CONTEXT_LOCKS_0),
dialog);
}
return true;
}
}

/**
* @see org.opencms.ui.actions.I_CmsWorkplaceAction#isActive(org.opencms.ui.I_CmsDialogContext)
*/
public boolean isActive(I_CmsDialogContext context) {

return getVisibility(context).isActive();
}

/**
* Opens the given dialog in a new overlay window.<p>
Expand Down
4 changes: 1 addition & 3 deletions src/org/opencms/ui/actions/CmsUndoDialogAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public class CmsUndoDialogAction extends A_CmsWorkplaceAction implements I_CmsAD
*/
public void executeAction(I_CmsDialogContext context) {

if (!hasBlockingLocks(context)) {
openDialog(new CmsUndoDialog(context), context);
}
openDialog(new CmsUndoDialog(context, hasBlockingLocks(context, false)), context);
}

/**
Expand Down
39 changes: 22 additions & 17 deletions src/org/opencms/ui/dialogs/CmsUndoDialog.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<meta name="package-mapping" content="u:org.opencms.ui" />
<meta name="package-mapping" content="o:org.opencms.ui.components" />
<head>
<meta name="package-mapping" content="o:org.opencms.ui.components" />
</head>
<body>
<o-cms-basic-dialog>
<content>
<v-form-layout>
<vaadin7-label _id="m_modifiedText" visible="false"/>
<vaadin7-label _id="m_infoText" />
<vaadin7-option-group _id="m_modifySubresourcesField" />
<vaadin7-check-box _id="m_undoMoveField" caption="%(key.GUI_UNDO_UNDOMOVE_0)" />
</v-form-layout>
</content>
<buttons>
<v-button _id="m_okButton" >%(key.GUI_DIALOG_BUTTON_OK_0)</v-button>
<v-button _id="m_cancelButton" >%(key.GUI_DIALOG_BUTTON_CANCEL_0)</v-button>
</buttons>
</o-cms-basic-dialog>
<o-cms-basic-dialog>
<content>
<v-form-layout>
<vaadin7-vertical-layout width="100%" _id="m_lockWarning" style-name="o-error-dialog" visible="false">
<vaadin7-horizontal-layout height="70px" width="100%">
<vaadin7-label _id="m_icon" width="60px" style-name="o-warning-icon" :middle />
<vaadin7-label :expand style-name="o-error-message" :middle>%(key.GUI_UNDO_LOCKS_ON_SUBRESOURCES_WARNING_0)</vaadin7-label>
</vaadin7-horizontal-layout>
</vaadin7-vertical-layout>
<vaadin7-label _id="m_modifiedText" visible="false"/>
<vaadin7-label _id="m_infoText" />
<vaadin7-option-group _id="m_modifySubresourcesField" />
<vaadin7-check-box _id="m_undoMoveField" caption="%(key.GUI_UNDO_UNDOMOVE_0)" />
</v-form-layout>
</content>
<buttons>
<v-button _id="m_okButton" >%(key.GUI_DIALOG_BUTTON_OK_0)</v-button>
<v-button _id="m_cancelButton" >%(key.GUI_DIALOG_BUTTON_CANCEL_0)</v-button>
</buttons>
</o-cms-basic-dialog>
</body>
</html>
26 changes: 24 additions & 2 deletions src/org/opencms/ui/dialogs/CmsUndoDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.opencms.main.OpenCms;
import org.opencms.ui.A_CmsUI;
import org.opencms.ui.CmsVaadinUtils;
import org.opencms.ui.FontOpenCms;
import org.opencms.ui.I_CmsDialogContext;
import org.opencms.ui.components.CmsBasicDialog;
import org.opencms.ui.components.CmsOkCancelActionHandler;
Expand All @@ -56,9 +57,11 @@
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.v7.shared.ui.label.ContentMode;
import com.vaadin.v7.ui.CheckBox;
import com.vaadin.v7.ui.Label;
import com.vaadin.v7.ui.OptionGroup;
import com.vaadin.v7.ui.VerticalLayout;

/**
* Dialog used to change resource modification times.<p>
Expand Down Expand Up @@ -92,12 +95,20 @@ public class CmsUndoDialog extends CmsBasicDialog {
/** The date selection field. */
private CheckBox m_undoMoveField;

/** The lock warning to display if sub-resources are locked. */
private VerticalLayout m_lockWarning;

/** The warning icon */
private Label m_icon;

/**
* Creates a new instance.<p>
*
* @param context the dialog context
* @param hasBlockingLocksOnSubResources flag, indicating if there are blocking locks on sub-resources
*/
public CmsUndoDialog(I_CmsDialogContext context) {
public CmsUndoDialog(I_CmsDialogContext context, boolean hasBlockingLocksOnSubResources) {

m_context = context;
CmsVaadinUtils.readAndLocalizeDesign(
this,
Expand Down Expand Up @@ -145,6 +156,14 @@ public CmsUndoDialog(I_CmsDialogContext context) {
m_modifySubresourcesField.setValue("false");

m_undoMoveField.setVisible(hasFolders || hasMoved);
if (hasBlockingLocksOnSubResources) {
m_modifySubresourcesField.setItemEnabled("true", false);
m_undoMoveField.setEnabled(false);
m_icon.setContentMode(ContentMode.HTML);
m_icon.setValue(FontOpenCms.WARNING.getHtml());
m_lockWarning.setVisible(true);
}

m_cancelButton.addClickListener(new ClickListener() {

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -204,7 +223,10 @@ protected void undo() {
}
CmsLockActionRecord actionRecord = null;
try {
actionRecord = CmsLockUtil.ensureLock(m_context.getCms(), resource);
actionRecord = CmsLockUtil.ensureLock(
m_context.getCms(),
resource,
!(resource.isFile() || recursive || undoMove));
CmsResourceUndoMode mode = CmsResourceUndoMode.getUndoMode(undoMove, recursive);
cms.undoChanges(cms.getSitePath(resource), mode);
if (undoMove) {
Expand Down
1 change: 1 addition & 0 deletions src/org/opencms/ui/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ GUI_UNDO_RECURSIVE_SINGLE_FILE_0=.
GUI_UNDO_RECURSIVE_MULTI_FOLDER_0=On these folders and all resources contained in the folders
GUI_UNDO_RECURSIVE_MULTI_FILE_0=.

GUI_UNDO_LOCKS_ON_SUBRESOURCES_WARNING_0=Options are disabled since resources inside a folder are locked by another user.


GUI_PREF_WORKPLACE_MODE_0=Workplace
Expand Down

0 comments on commit 477ac68

Please sign in to comment.