CCM NG/ccm-cms: Next part of migration of the ContentTypeAdminPane
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4432 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
44e21fb842
commit
91c510edd9
|
|
@ -112,46 +112,47 @@ public final class ContentTypeAdminPane extends BaseAdminPane {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(final ActionEvent event) {
|
public void actionPerformed(final ActionEvent event) {
|
||||||
final PageState state = event.getPageState();
|
// ToDo
|
||||||
ContentType contentType = (ContentType) m_model.getSelectedObject(state);
|
// final PageState state = event.getPageState();
|
||||||
ContentSection section = CMS.getContext().getContentSection();
|
// ContentType contentType = (ContentType) m_model.getSelectedObject(state);
|
||||||
if (contentType == null) {
|
// ContentSection section = CMS.getContext().getContentSection();
|
||||||
final String template = state.getRequest()
|
// if (contentType == null) {
|
||||||
.getParameter(ContentSectionPage
|
// final String template = state.getRequest()
|
||||||
.SET_TEMPLATE);
|
// .getParameter(ContentSectionPage
|
||||||
if (template != null) {
|
// .SET_TEMPLATE);
|
||||||
DataCollection da = SessionManager.getSession().retrieve(SectionTemplateMapping.BASE_DATA_OBJECT_TYPE);
|
// if (template != null) {
|
||||||
DomainCollection c = new DomainCollection(da);
|
// DataCollection da = SessionManager.getSession().retrieve(SectionTemplateMapping.BASE_DATA_OBJECT_TYPE);
|
||||||
c.addEqualsFilter(SectionTemplateMapping.SECTION + "." + ACSObject.ID,
|
// DomainCollection c = new DomainCollection(da);
|
||||||
section.getID());
|
// c.addEqualsFilter(SectionTemplateMapping.SECTION + "." + ACSObject.ID,
|
||||||
c.addEqualsFilter(SectionTemplateMapping.TEMPLATE + "." + ACSObject.ID,
|
// section.getID());
|
||||||
new BigDecimal(template));
|
// c.addEqualsFilter(SectionTemplateMapping.TEMPLATE + "." + ACSObject.ID,
|
||||||
c.addOrder(SectionTemplateMapping.CONTENT_TYPE + "." + ContentType.LABEL);
|
// new BigDecimal(template));
|
||||||
if (c.next()) {
|
// c.addOrder(SectionTemplateMapping.CONTENT_TYPE + "." + ContentType.LABEL);
|
||||||
SectionTemplateMapping mapping =
|
// if (c.next()) {
|
||||||
(SectionTemplateMapping) c.getDomainObject();
|
// SectionTemplateMapping mapping =
|
||||||
contentType = mapping.getContentType();
|
// (SectionTemplateMapping) c.getDomainObject();
|
||||||
}
|
// contentType = mapping.getContentType();
|
||||||
c.close();
|
// }
|
||||||
}
|
// c.close();
|
||||||
if (contentType == null) {
|
// }
|
||||||
ContentTypeCollection contentTypes = section.getContentTypes();
|
// if (contentType == null) {
|
||||||
contentTypes.addOrder("label asc");
|
// ContentTypeCollection contentTypes = section.getContentTypes();
|
||||||
try {
|
// contentTypes.addOrder("label asc");
|
||||||
if (contentTypes.next()) {
|
// try {
|
||||||
contentType = contentTypes.getContentType();
|
// if (contentTypes.next()) {
|
||||||
}
|
// contentType = contentTypes.getContentType();
|
||||||
} finally {
|
// }
|
||||||
contentTypes.close();
|
// } finally {
|
||||||
}
|
// contentTypes.close();
|
||||||
}
|
// }
|
||||||
if (contentType != null) {
|
// }
|
||||||
m_model.setSelectedObject(state, contentType);
|
// if (contentType != null) {
|
||||||
getBody().push(state, getItemPane());
|
// m_model.setSelectedObject(state, contentType);
|
||||||
}
|
// getBody().push(state, getItemPane());
|
||||||
|
// }
|
||||||
|
//
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,14 @@ import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
|
||||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
import com.arsdigita.toolbox.ui.ActionGroup;
|
||||||
import com.arsdigita.toolbox.ui.Cancellable;
|
import com.arsdigita.toolbox.ui.Cancellable;
|
||||||
import com.arsdigita.toolbox.ui.Section;
|
import com.arsdigita.toolbox.ui.Section;
|
||||||
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
|
import java.util.logging.Level;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
import org.librecms.contentsection.ContentSectionManager;
|
||||||
|
import org.librecms.contentsection.ContentTypeManager;
|
||||||
|
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -54,11 +61,10 @@ final class ContentTypeItemPane extends BaseItemPane {
|
||||||
private final ACSObjectSelectionModel m_model;
|
private final ACSObjectSelectionModel m_model;
|
||||||
private final ContentTypeRequestLocal m_type;
|
private final ContentTypeRequestLocal m_type;
|
||||||
private final SimpleContainer m_detailPane;
|
private final SimpleContainer m_detailPane;
|
||||||
private final TypeElements m_elements;
|
// Only useful for user definied content types private final TypeElements m_elements;
|
||||||
private final AddElement m_elementAddForm;
|
// Only useful for user definied content types private final AddElement m_elementAddForm;
|
||||||
//ToDo private final SectionTemplatesListing m_templates;
|
// ToDo private final SectionTemplatesListing m_templates;
|
||||||
private final TypePermissionsTable m_permissions;
|
private final TypePermissionsTable m_permissions;
|
||||||
// private final RelationAttributeSection m_relationAttributes;
|
|
||||||
|
|
||||||
ContentTypeItemPane(final ACSObjectSelectionModel model,
|
ContentTypeItemPane(final ACSObjectSelectionModel model,
|
||||||
final ContentTypeRequestLocal type,
|
final ContentTypeRequestLocal type,
|
||||||
|
|
@ -71,13 +77,11 @@ final class ContentTypeItemPane extends BaseItemPane {
|
||||||
add(m_detailPane);
|
add(m_detailPane);
|
||||||
setDefault(m_detailPane);
|
setDefault(m_detailPane);
|
||||||
|
|
||||||
m_elements = new TypeElements(m_model);
|
// m_elements = new TypeElements(m_model);
|
||||||
m_elementAddForm = new AddElement();
|
// m_elementAddForm = new AddElement();
|
||||||
|
|
||||||
// ToDo
|
// ToDo
|
||||||
// m_templates = new SectionTemplatesListing(
|
// m_templates = new SectionTemplatesListing(
|
||||||
// new ContentSectionRequestLocal(), m_type);
|
// new ContentSectionRequestLocal(), m_type);
|
||||||
|
|
||||||
m_permissions = new TypePermissionsTable(
|
m_permissions = new TypePermissionsTable(
|
||||||
new ContentSectionRequestLocal(), m_type);
|
new ContentSectionRequestLocal(), m_type);
|
||||||
|
|
||||||
|
|
@ -91,31 +95,29 @@ final class ContentTypeItemPane extends BaseItemPane {
|
||||||
// templateForm.add(templateFormSection);
|
// templateForm.add(templateFormSection);
|
||||||
// add(templateForm);
|
// add(templateForm);
|
||||||
|
|
||||||
|
// final AddTextElement textForm = new AddTextElement(m_model);
|
||||||
final AddTextElement textForm = new AddTextElement(m_model);
|
// add(textForm);
|
||||||
add(textForm);
|
//
|
||||||
|
// final AddNumberElement numberForm = new AddNumberElement(m_model);
|
||||||
final AddNumberElement numberForm = new AddNumberElement(m_model);
|
// add(numberForm);
|
||||||
add(numberForm);
|
//
|
||||||
|
// final AddDateElement dateForm = new AddDateElement(m_model);
|
||||||
final AddDateElement dateForm = new AddDateElement(m_model);
|
// add(dateForm);
|
||||||
add(dateForm);
|
//
|
||||||
|
// final AddTextAssetElement assetForm = new AddTextAssetElement(m_model);
|
||||||
final AddTextAssetElement assetForm = new AddTextAssetElement(m_model);
|
// add(assetForm);
|
||||||
add(assetForm);
|
//
|
||||||
|
// final AddImageElement imageForm = new AddImageElement(m_model);
|
||||||
final AddImageElement imageForm = new AddImageElement(m_model);
|
// add(imageForm);
|
||||||
add(imageForm);
|
//
|
||||||
|
// final AddFileElement fileForm = new AddFileElement(m_model);
|
||||||
final AddFileElement fileForm = new AddFileElement(m_model);
|
// add(fileForm);
|
||||||
add(fileForm);
|
//
|
||||||
|
// final AddContentItemElement itemForm
|
||||||
final AddContentItemElement itemForm =
|
// = new AddContentItemElement(m_model);
|
||||||
new AddContentItemElement(m_model);
|
// add(itemForm);
|
||||||
add(itemForm);
|
|
||||||
|
|
||||||
m_detailPane.add(new SummarySection(editLink, deleteLink));
|
m_detailPane.add(new SummarySection(editLink, deleteLink));
|
||||||
m_detailPane.add(new RelationAttributeSection());
|
// m_detailPane.add(new RelationAttributeSection());
|
||||||
|
|
||||||
m_detailPane.add(new TypeSecurityContainer(new ElementSection()));
|
m_detailPane.add(new TypeSecurityContainer(new ElementSection()));
|
||||||
m_detailPane.add(new TemplateSection(templateAddLink));
|
m_detailPane.add(new TemplateSection(templateAddLink));
|
||||||
|
|
@ -123,39 +125,38 @@ final class ContentTypeItemPane extends BaseItemPane {
|
||||||
//m_detailPane.add(new PermissionsSection(permissionAddLink));
|
//m_detailPane.add(new PermissionsSection(permissionAddLink));
|
||||||
m_detailPane.add(new PermissionsSection());
|
m_detailPane.add(new PermissionsSection());
|
||||||
|
|
||||||
connect(templateAddLink, templateForm);
|
// connect(templateAddLink, templateForm);
|
||||||
// connect(permissionAddLink, permissionsForm);
|
// connect(permissionAddLink, permissionsForm);
|
||||||
|
// final SingleSelect elementSelect
|
||||||
final SingleSelect elementSelect =
|
// = m_elementAddForm.getElementTypeSelect();
|
||||||
m_elementAddForm.getElementTypeSelect();
|
//
|
||||||
|
// connect(m_elementAddForm, elementSelect,
|
||||||
connect(m_elementAddForm, elementSelect,
|
// AddElement.TEXT_ELEMENT, textForm);
|
||||||
AddElement.TEXT_ELEMENT, textForm);
|
// connect(textForm);
|
||||||
connect(textForm);
|
//
|
||||||
|
// connect(m_elementAddForm, elementSelect,
|
||||||
connect(m_elementAddForm, elementSelect,
|
// AddElement.NUMBER_ELEMENT, numberForm);
|
||||||
AddElement.NUMBER_ELEMENT, numberForm);
|
// connect(numberForm);
|
||||||
connect(numberForm);
|
//
|
||||||
|
// connect(m_elementAddForm, elementSelect,
|
||||||
connect(m_elementAddForm, elementSelect,
|
// AddElement.DATE_ELEMENT, dateForm);
|
||||||
AddElement.DATE_ELEMENT, dateForm);
|
// connect(dateForm);
|
||||||
connect(dateForm);
|
//
|
||||||
|
// connect(m_elementAddForm, elementSelect,
|
||||||
connect(m_elementAddForm, elementSelect,
|
// AddElement.TEXT_ASSET_ELEMENT, assetForm);
|
||||||
AddElement.TEXT_ASSET_ELEMENT, assetForm);
|
// connect(assetForm);
|
||||||
connect(assetForm);
|
//
|
||||||
|
// connect(m_elementAddForm, elementSelect,
|
||||||
connect(m_elementAddForm, elementSelect,
|
// AddElement.IMAGE_ELEMENT, imageForm);
|
||||||
AddElement.IMAGE_ELEMENT, imageForm);
|
// connect(imageForm);
|
||||||
connect(imageForm);
|
//
|
||||||
|
// connect(m_elementAddForm, elementSelect,
|
||||||
connect(m_elementAddForm, elementSelect,
|
// AddElement.FILE_ELEMENT, fileForm);
|
||||||
AddElement.FILE_ELEMENT, fileForm);
|
// connect(fileForm);
|
||||||
connect(fileForm);
|
//
|
||||||
|
// connect(m_elementAddForm, elementSelect,
|
||||||
connect(m_elementAddForm, elementSelect,
|
// AddElement.CONTENT_ITEM_ELEMENT, itemForm);
|
||||||
AddElement.CONTENT_ITEM_ELEMENT, itemForm);
|
// connect(itemForm);
|
||||||
connect(itemForm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX A temporary, low-impact fix.
|
// XXX A temporary, low-impact fix.
|
||||||
|
|
@ -198,14 +199,15 @@ final class ContentTypeItemPane extends BaseItemPane {
|
||||||
final ActionGroup group = new ActionGroup();
|
final ActionGroup group = new ActionGroup();
|
||||||
setBody(group);
|
setBody(group);
|
||||||
|
|
||||||
group.setSubject(m_elements);
|
// group.setSubject(m_elements);
|
||||||
group.addAction(m_elementAddForm);
|
// group.addAction(m_elementAddForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean isVisible(final PageState state) {
|
public final boolean isVisible(final PageState state) {
|
||||||
return m_model.isSelected(state) && isDynamicType(state)
|
// return m_model.isSelected(state) && isDynamicType(state)
|
||||||
&& !ContentSection.getConfig().getHideUDCTUI();
|
// && !ContentSection.getConfig().getHideUDCTUI();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,7 +219,7 @@ final class ContentTypeItemPane extends BaseItemPane {
|
||||||
final ActionGroup group = new ActionGroup();
|
final ActionGroup group = new ActionGroup();
|
||||||
setBody(group);
|
setBody(group);
|
||||||
|
|
||||||
group.setSubject(m_templates);
|
// ToDo group.setSubject(m_templates);
|
||||||
group.addAction(new TypeSecurityContainer(templateAddLink));
|
group.addAction(new TypeSecurityContainer(templateAddLink));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,55 +247,55 @@ final class ContentTypeItemPane extends BaseItemPane {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RelationAttributeSection extends Section {
|
// private class RelationAttributeSection extends Section {
|
||||||
|
//
|
||||||
RelationAttributeSection() {
|
// RelationAttributeSection() {
|
||||||
setHeading(new Label(gz("cms.ui.type.attributes")));
|
// setHeading(new Label(gz("cms.ui.type.attributes")));
|
||||||
|
//
|
||||||
setBody(new RelationAttributeList(m_type));
|
// setBody(new RelationAttributeList(m_type));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public final boolean isVisible(final PageState state) {
|
// public final boolean isVisible(final PageState state) {
|
||||||
// ISt es möglich, den folgenden Code nur einmal zu haben?? Kann man auf die isVisible von RelationAttributeList
|
//// ISt es möglich, den folgenden Code nur einmal zu haben?? Kann man auf die isVisible von RelationAttributeList
|
||||||
// zurückgreifen??
|
// // zurückgreifen??
|
||||||
boolean retVal = false;
|
// boolean retVal = false;
|
||||||
ContentType ct = (ContentType) m_type.getContentType(state);
|
// ContentType ct = (ContentType) m_type.getContentType(state);
|
||||||
ContentItem ci = null;
|
// ContentItem ci = null;
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
Class<? extends ContentItem> clazz = Class.forName(ct.
|
// Class<? extends ContentItem> clazz = Class.forName(ct.
|
||||||
getClassName()).asSubclass(ContentItem.class);
|
// getClassName()).asSubclass(ContentItem.class);
|
||||||
ci = clazz.newInstance();
|
// ci = clazz.newInstance();
|
||||||
if (ci instanceof RelationAttributeInterface) {
|
// if (ci instanceof RelationAttributeInterface) {
|
||||||
RelationAttributeInterface rai =
|
// RelationAttributeInterface rai
|
||||||
(RelationAttributeInterface) ci;
|
// = (RelationAttributeInterface) ci;
|
||||||
retVal = rai.hasRelationAttributes();
|
// retVal = rai.hasRelationAttributes();
|
||||||
}
|
// }
|
||||||
ci.delete();
|
// ci.delete();
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
//retVal = false;
|
// //retVal = false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return retVal;
|
// return retVal;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void register(final Page page) {
|
public final void register(final Page page) {
|
||||||
super.register(page);
|
super.register(page);
|
||||||
|
|
||||||
page.addActionListener(new ActionListener() {
|
page.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
public final void actionPerformed(final ActionEvent e) {
|
@Override
|
||||||
final PageState state = e.getPageState();
|
public final void actionPerformed(final ActionEvent event) {
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
if (state.isVisibleOnPage(ContentTypeItemPane.this)
|
if (state.isVisibleOnPage(ContentTypeItemPane.this)
|
||||||
&& m_model.isSelected(state)
|
&& m_model.isSelected(state)
|
||||||
&& !userCanEdit(state)) {
|
&& !userCanEdit(state)) {
|
||||||
m_templates.getRemoveColumn().setVisible(state, false);
|
// m_templates.getRemoveColumn().setVisible(state, false);
|
||||||
m_templates.getDefaultColumn().setVisible(state, false);
|
// m_templates.getDefaultColumn().setVisible(state, false);
|
||||||
m_elements.getTable().getColumn(3).setVisible(state, false);
|
// m_elements.getTable().getColumn(3).setVisible(state, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -301,46 +303,47 @@ final class ContentTypeItemPane extends BaseItemPane {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister a content type from a content section.
|
* Unregister a content type from a content section.
|
||||||
* XXX domlay
|
|
||||||
*/
|
*/
|
||||||
private void removeType(final PageState state) {
|
private void removeType(final PageState state) {
|
||||||
final ContentSection section = CMS.getContext().getContentSection();
|
final ContentSection section = CMS.getContext().getContentSection();
|
||||||
|
|
||||||
section.removeContentType(m_type.getContentType(state));
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final ContentTypeManager typeManager = cdiUtil.findBean(
|
||||||
|
ContentTypeManager.class);
|
||||||
|
final ContentSectionManager sectionManager = cdiUtil.findBean(
|
||||||
|
ContentSectionManager.class);
|
||||||
|
|
||||||
section.save();
|
final ContentType type = m_type.getContentType(state);
|
||||||
|
final Class<? extends ContentItem> typeClass;
|
||||||
|
try {
|
||||||
|
typeClass = (Class<? extends ContentItem>) Class.forName(
|
||||||
|
type.getContentItemClass());
|
||||||
|
} catch (ClassNotFoundException ex) {
|
||||||
|
throw new UncheckedWrapperException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
sectionManager.removeContentTypeFromSection(typeClass, section);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the current user has access to edit the content type
|
* Determine if the current user has access to edit the content type
|
||||||
* XXX domlay
|
|
||||||
*/
|
*/
|
||||||
protected static boolean userCanEdit(final PageState state) {
|
protected static boolean userCanEdit(final PageState state) {
|
||||||
SecurityManager sm = Utilities.getSecurityManager(state);
|
final PermissionChecker permissionChecker = CdiUtil.createCdiUtil().findBean(PermissionChecker.class);
|
||||||
return sm.canAccess(state.getRequest(),
|
final ContentSection section = CMS.getContext().getContentSection();
|
||||||
SecurityManager.CONTENT_TYPE_ADMIN);
|
|
||||||
|
return permissionChecker.isPermitted(
|
||||||
|
AdminPrivileges.ADMINISTER_CONTENT_TYPES, section);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* utility method
|
* utility method get the DataObject from the DataBase, returns true if it
|
||||||
* get the DataObject from the DataBase, returns true if it
|
|
||||||
* is a modifiable type, false otherwise.
|
* is a modifiable type, false otherwise.
|
||||||
*
|
*
|
||||||
* XXX domlay
|
* Because we don't have modifiable types aka User Definied Content Types in
|
||||||
|
* CCM NG yet, this method returns always false for now.
|
||||||
*/
|
*/
|
||||||
protected final boolean isDynamicType(final PageState state) {
|
protected final boolean isDynamicType(final PageState state) {
|
||||||
final ContentType type = m_type.getContentType(state);
|
return false;
|
||||||
|
|
||||||
final String objectTypeString =
|
|
||||||
"com.arsdigita.persistence.DynamicObjectType";
|
|
||||||
final DataCollection collection = SessionManager.getSession().retrieve(
|
|
||||||
objectTypeString);
|
|
||||||
collection.addEqualsFilter("dynamicType", type.getAssociatedObjectType());
|
|
||||||
|
|
||||||
final boolean b = collection.next();
|
|
||||||
|
|
||||||
collection.close();
|
|
||||||
|
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,111 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2003-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.type;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.cms.CMS;
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.ContentType;
|
||||||
|
import org.librecms.lifecycle.LifecycleDefinition;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
import com.arsdigita.toolbox.ui.PropertyList;
|
||||||
|
import java.util.Locale;
|
||||||
|
import org.libreccm.workflow.WorkflowTemplate;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This component displays basic attributes of a content type
|
||||||
|
* including:
|
||||||
|
*
|
||||||
|
* label, description, default lifecycle definition, default workflow
|
||||||
|
* template
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
* @author Michael Pih
|
||||||
|
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
|
||||||
|
*/
|
||||||
|
class ContentTypePropertyList extends PropertyList {
|
||||||
|
|
||||||
|
private final ContentTypeRequestLocal m_type;
|
||||||
|
|
||||||
|
public ContentTypePropertyList(final ContentTypeRequestLocal type) {
|
||||||
|
m_type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final java.util.List properties(final PageState state) {
|
||||||
|
final java.util.List props = super.properties(state);
|
||||||
|
final ContentType type = m_type.getContentType(state);
|
||||||
|
final ContentSection section =
|
||||||
|
CMS.getContext().getContentSection();
|
||||||
|
|
||||||
|
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
||||||
|
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
||||||
|
|
||||||
|
props.add(new Property(gz("cms.ui.name"),
|
||||||
|
type.getLabel().getValue(defaultLocale)));
|
||||||
|
props.add(new Property(gz("cms.ui.description"),
|
||||||
|
type.getDescription().getValue(defaultLocale)));
|
||||||
|
// props.add(new Property(gz("cms.ui.type.parent"),
|
||||||
|
// type.getParent().orElse(null)));
|
||||||
|
props.add(new Property(gz("cms.ui.type.lifecycle"),
|
||||||
|
getLifecycle(section, type)));
|
||||||
|
props.add(new Property(gz("cms.ui.type.workflow"),
|
||||||
|
getWorkflow(section, type)));
|
||||||
|
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getLifecycle(final ContentSection section,
|
||||||
|
final ContentType type) {
|
||||||
|
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
||||||
|
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
||||||
|
|
||||||
|
final LifecycleDefinition cycle = type.getDefaultLifecycle();
|
||||||
|
|
||||||
|
if (cycle == null) {
|
||||||
|
return lz("cms.ui.type.lifecycle.none");
|
||||||
|
} else {
|
||||||
|
return cycle.getLabel().getValue(defaultLocale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getWorkflow(final ContentSection section,
|
||||||
|
final ContentType type) {
|
||||||
|
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
||||||
|
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
||||||
|
|
||||||
|
final WorkflowTemplate template = type.getDefaultWorkflow();
|
||||||
|
|
||||||
|
if (template == null) {
|
||||||
|
return lz("cms.ui.type.workflow.none");
|
||||||
|
} else {
|
||||||
|
return template.getName().getValue(defaultLocale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GlobalizedMessage gz(final String key) {
|
||||||
|
return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String lz(final String key) {
|
||||||
|
return (String) gz(key).localize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,288 @@
|
||||||
|
package com.arsdigita.cms.ui.type;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.Component;
|
||||||
|
import com.arsdigita.bebop.ControlLink;
|
||||||
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.Table;
|
||||||
|
import com.arsdigita.bebop.event.TableActionEvent;
|
||||||
|
import com.arsdigita.bebop.event.TableActionListener;
|
||||||
|
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||||
|
import com.arsdigita.bebop.table.TableColumn;
|
||||||
|
import com.arsdigita.bebop.table.TableColumnModel;
|
||||||
|
import com.arsdigita.bebop.table.TableModel;
|
||||||
|
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||||
|
import com.arsdigita.cms.CMS;
|
||||||
|
import org.librecms.contentsection.ContentType;
|
||||||
|
import com.arsdigita.cms.dispatcher.Utilities;
|
||||||
|
import com.arsdigita.cms.ui.ContentSectionRequestLocal;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.ui.admin.GlobalizationUtil;
|
||||||
|
import org.libreccm.security.Party;
|
||||||
|
import org.libreccm.security.Role;
|
||||||
|
import com.arsdigita.util.LockableImpl;
|
||||||
|
import java.awt.image.Kernel;
|
||||||
|
import java.util.List;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.security.Permission;
|
||||||
|
import org.libreccm.security.RoleRepository;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import sun.security.util.SecurityConstants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ToDo, maybe not needed anymore...
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter
|
||||||
|
*/
|
||||||
|
public class TypePermissionsTable extends Table implements TableActionListener {
|
||||||
|
|
||||||
|
private final String TABLE_COL_ROLE = "table_col_role";
|
||||||
|
private final String TABLE_COL_CAN_USE = "table_col_can_use";
|
||||||
|
private final String TABLE_COL_ACTION = "table_col_action";
|
||||||
|
private final ContentTypeRequestLocal type;
|
||||||
|
|
||||||
|
public TypePermissionsTable(final ContentSectionRequestLocal section,
|
||||||
|
final ContentTypeRequestLocal type) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.type = type;
|
||||||
|
|
||||||
|
setEmptyView(new Label(new GlobalizedMessage(
|
||||||
|
"cms.ui.type.permissions.none",
|
||||||
|
CmsConstants.CMS_BUNDLE)));
|
||||||
|
|
||||||
|
TableColumnModel columnModel = getColumnModel();
|
||||||
|
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
0,
|
||||||
|
new GlobalizedMessage("cms.ui.type.permissions.role",
|
||||||
|
CmsConstants.CMS_BUNDLE).localize(),
|
||||||
|
TABLE_COL_ROLE));
|
||||||
|
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
1,
|
||||||
|
new GlobalizedMessage("cms.ui.type.permissions_can_use",
|
||||||
|
CmsConstants.CMS_BUNDLE).localize(),
|
||||||
|
TABLE_COL_CAN_USE));
|
||||||
|
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
2,
|
||||||
|
new GlobalizedMessage("cms.ui.type.permission.action",
|
||||||
|
CmsConstants.CMS_BUNDLE).localize(),
|
||||||
|
TABLE_COL_ACTION));
|
||||||
|
|
||||||
|
setModelBuilder(new TypePermissionsTableModelBuilder());
|
||||||
|
|
||||||
|
columnModel.get(0).setCellRenderer(new RoleCellRenderer());
|
||||||
|
columnModel.get(1).setCellRenderer(new CanUseCellRenderer());
|
||||||
|
columnModel.get(2).setCellRenderer(new ActionCellRenderer());
|
||||||
|
|
||||||
|
addTableActionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cellSelected(final TableActionEvent event) {
|
||||||
|
PageState state = event.getPageState();
|
||||||
|
|
||||||
|
final TableColumn column = getColumnModel().get(event.getColumn());
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final RoleRepository roleRepo = cdiUtil.findBean(RoleRepository.class);
|
||||||
|
|
||||||
|
if (TABLE_COL_ACTION.equals(column.getHeaderKey().toString())) {
|
||||||
|
final Role role = roleRepo.findById(Long.parseLong(
|
||||||
|
event.getRowKey().toString()));
|
||||||
|
ContentType contentType = getType().getContentType(state);
|
||||||
|
// ToDo
|
||||||
|
// ObjectPermissionCollection permissions
|
||||||
|
// = PermissionService.
|
||||||
|
// getDirectGrantedPermissions(contentType.getOID());
|
||||||
|
//
|
||||||
|
// if ((permissions.size() == 0)) {
|
||||||
|
// role.grantPermission(contentType,
|
||||||
|
// PrivilegeDescriptor.get(
|
||||||
|
// com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM));
|
||||||
|
// } else if (!role.checkPermission(contentType, PrivilegeDescriptor.
|
||||||
|
// get(com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM))) {
|
||||||
|
// role.grantPermission(contentType,
|
||||||
|
// PrivilegeDescriptor.get(
|
||||||
|
// com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM));
|
||||||
|
// } else {
|
||||||
|
// role.revokePermission(contentType,
|
||||||
|
// PrivilegeDescriptor.get(
|
||||||
|
// com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM));
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void headSelected(final TableActionEvent event) {
|
||||||
|
//Nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TypePermissionsTableModelBuilder
|
||||||
|
extends LockableImpl
|
||||||
|
implements TableModelBuilder {
|
||||||
|
|
||||||
|
public TypePermissionsTableModelBuilder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableModel makeModel(final Table table, final PageState state) {
|
||||||
|
table.getRowSelectionModel().clearSelection(state);
|
||||||
|
return new TypePermissionsTableModel(table, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TypePermissionsTableModel implements TableModel {
|
||||||
|
|
||||||
|
private Table table;
|
||||||
|
private List<Role> roles;
|
||||||
|
private ContentType contentType;
|
||||||
|
private List<Permission> permissions;
|
||||||
|
|
||||||
|
public TypePermissionsTableModel(final Table table,
|
||||||
|
final PageState state) {
|
||||||
|
this.table = table;
|
||||||
|
contentType
|
||||||
|
= ((TypePermissionsTable) table).getType().getContentType(
|
||||||
|
state);
|
||||||
|
|
||||||
|
roles = CMS.getContext().getContentSection().getRoles();
|
||||||
|
|
||||||
|
// permissions
|
||||||
|
// = PermissionService.
|
||||||
|
// getDirectGrantedPermissions(contentType.getOID());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
if (roles == null) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return (int) roles.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean nextRow() {
|
||||||
|
return false;
|
||||||
|
// if (roles == null) {
|
||||||
|
// return false;
|
||||||
|
// } else {
|
||||||
|
// return roles.next();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getElementAt(int columnIndex) {
|
||||||
|
// switch (columnIndex) {
|
||||||
|
// case 0:
|
||||||
|
// return roles.getRole().getName();
|
||||||
|
// case 1:
|
||||||
|
// if (permissions.isEmpty()) {
|
||||||
|
// return "cms.ui.type.permissions.can_use.yes";
|
||||||
|
// } else {
|
||||||
|
// if (roles.getRole().checkPermission(contentType,
|
||||||
|
// PrivilegeDescriptor.
|
||||||
|
// get(
|
||||||
|
// com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM))) {
|
||||||
|
// return "cms.ui.type.permissions.can_use.yes";
|
||||||
|
// } else {
|
||||||
|
// return "cms.ui.type.permissions.can_use.no";
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// case 2:
|
||||||
|
// if (permissions.size() == 0) {
|
||||||
|
// return "cms.ui.type.permissions.actions.restrict_to_this_role";
|
||||||
|
// } else {
|
||||||
|
// if (roles.getRole().checkPermission(contentType,
|
||||||
|
// PrivilegeDescriptor.
|
||||||
|
// get(
|
||||||
|
// com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM))) {
|
||||||
|
// return "cms.ui.type.permissions.actions.revoke";
|
||||||
|
// } else {
|
||||||
|
// return "cms.ui.type.permissions.can_use.grant";
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// default:
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getKeyAt(int columnIndex) {
|
||||||
|
// return roles.getRole().getID();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class RoleCellRenderer
|
||||||
|
extends LockableImpl
|
||||||
|
implements TableCellRenderer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getComponent(Table table,
|
||||||
|
PageState state,
|
||||||
|
Object value,
|
||||||
|
boolean isSelected,
|
||||||
|
Object key,
|
||||||
|
int row,
|
||||||
|
int column) {
|
||||||
|
return new Label(value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class CanUseCellRenderer
|
||||||
|
extends LockableImpl
|
||||||
|
implements TableCellRenderer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getComponent(Table table,
|
||||||
|
PageState state,
|
||||||
|
Object value,
|
||||||
|
boolean isSelected,
|
||||||
|
Object key,
|
||||||
|
int row,
|
||||||
|
int column) {
|
||||||
|
return new Label(GlobalizationUtil.globalize(value.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ActionCellRenderer
|
||||||
|
extends LockableImpl
|
||||||
|
implements TableCellRenderer {
|
||||||
|
|
||||||
|
public Component getComponent(Table table,
|
||||||
|
PageState state,
|
||||||
|
Object value,
|
||||||
|
boolean isSelected,
|
||||||
|
Object key,
|
||||||
|
int row,
|
||||||
|
int column) {
|
||||||
|
// com.arsdigita.cms.SecurityManager securityManager = Utilities.
|
||||||
|
// getSecurityManager(state);
|
||||||
|
// Party party = Kernel.getContext().getParty();
|
||||||
|
// if (party == null) {
|
||||||
|
// party = Kernel.getPublicUser();
|
||||||
|
// }
|
||||||
|
// if (securityManager.canAccess(party,
|
||||||
|
// SecurityConstants.CONTENT_TYPE_ADMIN)) {
|
||||||
|
// ControlLink link = new ControlLink((String) GlobalizationUtil.
|
||||||
|
// globalize(
|
||||||
|
// value.toString()).localize());
|
||||||
|
//
|
||||||
|
// return link;
|
||||||
|
// } else {
|
||||||
|
return new Label(value.toString());
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ContentTypeRequestLocal getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,270 +0,0 @@
|
||||||
package com.arsdigita.cms.ui.type;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Column;
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.cms.CMS;
|
|
||||||
import com.arsdigita.cms.ContentType;
|
|
||||||
import com.arsdigita.cms.dispatcher.Utilities;
|
|
||||||
import com.arsdigita.cms.ui.ContentSectionRequestLocal;
|
|
||||||
import com.arsdigita.cms.util.GlobalizationUtil;
|
|
||||||
import com.arsdigita.cms.util.SecurityConstants;
|
|
||||||
import com.arsdigita.kernel.Kernel;
|
|
||||||
import com.arsdigita.kernel.Party;
|
|
||||||
import com.arsdigita.kernel.Role;
|
|
||||||
import com.arsdigita.kernel.RoleCollection;
|
|
||||||
import com.arsdigita.kernel.permissions.ObjectPermissionCollection;
|
|
||||||
import com.arsdigita.kernel.permissions.PermissionDescriptor;
|
|
||||||
import com.arsdigita.kernel.permissions.PermissionService;
|
|
||||||
import com.arsdigita.kernel.permissions.PrivilegeDescriptor;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class TypePermissionsTable extends Table implements TableActionListener {
|
|
||||||
|
|
||||||
private final String TABLE_COL_ROLE = "table_col_role";
|
|
||||||
private final String TABLE_COL_CAN_USE = "table_col_can_use";
|
|
||||||
private final String TABLE_COL_ACTION = "table_col_action";
|
|
||||||
private final ContentTypeRequestLocal type;
|
|
||||||
|
|
||||||
public TypePermissionsTable(final ContentSectionRequestLocal section,
|
|
||||||
final ContentTypeRequestLocal type) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.type = type;
|
|
||||||
|
|
||||||
setEmptyView(new Label(GlobalizationUtil.globalize(
|
|
||||||
"cms.ui.type.permissions.none")));
|
|
||||||
|
|
||||||
TableColumnModel columnModel = getColumnModel();
|
|
||||||
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
0,
|
|
||||||
GlobalizationUtil.globalize("cms.ui.type.permissions.role").
|
|
||||||
localize(),
|
|
||||||
TABLE_COL_ROLE));
|
|
||||||
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
1,
|
|
||||||
GlobalizationUtil.globalize("cms.ui.type.permissions_can_use").
|
|
||||||
localize(),
|
|
||||||
TABLE_COL_CAN_USE));
|
|
||||||
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
2,
|
|
||||||
GlobalizationUtil.globalize(
|
|
||||||
"cms.ui.type.permission.action").localize(),
|
|
||||||
TABLE_COL_ACTION));
|
|
||||||
|
|
||||||
setModelBuilder(new TypePermissionsTableModelBuilder());
|
|
||||||
|
|
||||||
columnModel.get(0).setCellRenderer(new RoleCellRenderer());
|
|
||||||
columnModel.get(1).setCellRenderer(new CanUseCellRenderer());
|
|
||||||
columnModel.get(2).setCellRenderer(new ActionCellRenderer());
|
|
||||||
|
|
||||||
addTableActionListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
PageState state = event.getPageState();
|
|
||||||
|
|
||||||
TableColumn column = getColumnModel().get(event.getColumn().intValue());
|
|
||||||
|
|
||||||
if (TABLE_COL_ACTION.equals(column.getHeaderKey().toString())) {
|
|
||||||
Role role = new Role(new BigDecimal(event.getRowKey().toString()));
|
|
||||||
ContentType contentType = getType().getContentType(state);
|
|
||||||
ObjectPermissionCollection permissions =
|
|
||||||
PermissionService.
|
|
||||||
getDirectGrantedPermissions(contentType.getOID());
|
|
||||||
|
|
||||||
if ((permissions.size() == 0)) {
|
|
||||||
role.grantPermission(contentType,
|
|
||||||
PrivilegeDescriptor.get(
|
|
||||||
com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM));
|
|
||||||
} else if (!role.checkPermission(contentType, PrivilegeDescriptor.
|
|
||||||
get(com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM))) {
|
|
||||||
role.grantPermission(contentType,
|
|
||||||
PrivilegeDescriptor.get(
|
|
||||||
com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM));
|
|
||||||
} else {
|
|
||||||
role.revokePermission(contentType,
|
|
||||||
PrivilegeDescriptor.get(
|
|
||||||
com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TypePermissionsTableModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
public TypePermissionsTableModelBuilder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public TableModel makeModel(Table table, PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
return new TypePermissionsTableModel(table, state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TypePermissionsTableModel implements TableModel {
|
|
||||||
|
|
||||||
private Table table;
|
|
||||||
private RoleCollection roles;
|
|
||||||
private ContentType contentType;
|
|
||||||
private ObjectPermissionCollection permissions;
|
|
||||||
|
|
||||||
public TypePermissionsTableModel(Table table, PageState state) {
|
|
||||||
this.table = table;
|
|
||||||
contentType =
|
|
||||||
((TypePermissionsTable) table).getType().getContentType(
|
|
||||||
state);
|
|
||||||
|
|
||||||
roles = CMS.getContext().getContentSection().getStaffGroup().
|
|
||||||
getRoles();
|
|
||||||
|
|
||||||
permissions =
|
|
||||||
PermissionService.getDirectGrantedPermissions(contentType.getOID());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getColumnCount() {
|
|
||||||
if (roles == null) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return (int) roles.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean nextRow() {
|
|
||||||
if (roles == null) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return roles.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getElementAt(int columnIndex) {
|
|
||||||
switch (columnIndex) {
|
|
||||||
case 0:
|
|
||||||
return roles.getRole().getName();
|
|
||||||
case 1:
|
|
||||||
if (permissions.size() == 0) {
|
|
||||||
return "cms.ui.type.permissions.can_use.yes";
|
|
||||||
} else {
|
|
||||||
if (roles.getRole().checkPermission(contentType,
|
|
||||||
PrivilegeDescriptor.
|
|
||||||
get(
|
|
||||||
com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM))) {
|
|
||||||
return "cms.ui.type.permissions.can_use.yes";
|
|
||||||
} else {
|
|
||||||
return "cms.ui.type.permissions.can_use.no";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case 2:
|
|
||||||
if (permissions.size() == 0) {
|
|
||||||
return "cms.ui.type.permissions.actions.restrict_to_this_role";
|
|
||||||
} else {
|
|
||||||
if (roles.getRole().checkPermission(contentType,
|
|
||||||
PrivilegeDescriptor.
|
|
||||||
get(
|
|
||||||
com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM))) {
|
|
||||||
return "cms.ui.type.permissions.actions.revoke";
|
|
||||||
} else {
|
|
||||||
return "cms.ui.type.permissions.can_use.grant";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getKeyAt(int columnIndex) {
|
|
||||||
return roles.getRole().getID();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RoleCellRenderer
|
|
||||||
extends LockableImpl
|
|
||||||
implements TableCellRenderer {
|
|
||||||
|
|
||||||
public Component getComponent(Table table,
|
|
||||||
PageState state,
|
|
||||||
Object value,
|
|
||||||
boolean isSelected,
|
|
||||||
Object key,
|
|
||||||
int row,
|
|
||||||
int column) {
|
|
||||||
return new Label(value.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CanUseCellRenderer
|
|
||||||
extends LockableImpl
|
|
||||||
implements TableCellRenderer {
|
|
||||||
|
|
||||||
public Component getComponent(Table table,
|
|
||||||
PageState state,
|
|
||||||
Object value,
|
|
||||||
boolean isSelected,
|
|
||||||
Object key,
|
|
||||||
int row,
|
|
||||||
int column) {
|
|
||||||
return new Label(GlobalizationUtil.globalize(value.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ActionCellRenderer
|
|
||||||
extends LockableImpl
|
|
||||||
implements TableCellRenderer {
|
|
||||||
|
|
||||||
public Component getComponent(Table table,
|
|
||||||
PageState state,
|
|
||||||
Object value,
|
|
||||||
boolean isSelected,
|
|
||||||
Object key,
|
|
||||||
int row,
|
|
||||||
int column) {
|
|
||||||
com.arsdigita.cms.SecurityManager securityManager = Utilities.
|
|
||||||
getSecurityManager(state);
|
|
||||||
Party party = Kernel.getContext().getParty();
|
|
||||||
if (party == null) {
|
|
||||||
party = Kernel.getPublicUser();
|
|
||||||
}
|
|
||||||
if (securityManager.canAccess(party,
|
|
||||||
SecurityConstants.CONTENT_TYPE_ADMIN)) {
|
|
||||||
ControlLink link = new ControlLink((String)GlobalizationUtil.globalize(
|
|
||||||
value.toString()).localize());
|
|
||||||
|
|
||||||
return link;
|
|
||||||
} else {
|
|
||||||
return new Label(value.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ContentTypeRequestLocal getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -31,8 +31,6 @@ import org.libreccm.core.CoreConstants;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue