CCM NG/ccm-cms:
- Added WorkflowLockedComponentAccess component - Placeholder for ItemTemplates component git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4470 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
d1e4d27ceb
commit
eab9004678
|
|
@ -0,0 +1,261 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.templates;
|
||||
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.ControlLink;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SegmentedPanel;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.Table;
|
||||
import com.arsdigita.bebop.Text;
|
||||
import com.arsdigita.bebop.event.ActionEvent;
|
||||
import com.arsdigita.bebop.event.ActionListener;
|
||||
import com.arsdigita.bebop.event.PrintEvent;
|
||||
import com.arsdigita.bebop.event.PrintListener;
|
||||
import com.arsdigita.bebop.event.TableActionAdapter;
|
||||
import com.arsdigita.bebop.event.TableActionEvent;
|
||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||
import com.arsdigita.bebop.table.TableColumn;
|
||||
import com.arsdigita.cms.CMS;
|
||||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentType;
|
||||
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.ui.SecurityPropertyEditor;
|
||||
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
|
||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
||||
import com.arsdigita.util.Assert;
|
||||
|
||||
/**
|
||||
* This component will eventually contain the full templates UI for
|
||||
* content items. It is just a placeholder for now.
|
||||
*
|
||||
* @author Stanislav Freidin
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ItemTemplates extends SecurityPropertyEditor {
|
||||
private ItemSelectionModel m_itemModel;
|
||||
|
||||
public static final String ASSIGN_TEMPLATE = "assignTemplate";
|
||||
|
||||
/**
|
||||
* Construct a new ItemTemplates component
|
||||
*
|
||||
* @param model the <code>ItemSelectionModel</code> that will supply the
|
||||
* current content item
|
||||
*/
|
||||
public ItemTemplates(ItemSelectionModel model) {
|
||||
super();
|
||||
m_itemModel = model;
|
||||
|
||||
addComponent("Placeholder", new Text("Placeholder"));
|
||||
|
||||
// ToDo
|
||||
// ItemTemplatesListingImpl l = new ItemTemplatesListingImpl(model);
|
||||
//
|
||||
// final LayoutPanel layout = new LayoutPanel();
|
||||
// setDisplayComponent(layout);
|
||||
//
|
||||
// SegmentedPanel st = new SegmentedPanel();
|
||||
// layout.setBody(st);
|
||||
//
|
||||
// st.addSegment(new Label(GlobalizationUtil.globalize("cms.ui.templates.assigned_templates")), l);
|
||||
//
|
||||
// SegmentedPanel sa = new SegmentedPanel();
|
||||
// Label assignLabel = new Label(GlobalizationUtil.globalize("cms.ui.templates.dummy"));
|
||||
// assignLabel.addPrintListener(new PrintListener() {
|
||||
// public void prepare(PrintEvent e) {
|
||||
// PageState s = e.getPageState();
|
||||
// Label targetLabel = (Label)e.getTarget();
|
||||
// ContentPage item = (ContentPage)m_itemModel.getSelectedItem(s);
|
||||
// Assert.exists(item, "item");
|
||||
// targetLabel.setLabel( (String) GlobalizationUtil.globalize("cms.ui.templates.assign_a_template_to").localize() + item.getTitle());
|
||||
// }
|
||||
// });
|
||||
// sa.addSegment(assignLabel,
|
||||
// new AvailableTemplatesListing(l.getRowSelectionModel()));
|
||||
// addComponent(ASSIGN_TEMPLATE, sa);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a list of templates which are currently assigned to
|
||||
* the current item
|
||||
*/
|
||||
// protected class ItemTemplatesListingImpl extends ItemTemplatesListing {
|
||||
//
|
||||
// private WorkflowLockedComponentAccess m_access;
|
||||
//
|
||||
// public ItemTemplatesListingImpl(ItemSelectionModel model) {
|
||||
// super(model);
|
||||
// m_access = new WorkflowLockedComponentAccess(null, model);
|
||||
// }
|
||||
//
|
||||
// public void assignLinkClicked(PageState s,
|
||||
// ContentItem item,
|
||||
// String useContext) {
|
||||
// showComponent(s, ASSIGN_TEMPLATE);
|
||||
// }
|
||||
//
|
||||
// public void register(Page p) {
|
||||
// super.register(p);
|
||||
// // Hide action columns if user has no access
|
||||
// p.addActionListener(new ActionListener() {
|
||||
// public void actionPerformed(ActionEvent e) {
|
||||
// final PageState state = e.getPageState();
|
||||
//
|
||||
// if (state.isVisibleOnPage(ItemTemplates.this)) {
|
||||
// if (m_access.canAccess
|
||||
// (state,
|
||||
// CMS.getContext().getSecurityManager())) {
|
||||
// getRemoveColumn().setVisible(state, true);
|
||||
// getAssignColumn().setVisible(state, true);
|
||||
// } else {
|
||||
// getRemoveColumn().setVisible(state, false);
|
||||
// getAssignColumn().setVisible(state, false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Displays a list of templates for the given content item in the
|
||||
// * given context, along with a link to select a template
|
||||
// */
|
||||
// protected class AvailableTemplatesListing extends TemplatesListing {
|
||||
//
|
||||
// TableColumn m_assignCol;
|
||||
// SingleSelectionModel m_contextModel;
|
||||
//
|
||||
// /**
|
||||
// * Construct a new AvailableTemplatesListing
|
||||
// *
|
||||
// * @param contextModel the SingleSelectionModel that will define the
|
||||
// * current use context
|
||||
// */
|
||||
// public AvailableTemplatesListing(SingleSelectionModel contextModel) {
|
||||
// super();
|
||||
// m_contextModel = contextModel;
|
||||
//
|
||||
// // Add the "assign" column and corresponding action listener
|
||||
// m_assignCol = addColumn("Assign",
|
||||
// TemplateCollection.TEMPLATE, false,
|
||||
// new AssignCellRenderer());
|
||||
//
|
||||
// addTableActionListener(new TableActionAdapter() {
|
||||
// public void cellSelected(TableActionEvent e) {
|
||||
// PageState s = e.getPageState();
|
||||
// TemplatesListing l = (TemplatesListing)e.getSource();
|
||||
// int i = e.getColumn().intValue();
|
||||
// TableColumn c = l.getColumnModel().get(i);
|
||||
//
|
||||
// // Safe to check pointer equality since the column is
|
||||
// // created statically
|
||||
// if(c == m_assignCol) {
|
||||
// SectionTemplateMapping m =
|
||||
// (SectionTemplateMapping)getMappingModel().getSelectedObject(s);
|
||||
// assignTemplate(s, m.getTemplate());
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get all the templates for the given context in the current section
|
||||
// */
|
||||
// protected TemplateCollection getTemplateCollection(PageState s) {
|
||||
// ContentSection sec = CMS.getContext().getContentSection();
|
||||
//
|
||||
// ContentItem item = m_itemModel.getSelectedItem(s);
|
||||
// Assert.exists(item, "item");
|
||||
//
|
||||
// ContentType type = item.getContentType();
|
||||
// Assert.exists(type, "content type");
|
||||
//
|
||||
// MimeType mimeType = getMimeType(s);
|
||||
// TemplateCollection c =
|
||||
// TemplateManagerFactory.getInstance().getTemplates(sec, type);
|
||||
// if (mimeType != null) {
|
||||
// c.addEqualsFilter(TemplateCollection.TEMPLATE + "." +
|
||||
// Template.MIME_TYPE + "." +
|
||||
// MimeType.MIME_TYPE, mimeType.getMimeType());
|
||||
// }
|
||||
// c.addEqualsFilter(TemplateCollection.USE_CONTEXT,
|
||||
// getUseContext(s));
|
||||
// return c;
|
||||
// }
|
||||
//
|
||||
// // TODO: this is a 100% convoluted interdependent mess that
|
||||
// // really needs to be reworked
|
||||
// /**
|
||||
// * Get the currently selected use context
|
||||
// */
|
||||
// protected String getUseContext(PageState s) {
|
||||
// String c = (String)m_contextModel.getSelectedKey(s);
|
||||
// Assert.exists(c, "use context");
|
||||
// return ItemTemplatesListing.getUseContextFromKey(c);
|
||||
// }
|
||||
//
|
||||
// protected MimeType getMimeType(PageState s) {
|
||||
// String key = (String)m_contextModel.getSelectedKey(s);
|
||||
// return ItemTemplatesListing.getMimeTypeFromKey(key);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Assign a template to the current item
|
||||
// */
|
||||
// public void assignTemplate(PageState s, Template t) {
|
||||
// ContentItem item = m_itemModel.getSelectedItem(s);
|
||||
// Assert.exists(item, "item");
|
||||
//
|
||||
// TemplateManagerFactory.getInstance()
|
||||
// .addTemplate(item, t, getUseContext(s));
|
||||
//
|
||||
// showDisplayPane(s);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Render the "assign" link
|
||||
// */
|
||||
// protected class AssignCellRenderer implements TableCellRenderer {
|
||||
//
|
||||
// private ControlLink m_link;
|
||||
//
|
||||
// public AssignCellRenderer() {
|
||||
// m_link = new ControlLink
|
||||
// (new Label(GlobalizationUtil.globalize
|
||||
// ("cms.ui.templates.assign_this_template")));
|
||||
// m_link.setClassAttr("assignTemplateLink");
|
||||
// }
|
||||
//
|
||||
// public Component getComponent(Table table, PageState state, Object value,
|
||||
// boolean isSelected, Object key,
|
||||
// int row, int column) {
|
||||
// return m_link;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
@ -1,258 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.templates;
|
||||
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.ControlLink;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SegmentedPanel;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.Table;
|
||||
import com.arsdigita.bebop.event.ActionEvent;
|
||||
import com.arsdigita.bebop.event.ActionListener;
|
||||
import com.arsdigita.bebop.event.PrintEvent;
|
||||
import com.arsdigita.bebop.event.PrintListener;
|
||||
import com.arsdigita.bebop.event.TableActionAdapter;
|
||||
import com.arsdigita.bebop.event.TableActionEvent;
|
||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||
import com.arsdigita.bebop.table.TableColumn;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentType;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.Template;
|
||||
import com.arsdigita.cms.TemplateCollection;
|
||||
import com.arsdigita.cms.TemplateManagerFactory;
|
||||
import com.arsdigita.cms.ui.SecurityPropertyEditor;
|
||||
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
|
||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
||||
import com.arsdigita.util.Assert;
|
||||
|
||||
/**
|
||||
* This component will eventually contain the full templates UI for
|
||||
* content items. It is just a placeholder for now.
|
||||
*
|
||||
* @author Stanislav Freidin
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ItemTemplates extends SecurityPropertyEditor {
|
||||
private ItemSelectionModel m_itemModel;
|
||||
|
||||
public static final String ASSIGN_TEMPLATE = "assignTemplate";
|
||||
|
||||
/**
|
||||
* Construct a new ItemTemplates component
|
||||
*
|
||||
* @param model the <code>ItemSelectionModel</code> that will supply the
|
||||
* current content item
|
||||
*/
|
||||
public ItemTemplates(ItemSelectionModel model) {
|
||||
super();
|
||||
m_itemModel = model;
|
||||
|
||||
ItemTemplatesListingImpl l = new ItemTemplatesListingImpl(model);
|
||||
|
||||
final LayoutPanel layout = new LayoutPanel();
|
||||
setDisplayComponent(layout);
|
||||
|
||||
SegmentedPanel st = new SegmentedPanel();
|
||||
layout.setBody(st);
|
||||
|
||||
st.addSegment(new Label(GlobalizationUtil.globalize("cms.ui.templates.assigned_templates")), l);
|
||||
|
||||
SegmentedPanel sa = new SegmentedPanel();
|
||||
Label assignLabel = new Label(GlobalizationUtil.globalize("cms.ui.templates.dummy"));
|
||||
assignLabel.addPrintListener(new PrintListener() {
|
||||
public void prepare(PrintEvent e) {
|
||||
PageState s = e.getPageState();
|
||||
Label targetLabel = (Label)e.getTarget();
|
||||
ContentPage item = (ContentPage)m_itemModel.getSelectedItem(s);
|
||||
Assert.exists(item, "item");
|
||||
targetLabel.setLabel( (String) GlobalizationUtil.globalize("cms.ui.templates.assign_a_template_to").localize() + item.getTitle());
|
||||
}
|
||||
});
|
||||
sa.addSegment(assignLabel,
|
||||
new AvailableTemplatesListing(l.getRowSelectionModel()));
|
||||
addComponent(ASSIGN_TEMPLATE, sa);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a list of templates which are currently assigned to
|
||||
* the current item
|
||||
*/
|
||||
protected class ItemTemplatesListingImpl extends ItemTemplatesListing {
|
||||
|
||||
private WorkflowLockedComponentAccess m_access;
|
||||
|
||||
public ItemTemplatesListingImpl(ItemSelectionModel model) {
|
||||
super(model);
|
||||
m_access = new WorkflowLockedComponentAccess(null, model);
|
||||
}
|
||||
|
||||
public void assignLinkClicked(PageState s,
|
||||
ContentItem item,
|
||||
String useContext) {
|
||||
showComponent(s, ASSIGN_TEMPLATE);
|
||||
}
|
||||
|
||||
public void register(Page p) {
|
||||
super.register(p);
|
||||
// Hide action columns if user has no access
|
||||
p.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final PageState state = e.getPageState();
|
||||
|
||||
if (state.isVisibleOnPage(ItemTemplates.this)) {
|
||||
if (m_access.canAccess
|
||||
(state,
|
||||
CMS.getContext().getSecurityManager())) {
|
||||
getRemoveColumn().setVisible(state, true);
|
||||
getAssignColumn().setVisible(state, true);
|
||||
} else {
|
||||
getRemoveColumn().setVisible(state, false);
|
||||
getAssignColumn().setVisible(state, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a list of templates for the given content item in the
|
||||
* given context, along with a link to select a template
|
||||
*/
|
||||
protected class AvailableTemplatesListing extends TemplatesListing {
|
||||
|
||||
TableColumn m_assignCol;
|
||||
SingleSelectionModel m_contextModel;
|
||||
|
||||
/**
|
||||
* Construct a new AvailableTemplatesListing
|
||||
*
|
||||
* @param contextModel the SingleSelectionModel that will define the
|
||||
* current use context
|
||||
*/
|
||||
public AvailableTemplatesListing(SingleSelectionModel contextModel) {
|
||||
super();
|
||||
m_contextModel = contextModel;
|
||||
|
||||
// Add the "assign" column and corresponding action listener
|
||||
m_assignCol = addColumn("Assign",
|
||||
TemplateCollection.TEMPLATE, false,
|
||||
new AssignCellRenderer());
|
||||
|
||||
addTableActionListener(new TableActionAdapter() {
|
||||
public void cellSelected(TableActionEvent e) {
|
||||
PageState s = e.getPageState();
|
||||
TemplatesListing l = (TemplatesListing)e.getSource();
|
||||
int i = e.getColumn().intValue();
|
||||
TableColumn c = l.getColumnModel().get(i);
|
||||
|
||||
// Safe to check pointer equality since the column is
|
||||
// created statically
|
||||
if(c == m_assignCol) {
|
||||
SectionTemplateMapping m =
|
||||
(SectionTemplateMapping)getMappingModel().getSelectedObject(s);
|
||||
assignTemplate(s, m.getTemplate());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the templates for the given context in the current section
|
||||
*/
|
||||
protected TemplateCollection getTemplateCollection(PageState s) {
|
||||
ContentSection sec = CMS.getContext().getContentSection();
|
||||
|
||||
ContentItem item = m_itemModel.getSelectedItem(s);
|
||||
Assert.exists(item, "item");
|
||||
|
||||
ContentType type = item.getContentType();
|
||||
Assert.exists(type, "content type");
|
||||
|
||||
MimeType mimeType = getMimeType(s);
|
||||
TemplateCollection c =
|
||||
TemplateManagerFactory.getInstance().getTemplates(sec, type);
|
||||
if (mimeType != null) {
|
||||
c.addEqualsFilter(TemplateCollection.TEMPLATE + "." +
|
||||
Template.MIME_TYPE + "." +
|
||||
MimeType.MIME_TYPE, mimeType.getMimeType());
|
||||
}
|
||||
c.addEqualsFilter(TemplateCollection.USE_CONTEXT,
|
||||
getUseContext(s));
|
||||
return c;
|
||||
}
|
||||
|
||||
// TODO: this is a 100% convoluted interdependent mess that
|
||||
// really needs to be reworked
|
||||
/**
|
||||
* Get the currently selected use context
|
||||
*/
|
||||
protected String getUseContext(PageState s) {
|
||||
String c = (String)m_contextModel.getSelectedKey(s);
|
||||
Assert.exists(c, "use context");
|
||||
return ItemTemplatesListing.getUseContextFromKey(c);
|
||||
}
|
||||
|
||||
protected MimeType getMimeType(PageState s) {
|
||||
String key = (String)m_contextModel.getSelectedKey(s);
|
||||
return ItemTemplatesListing.getMimeTypeFromKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a template to the current item
|
||||
*/
|
||||
public void assignTemplate(PageState s, Template t) {
|
||||
ContentItem item = m_itemModel.getSelectedItem(s);
|
||||
Assert.exists(item, "item");
|
||||
|
||||
TemplateManagerFactory.getInstance()
|
||||
.addTemplate(item, t, getUseContext(s));
|
||||
|
||||
showDisplayPane(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the "assign" link
|
||||
*/
|
||||
protected class AssignCellRenderer implements TableCellRenderer {
|
||||
|
||||
private ControlLink m_link;
|
||||
|
||||
public AssignCellRenderer() {
|
||||
m_link = new ControlLink
|
||||
(new Label(GlobalizationUtil.globalize
|
||||
("cms.ui.templates.assign_this_template")));
|
||||
m_link.setClassAttr("assignTemplateLink");
|
||||
}
|
||||
|
||||
public Component getComponent(Table table, PageState state, Object value,
|
||||
boolean isSelected, Object key,
|
||||
int row, int column) {
|
||||
return m_link;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.workflow;
|
||||
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.dispatcher.Utilities;
|
||||
import com.arsdigita.toolbox.ui.ComponentAccess;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||
|
||||
/**
|
||||
* A <code>ComponentAccess</code> implementation that respects workflow
|
||||
*
|
||||
* @author Stanislav Freidin
|
||||
* @author Uday Mathur
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class WorkflowLockedComponentAccess extends ComponentAccess {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
WorkflowLockedComponentAccess.class);
|
||||
private final ItemSelectionModel itemModel;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param component The component
|
||||
* @param itemModel
|
||||
*/
|
||||
public WorkflowLockedComponentAccess(final Component component,
|
||||
final ItemSelectionModel itemModel) {
|
||||
super(component);
|
||||
this.itemModel = itemModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param component The component
|
||||
* @param check An access check
|
||||
*/
|
||||
public WorkflowLockedComponentAccess(final Component component,
|
||||
final String check,
|
||||
final ItemSelectionModel itemModel) {
|
||||
super(component, check);
|
||||
this.itemModel = itemModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this item is locked from the workflow module. In addition check
|
||||
* if all the access checks registered to the component pass.
|
||||
*
|
||||
* @param state The page state
|
||||
*
|
||||
* @return true if all the access checks pass, false otherwise
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public boolean canAccess(final PageState state) {
|
||||
final ContentItem item = itemModel.getSelectedObject(state);
|
||||
|
||||
if (isVisible(state) == true) {
|
||||
if (super.canAccess(state)) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||
PermissionChecker.class);
|
||||
|
||||
final boolean result = permissionChecker.isPermitted(
|
||||
ItemPrivileges.EDIT, item);
|
||||
LOGGER.debug(
|
||||
"Superclass security check passed. Result of check "
|
||||
+ "for permission {}.{} is {}.",
|
||||
ItemPrivileges.class.getName(),
|
||||
ItemPrivileges.EDIT,
|
||||
result);
|
||||
|
||||
return result;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to change visiblity of action link created by
|
||||
* SecurityPropertyEditor add-method. If this method returns false, the link
|
||||
* will be hidden, p.ex. to hide a delete link if the component is already
|
||||
* empty.
|
||||
*
|
||||
* @param state The page state
|
||||
*
|
||||
* @return true for default behavior
|
||||
*/
|
||||
public boolean isVisible(final PageState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -22,12 +22,11 @@ import com.arsdigita.bebop.Component;
|
|||
import com.arsdigita.bebop.PageState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
|
||||
import org.libreccm.security.Party;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
|
||||
/**
|
||||
|
|
@ -104,4 +103,8 @@ public class ComponentAccess {
|
|||
return canAccess.orElse(false);
|
||||
}
|
||||
|
||||
public boolean canAccess(final PageState state) {
|
||||
return canAccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue