<fim-prefix>st;
import org.olat.core.gui.components.Component;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.controller.BasicController;
import org.olat.core.gui.control.generic.modal.DialogBoxController;
import org.olat.core.gui.control.generic.modal.DialogBoxUIFactory;
import org.olat.core.gui.translator.Translator;
import org.olat.core.util.vfs.VFSConstants;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSItem;
import org.olat.core.util.vfs.VFSLockApplicationType;
import org.olat.core.util.vfs.VFSLockManager;

public class CmdDelete extends BasicController implements FolderCommand {

	private static int status = FolderCommandStatus.STATUS_SUCCESS;

	private Translator translator;
	private FolderComponent folderComponent;
	private FileSelection fileSelection;

	private DialogBoxController dialogCtr;
	private DialogBoxController lockedFiledCtr;
	
	private final boolean versionsEnabled;
	private final VFSLockManager lockManager;
	
	protected CmdDelete(UserRequest ureq, WindowControl wControl) {
		super(ureq, wControl);
		versionsEnabled = CoreSpringFactory.getImpl(VFSVersionModule.class).isEnabled();
		lockManager = CoreSpringFactory.getImpl(VFSLockManager.class);
	}

	@Override
	public Controller execute(FolderComponent fc, UserRequest ureq, WindowControl wContr, Translator trans) {
		this.translator = trans;
		this.folderComponent = fc;
		// BUG: CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
		// this.fileSelection = new FileSelection(ureq, fc.getCurrentContainerPath());
		// FIXED:
	<fim-middle>	this.fileSelection = new FileSelection(ureq, fc.getCurrentContainer(), fc.getCurrentContainerPath());

		VFSContainer currentContainer = folderComponent.getCurrentContainer();
		List<String> lockedFil<fix-suffix>es = hasLockedFiles(currentContainer, fileSelection);
		if (lockedFiles.isEmpty()) {
			String msg = trans.translate("del.confirm") + "<p>" + fileSelection.renderAsHtml() + "</p>";		
			// create dialog controller
			dialogCtr = activateYesNoDialog(ureq, trans.translate("del.header"), msg, dialogCtr);
		} else {
			String msg = FolderCommandHelper.renderLockedMessageAsHtml(trans, lockedFiles);
			List<String> buttonLabels = Collections.singletonList(trans.translate("ok"));
			lockedFiledCtr = activateGenericDialog(ureq, trans.translate("lock.title"), msg, buttonLabels, lockedFiledCtr);
		}
		return this;
	}
	
	public List<String> hasLockedFiles(VFSContainer container, FileSelection selection) {
		List<String> lockedFiles = new ArrayList<>();
		for (String file : selection.getFiles()) {
			VFSItem item = container.resolve(file);
			if (lockManager.isLockedForMe(item, getIdentity(), VFSLockApplicationType.vfs, null)) {
				lockedFiles.add(file);
			}
		}
		return lockedFiles;
	}

	@Overr<|endoftext|>