CCM NG/ccm-cms: RoleAdminPane ported
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4523 8810af33-2d31-482b-a856-94f89814c4df
parent
78d0833d99
commit
26015af797
|
|
@ -39,7 +39,7 @@ import com.arsdigita.cms.dispatcher.CMSPage;
|
||||||
import com.arsdigita.cms.ui.cse.ContentSoonExpiredPane;
|
import com.arsdigita.cms.ui.cse.ContentSoonExpiredPane;
|
||||||
import com.arsdigita.cms.ui.folder.FolderAdminPane;
|
import com.arsdigita.cms.ui.folder.FolderAdminPane;
|
||||||
import com.arsdigita.cms.ui.lifecycle.LifecycleAdminPane;
|
import com.arsdigita.cms.ui.lifecycle.LifecycleAdminPane;
|
||||||
//import com.arsdigita.cms.ui.role.RoleAdminPane;
|
import com.arsdigita.cms.ui.role.RoleAdminPane;
|
||||||
import com.arsdigita.cms.ui.type.ContentTypeAdminPane;
|
import com.arsdigita.cms.ui.type.ContentTypeAdminPane;
|
||||||
import com.arsdigita.cms.ui.workflow.WorkflowAdminPane;
|
import com.arsdigita.cms.ui.workflow.WorkflowAdminPane;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
|
@ -121,7 +121,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
||||||
//ToDo NG private BrowsePane m_browsePane;
|
//ToDo NG private BrowsePane m_browsePane;
|
||||||
//ToDo NG private ItemSearch m_searchPane;
|
//ToDo NG private ItemSearch m_searchPane;
|
||||||
//ToDo NG private ImagesPane m_imagesPane;
|
//ToDo NG private ImagesPane m_imagesPane;
|
||||||
//ToDo NG private RoleAdminPane m_rolePane;
|
private RoleAdminPane m_rolePane;
|
||||||
private WorkflowAdminPane m_workflowPane;
|
private WorkflowAdminPane m_workflowPane;
|
||||||
private LifecycleAdminPane m_lifecyclePane;
|
private LifecycleAdminPane m_lifecyclePane;
|
||||||
//ToDo NG private CategoryAdminPane m_categoryPane;
|
//ToDo NG private CategoryAdminPane m_categoryPane;
|
||||||
|
|
@ -148,7 +148,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
||||||
//ToDo NG m_browsePane = getBrowsePane();
|
//ToDo NG m_browsePane = getBrowsePane();
|
||||||
//ToDo NG m_searchPane = getSearchPane();
|
//ToDo NG m_searchPane = getSearchPane();
|
||||||
//ToDo NG m_imagesPane = getImagesPane();
|
//ToDo NG m_imagesPane = getImagesPane();
|
||||||
//ToDo NG m_rolePane = getRoleAdminPane();
|
m_rolePane = getRoleAdminPane();
|
||||||
m_workflowPane = getWorkflowAdminPane();
|
m_workflowPane = getWorkflowAdminPane();
|
||||||
m_lifecyclePane = getLifecycleAdminPane();
|
m_lifecyclePane = getLifecycleAdminPane();
|
||||||
//ToDo NG m_categoryPane = getCategoryAdminPane();
|
//ToDo NG m_categoryPane = getCategoryAdminPane();
|
||||||
|
|
@ -202,12 +202,12 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
||||||
m_typePane,
|
m_typePane,
|
||||||
permissionChecker.isPermitted(
|
permissionChecker.isPermitted(
|
||||||
AdminPrivileges.ADMINISTER_CONTENT_TYPES));
|
AdminPrivileges.ADMINISTER_CONTENT_TYPES));
|
||||||
//ToDo NG
|
|
||||||
//m_tabbedPane.setTabVisible(
|
m_tabbedPane.setTabVisible(
|
||||||
// state,
|
state,
|
||||||
// m_rolePane,
|
m_rolePane,
|
||||||
// permissionChecker.isPermitted(
|
permissionChecker.isPermitted(
|
||||||
// AdminPrivileges.ADMINISTER_ROLES));
|
AdminPrivileges.ADMINISTER_ROLES));
|
||||||
// csePane: should check permission
|
// csePane: should check permission
|
||||||
m_tabbedPane.setTabVisible(state, m_csePane, true);
|
m_tabbedPane.setTabVisible(state, m_csePane, true);
|
||||||
// TODO Check for reportPane as well
|
// TODO Check for reportPane as well
|
||||||
|
|
@ -266,13 +266,13 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
||||||
// }
|
// }
|
||||||
// return m_imagesPane;
|
// return m_imagesPane;
|
||||||
// }
|
// }
|
||||||
// ToDo NG
|
protected RoleAdminPane getRoleAdminPane() {
|
||||||
// protected RoleAdminPane getRoleAdminPane() {
|
if (m_rolePane == null) {
|
||||||
// if (m_rolePane == null) {
|
m_rolePane = new RoleAdminPane();
|
||||||
// m_rolePane = new RoleAdminPane();
|
}
|
||||||
// }
|
return m_rolePane;
|
||||||
// return m_rolePane;
|
}
|
||||||
// }
|
|
||||||
/**
|
/**
|
||||||
* Creates, and then caches, the workflow administration pane. Overriding
|
* Creates, and then caches, the workflow administration pane. Overriding
|
||||||
* this method to return null will prevent this tab from appearing.
|
* this method to return null will prevent this tab from appearing.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,266 @@
|
||||||
|
/*
|
||||||
|
* 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.role;
|
||||||
|
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.ActionLink;
|
||||||
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.SimpleContainer;
|
||||||
|
import com.arsdigita.bebop.SingleSelectionModel;
|
||||||
|
import com.arsdigita.bebop.Table;
|
||||||
|
import com.arsdigita.bebop.event.TableActionAdapter;
|
||||||
|
import com.arsdigita.bebop.event.TableActionEvent;
|
||||||
|
import com.arsdigita.bebop.table.DefaultTableCellRenderer;
|
||||||
|
import com.arsdigita.bebop.table.TableColumn;
|
||||||
|
import com.arsdigita.bebop.table.TableColumnModel;
|
||||||
|
import com.arsdigita.cms.ui.BaseItemPane;
|
||||||
|
import com.arsdigita.cms.ui.PartySearchForm;
|
||||||
|
import com.arsdigita.cms.ui.VisibilityComponent;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
import com.arsdigita.toolbox.ui.ActionGroup;
|
||||||
|
import com.arsdigita.toolbox.ui.Property;
|
||||||
|
import com.arsdigita.toolbox.ui.PropertyList;
|
||||||
|
import com.arsdigita.toolbox.ui.Section;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.configuration.ConfigurationManager;
|
||||||
|
import org.libreccm.security.Party;
|
||||||
|
import org.libreccm.security.PartyRepository;
|
||||||
|
import org.libreccm.security.Permission;
|
||||||
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
import org.libreccm.security.Role;
|
||||||
|
import org.libreccm.security.RoleManager;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This pane is for showing the properties of a {@link Role}. That includes
|
||||||
|
* name, description, permissions and members. The last one is a list of
|
||||||
|
* {@link Party parties} to which the role corresponds to.
|
||||||
|
*
|
||||||
|
* NOTE: There was an AdminTable besides the MemberTable. Since this function
|
||||||
|
* was/is never used, it was deemed deprecated and was removed.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Justin Ross <jross@redhat.com>
|
||||||
|
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
class BaseRoleItemPane extends BaseItemPane {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
|
BaseRoleItemPane.class);
|
||||||
|
|
||||||
|
private final RoleRequestLocal roleRequestLocal;
|
||||||
|
|
||||||
|
private final MemberTable membersTable;
|
||||||
|
|
||||||
|
BaseRoleItemPane(final SingleSelectionModel<String> model,
|
||||||
|
final RoleRequestLocal role,
|
||||||
|
final ActionLink editLink,
|
||||||
|
final ActionLink deleteLink) {
|
||||||
|
roleRequestLocal = role;
|
||||||
|
|
||||||
|
membersTable = new MemberTable();
|
||||||
|
|
||||||
|
final ActionLink memberAddLink = new ActionLink(new Label(gz(
|
||||||
|
"cms.ui.role.member.add")));
|
||||||
|
|
||||||
|
final SimpleContainer m_detailPane = new SimpleContainer();
|
||||||
|
add(m_detailPane);
|
||||||
|
setDefault(m_detailPane);
|
||||||
|
|
||||||
|
m_detailPane.add(new SummarySection(editLink, deleteLink));
|
||||||
|
m_detailPane.add(new MemberSection(memberAddLink));
|
||||||
|
|
||||||
|
final PartySearchForm memberSearchForm = new PartySearchForm();
|
||||||
|
add(memberSearchForm);
|
||||||
|
|
||||||
|
final RolePartyAddForm memberAddForm = new RolePartyAddForm(
|
||||||
|
model, memberSearchForm.getSearchWidget());
|
||||||
|
add(memberAddForm);
|
||||||
|
|
||||||
|
connect(memberAddLink, memberSearchForm);
|
||||||
|
connect(memberSearchForm, memberAddForm);
|
||||||
|
memberAddForm.getForm().addSubmissionListener(new CancelListener(
|
||||||
|
memberAddForm.getForm()));
|
||||||
|
resume(memberAddForm.getForm(), m_detailPane);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SummarySection extends Section {
|
||||||
|
|
||||||
|
SummarySection(final ActionLink editLink,
|
||||||
|
final ActionLink deleteLink) {
|
||||||
|
setHeading(gz("cms.ui.role.details"));
|
||||||
|
|
||||||
|
final ActionGroup group = new ActionGroup();
|
||||||
|
setBody(group);
|
||||||
|
|
||||||
|
group.setSubject(new Properties());
|
||||||
|
group.addAction(
|
||||||
|
new VisibilityComponent(editLink,
|
||||||
|
AdminPrivileges.ADMINISTER_ROLES),
|
||||||
|
ActionGroup.DELETE);
|
||||||
|
group.addAction(
|
||||||
|
new VisibilityComponent(deleteLink,
|
||||||
|
AdminPrivileges.ADMINISTER_ROLES),
|
||||||
|
ActionGroup.DELETE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private class Properties extends PropertyList {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final java.util.List<Property> properties(
|
||||||
|
final PageState state) {
|
||||||
|
|
||||||
|
final java.util.List<Property> properties = super.properties(
|
||||||
|
state);
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final ConfigurationManager manager = cdiUtil.findBean(
|
||||||
|
ConfigurationManager.class);
|
||||||
|
final KernelConfig config = manager.findConfiguration(
|
||||||
|
KernelConfig.class);
|
||||||
|
|
||||||
|
final Role role = roleRequestLocal.getRole(state);
|
||||||
|
|
||||||
|
properties.add(new Property(lz("cms.ui.name"),
|
||||||
|
role.getName()));
|
||||||
|
// Right now just loads the default locale description.
|
||||||
|
properties.add(new Property(lz("cms.ui.description"),
|
||||||
|
role.getDescription().getValue(
|
||||||
|
config
|
||||||
|
.getDefaultLocale())));
|
||||||
|
|
||||||
|
// Since Permissions don't seem to have a "pretty" form, the granted privilege is used.
|
||||||
|
final String permissions = role.getPermissions().stream()
|
||||||
|
.map(Permission::getGrantedPrivilege)
|
||||||
|
.collect(Collectors.joining(", "));
|
||||||
|
|
||||||
|
if (permissions.length() > 0) {
|
||||||
|
properties.add(new Property(lz("cms.ui.role.privileges"),
|
||||||
|
permissions));
|
||||||
|
} else {
|
||||||
|
properties.add(new Property(lz("cms.ui.role.privileges"),
|
||||||
|
lz("cms.ui.role.privilege.none")));
|
||||||
|
}
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MemberSection extends Section {
|
||||||
|
|
||||||
|
MemberSection(final ActionLink memberAddLink) {
|
||||||
|
setHeading(gz("cms.ui.role.members"));
|
||||||
|
|
||||||
|
final ActionGroup group = new ActionGroup();
|
||||||
|
setBody(group);
|
||||||
|
|
||||||
|
group.setSubject(membersTable);
|
||||||
|
group.addAction(
|
||||||
|
new VisibilityComponent(memberAddLink,
|
||||||
|
AdminPrivileges.ADMINISTER_ROLES),
|
||||||
|
ActionGroup.ADD);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MemberTable extends Table {
|
||||||
|
|
||||||
|
private static final int COL_NAME = 0;
|
||||||
|
private static final int COL_EMAIL = 1;
|
||||||
|
private static final int COL_REMOVE = 2;
|
||||||
|
|
||||||
|
MemberTable() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
final TableColumnModel columnModel = getColumnModel();
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
COL_NAME,
|
||||||
|
new Label(new GlobalizedMessage("cms.ui.name",
|
||||||
|
CmsConstants.CMS_BUNDLE))));
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
COL_EMAIL,
|
||||||
|
new Label(new GlobalizedMessage("cms.ui.role.member.email",
|
||||||
|
CmsConstants.CMS_BUNDLE))));
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
COL_REMOVE,
|
||||||
|
new Label(new GlobalizedMessage("cms.ui.role.member.remove",
|
||||||
|
CmsConstants.CMS_BUNDLE))));
|
||||||
|
|
||||||
|
setEmptyView(new Label(gz("cms.ui.role.member.none")));
|
||||||
|
|
||||||
|
setModelBuilder(new MemberTableModelBuilder(roleRequestLocal));
|
||||||
|
|
||||||
|
getColumn(2).setCellRenderer(new DefaultTableCellRenderer(true));
|
||||||
|
|
||||||
|
addTableActionListener(new Listener());
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Listener extends TableActionAdapter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void cellSelected(final TableActionEvent e) throws
|
||||||
|
FormProcessException {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final PageState state = e.getPageState();
|
||||||
|
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||||
|
PermissionChecker.class);
|
||||||
|
|
||||||
|
if (!permissionChecker.isPermitted(
|
||||||
|
AdminPrivileges.ADMINISTER_ROLES)) {
|
||||||
|
throw new FormProcessException(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"cms.ui.role.insufficient_privileges",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.getColumn() == 2) {
|
||||||
|
final Role role = roleRequestLocal.getRole(state);
|
||||||
|
long itemId = Long.parseLong(e.getRowKey().toString());
|
||||||
|
|
||||||
|
final PartyRepository partyRepository = cdiUtil.findBean(
|
||||||
|
PartyRepository.class);
|
||||||
|
final RoleManager roleManager = cdiUtil.findBean(
|
||||||
|
RoleManager.class);
|
||||||
|
final Party party = partyRepository.findById(itemId);
|
||||||
|
|
||||||
|
roleManager.removeRoleFromParty(role, party);
|
||||||
|
|
||||||
|
getRowSelectionModel().clearSelection(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,205 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.role;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.*;
|
|
||||||
import com.arsdigita.bebop.event.TableActionAdapter;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.table.DefaultTableCellRenderer;
|
|
||||||
import com.arsdigita.cms.ui.BaseItemPane;
|
|
||||||
import com.arsdigita.cms.ui.PartySearchForm;
|
|
||||||
import com.arsdigita.cms.ui.VisibilityComponent;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
|
||||||
import com.arsdigita.toolbox.ui.PropertyList;
|
|
||||||
import com.arsdigita.toolbox.ui.Section;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.libreccm.security.*;
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This pane is for showing the properties of a {@link Role}. That includes name, description, permissions and
|
|
||||||
* members. The last one is a list of {@link Party parties} to which the role corresponds to.
|
|
||||||
*
|
|
||||||
* NOTE: There was an AdminTable besides the MemberTable. Since this function was/is never used, it was deemed
|
|
||||||
* deprecated and was removed.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
|
||||||
* @author Justin Ross <jross@redhat.com>
|
|
||||||
* @version $Id: BaseRoleItemPane.java 287 2005-02-22 00:29:02Z sskracic $
|
|
||||||
*/
|
|
||||||
class BaseRoleItemPane extends BaseItemPane {
|
|
||||||
|
|
||||||
private static final Logger s_log = Logger.getLogger
|
|
||||||
(BaseRoleItemPane.class);
|
|
||||||
|
|
||||||
private final RoleRequestLocal m_role;
|
|
||||||
|
|
||||||
private final MemberTable m_members;
|
|
||||||
|
|
||||||
BaseRoleItemPane(final SingleSelectionModel model,
|
|
||||||
final RoleRequestLocal role,
|
|
||||||
final ActionLink editLink,
|
|
||||||
final ActionLink deleteLink) {
|
|
||||||
m_role = role;
|
|
||||||
|
|
||||||
m_members = new MemberTable();
|
|
||||||
|
|
||||||
final ActionLink memberAddLink = new ActionLink
|
|
||||||
(new Label(gz("cms.ui.role.member.add")));
|
|
||||||
|
|
||||||
SimpleContainer m_detailPane = new SimpleContainer();
|
|
||||||
add(m_detailPane);
|
|
||||||
setDefault(m_detailPane);
|
|
||||||
|
|
||||||
m_detailPane.add(new SummarySection(editLink, deleteLink));
|
|
||||||
m_detailPane.add(new MemberSection(memberAddLink));
|
|
||||||
|
|
||||||
final PartySearchForm memberSearchForm = new PartySearchForm();
|
|
||||||
add(memberSearchForm);
|
|
||||||
|
|
||||||
final RolePartyAddForm memberAddForm = new RolePartyAddForm
|
|
||||||
(model, memberSearchForm.getSearchWidget());
|
|
||||||
add(memberAddForm);
|
|
||||||
|
|
||||||
connect(memberAddLink, memberSearchForm);
|
|
||||||
connect(memberSearchForm, memberAddForm);
|
|
||||||
memberAddForm.getForm().addSubmissionListener
|
|
||||||
(new CancelListener(memberAddForm.getForm()));
|
|
||||||
resume(memberAddForm.getForm(), m_detailPane);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AdminVisible extends VisibilityComponent {
|
|
||||||
AdminVisible(final Component child) {
|
|
||||||
super(child, AdminPrivileges.ADMINISTER_ROLES);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SummarySection extends Section {
|
|
||||||
SummarySection(final ActionLink editLink,
|
|
||||||
final ActionLink deleteLink) {
|
|
||||||
setHeading(gz("cms.ui.role.details"));
|
|
||||||
|
|
||||||
final ActionGroup group = new ActionGroup();
|
|
||||||
setBody(group);
|
|
||||||
|
|
||||||
group.setSubject(new Properties());
|
|
||||||
group.addAction(new AdminVisible(editLink), ActionGroup.EDIT);
|
|
||||||
group.addAction(new AdminVisible(deleteLink), ActionGroup.DELETE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private class Properties extends PropertyList {
|
|
||||||
protected final java.util.List properties(final PageState state) {
|
|
||||||
final java.util.List props = super.properties(state);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ConfigurationManager manager = cdiUtil.findBean(ConfigurationManager.class);
|
|
||||||
final KernelConfig config = manager.findConfiguration(KernelConfig.class);
|
|
||||||
|
|
||||||
final Role role = m_role.getRole(state);
|
|
||||||
|
|
||||||
props.add(new Property(lz("cms.ui.name"),
|
|
||||||
role.getName()));
|
|
||||||
// Right now just loads the default locale description.
|
|
||||||
props.add(new Property(lz("cms.ui.description"),
|
|
||||||
role.getDescription().getValue(config.getDefaultLocale())));
|
|
||||||
|
|
||||||
// Since Permissions don't seem to have a "pretty" form, the granted privilege is used.
|
|
||||||
final String permissions = role.getPermissions().stream()
|
|
||||||
.map(Permission::getGrantedPrivilege)
|
|
||||||
.collect(Collectors.joining(", "));
|
|
||||||
|
|
||||||
if (permissions.length() > 0) {
|
|
||||||
props.add(new Property(lz("cms.ui.role.privileges"), permissions));
|
|
||||||
} else {
|
|
||||||
props.add(new Property(lz("cms.ui.role.privileges"),
|
|
||||||
lz("cms.ui.role.privilege.none")));
|
|
||||||
}
|
|
||||||
|
|
||||||
return props;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MemberSection extends Section {
|
|
||||||
MemberSection(final ActionLink memberAddLink) {
|
|
||||||
setHeading(gz("cms.ui.role.members"));
|
|
||||||
|
|
||||||
final ActionGroup group = new ActionGroup();
|
|
||||||
setBody(group);
|
|
||||||
|
|
||||||
group.setSubject(m_members);
|
|
||||||
group.addAction(new AdminVisible(memberAddLink), ActionGroup.ADD);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String[] s_memberColumns = new String[] {
|
|
||||||
lz("cms.ui.name"),
|
|
||||||
lz("cms.ui.role.member.email"),
|
|
||||||
lz("cms.ui.role.member.remove")
|
|
||||||
};
|
|
||||||
|
|
||||||
private class MemberTable extends Table {
|
|
||||||
MemberTable() {
|
|
||||||
super(new MemberTableModelBuilder(m_role), s_memberColumns);
|
|
||||||
|
|
||||||
setEmptyView(new Label(gz("cms.ui.role.member.none")));
|
|
||||||
|
|
||||||
getColumn(2).setCellRenderer
|
|
||||||
(new DefaultTableCellRenderer(true));
|
|
||||||
|
|
||||||
addTableActionListener(new Listener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Listener extends TableActionAdapter {
|
|
||||||
@Override
|
|
||||||
public final void cellSelected(final TableActionEvent e) throws FormProcessException {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
|
|
||||||
|
|
||||||
if (!permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_ROLES)) {
|
|
||||||
throw new FormProcessException(
|
|
||||||
new GlobalizedMessage("cms.ui.role.insufficient_privileges", CmsConstants.CMS_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.getColumn() == 2) {
|
|
||||||
final Role role = m_role.getRole(state);
|
|
||||||
long itemId = Long.parseLong(e.getRowKey().toString());
|
|
||||||
|
|
||||||
final PartyRepository partyRepository = cdiUtil.findBean(PartyRepository.class);
|
|
||||||
final RoleManager roleManager = cdiUtil.findBean(RoleManager.class);
|
|
||||||
final Party party = partyRepository.findById(itemId);
|
|
||||||
|
|
||||||
roleManager.removeRoleFromParty(role, party);
|
|
||||||
|
|
||||||
getRowSelectionModel().clearSelection(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -23,7 +23,7 @@ import com.arsdigita.bebop.Table;
|
||||||
import com.arsdigita.bebop.table.AbstractTableModelBuilder;
|
import com.arsdigita.bebop.table.AbstractTableModelBuilder;
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
import com.arsdigita.bebop.table.TableModel;
|
||||||
import com.arsdigita.ui.admin.GlobalizationUtil;
|
import com.arsdigita.ui.admin.GlobalizationUtil;
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.security.Party;
|
import org.libreccm.security.Party;
|
||||||
import org.libreccm.security.PartyRepository;
|
import org.libreccm.security.PartyRepository;
|
||||||
|
|
@ -33,6 +33,7 @@ import org.libreccm.security.RoleManager;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,36 +42,34 @@ import java.util.stream.Collectors;
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||||
* @author Justin Ross <jross@redhat.com>
|
* @author Justin Ross <jross@redhat.com>
|
||||||
* @version $Id: MemberTableModelBuilder.java 287 2005-02-22 00:29:02Z sskracic $
|
* @version $Id: MemberTableModelBuilder.java 287 2005-02-22 00:29:02Z sskracic
|
||||||
|
* $
|
||||||
*/
|
*/
|
||||||
class MemberTableModelBuilder extends AbstractTableModelBuilder {
|
class MemberTableModelBuilder extends AbstractTableModelBuilder {
|
||||||
|
|
||||||
private static final Logger s_log = Logger.getLogger
|
private final RoleRequestLocal roleRequestLocal;
|
||||||
(MemberTableModelBuilder.class);
|
|
||||||
|
|
||||||
private final RoleRequestLocal m_role;
|
|
||||||
|
|
||||||
MemberTableModelBuilder(final RoleRequestLocal role) {
|
MemberTableModelBuilder(final RoleRequestLocal role) {
|
||||||
m_role = role;
|
roleRequestLocal = role;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final TableModel makeModel(final Table table,
|
public final TableModel makeModel(final Table table,
|
||||||
final PageState state) {
|
final PageState state) {
|
||||||
final Role role = m_role.getRole(state);
|
final Role role = roleRequestLocal.getRole(state);
|
||||||
|
|
||||||
//FIXME Dirty hack, needs to be filtered in the database.
|
final List<Party> members = role.getMemberships()
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
.stream()
|
||||||
final PartyRepository partyRepository = cdiUtil.findBean(PartyRepository.class);
|
.map(membership -> membership.getMember())
|
||||||
final RoleManager roleManager = cdiUtil.findBean(RoleManager.class);
|
.collect(Collectors.toList());
|
||||||
Collection<Party> parties = partyRepository.findAll().stream()
|
members.sort((member1, member2) -> member1.getName().compareTo(
|
||||||
.filter(x -> roleManager.hasRole(x, role))
|
member2.getName()));
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
|
||||||
|
|
||||||
return new Model(parties);
|
return new Model(members);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Model implements TableModel {
|
private static class Model implements TableModel {
|
||||||
|
|
||||||
private Party m_party;
|
private Party m_party;
|
||||||
private final Collection<Party> m_parties;
|
private final Collection<Party> m_parties;
|
||||||
private final Iterator<Party> iterator;
|
private final Iterator<Party> iterator;
|
||||||
|
|
@ -113,9 +112,11 @@ class MemberTableModelBuilder extends AbstractTableModelBuilder {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String lz(final String key) {
|
protected static String lz(final String key) {
|
||||||
return (String) GlobalizationUtil.globalize(key).localize();
|
return (String) GlobalizationUtil.globalize(key).localize();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,11 @@ import com.arsdigita.toolbox.ui.ActionGroup;
|
||||||
import com.arsdigita.toolbox.ui.Section;
|
import com.arsdigita.toolbox.ui.Section;
|
||||||
import com.arsdigita.util.LockableImpl;
|
import com.arsdigita.util.LockableImpl;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.security.Role;
|
import org.libreccm.security.Role;
|
||||||
import org.libreccm.security.RoleRepository;
|
import org.libreccm.security.RoleRepository;
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
import org.librecms.contentsection.ContentSection;
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||||
|
|
||||||
|
|
@ -56,29 +56,32 @@ import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||||
* Since this is no longer the case, there exists only the
|
* Since this is no longer the case, there exists only the
|
||||||
* {@link RoleListModelBuilder} now.
|
* {@link RoleListModelBuilder} now.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
*
|
||||||
* @author Justin Ross <jross@redhat.com>
|
* @author Justin Ross <jross@redhat.com>
|
||||||
* @version $Id: RoleAdminPane.java 287 2005-02-22 00:29:02Z sskracic $
|
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||||
|
* @authr <a href="mailto:jens.pelzetter@googemail.com">Jens Pelzetter</a>
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class RoleAdminPane extends BaseAdminPane {
|
public class RoleAdminPane extends BaseAdminPane<String> {
|
||||||
|
|
||||||
private static final Logger s_log = Logger.getLogger(RoleAdminPane.class);
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
|
RoleAdminPane.class);
|
||||||
|
|
||||||
private final SingleSelectionModel m_model;
|
private final SingleSelectionModel<String> selectionModel;
|
||||||
|
|
||||||
private final List m_roles;
|
private final List rolesList;
|
||||||
|
|
||||||
public RoleAdminPane() {
|
public RoleAdminPane() {
|
||||||
m_model = new ParameterSingleSelectionModel(new StringParameter(
|
selectionModel = new ParameterSingleSelectionModel<>(
|
||||||
List.SELECTED));
|
new StringParameter(List.SELECTED));
|
||||||
setSelectionModel(m_model);
|
setSelectionModel(selectionModel);
|
||||||
|
|
||||||
m_model.addChangeListener(new SelectionListener());
|
selectionModel.addChangeListener(new SelectionListener());
|
||||||
|
|
||||||
RoleRequestLocal m_role = new SelectionRequestLocal();
|
RoleRequestLocal m_role = new SelectionRequestLocal();
|
||||||
|
|
||||||
m_roles = new List(new RoleListModelBuilder());
|
rolesList = new List(new RoleListModelBuilder());
|
||||||
m_roles.setSelectionModel(m_model);
|
rolesList.setSelectionModel(selectionModel);
|
||||||
|
|
||||||
final SimpleContainer left = new SimpleContainer();
|
final SimpleContainer left = new SimpleContainer();
|
||||||
setLeft(left);
|
setLeft(left);
|
||||||
|
|
@ -90,7 +93,7 @@ public class RoleAdminPane extends BaseAdminPane {
|
||||||
setDelete(gz("cms.ui.role.delete"), new DeleteForm());
|
setDelete(gz("cms.ui.role.delete"), new DeleteForm());
|
||||||
|
|
||||||
setIntroPane(new Label(gz("cms.ui.role.intro")));
|
setIntroPane(new Label(gz("cms.ui.role.intro")));
|
||||||
setItemPane(new BaseRoleItemPane(m_model, m_role,
|
setItemPane(new BaseRoleItemPane(selectionModel, m_role,
|
||||||
getEditLink(), getDeleteLink()));
|
getEditLink(), getDeleteLink()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,17 +105,17 @@ public class RoleAdminPane extends BaseAdminPane {
|
||||||
final ActionGroup group = new ActionGroup();
|
final ActionGroup group = new ActionGroup();
|
||||||
setBody(group);
|
setBody(group);
|
||||||
|
|
||||||
group.setSubject(m_roles);
|
group.setSubject(rolesList);
|
||||||
|
|
||||||
final ActionLink link = new ActionLink(new Label(gz(
|
final ActionLink link = new ActionLink(new Label(gz(
|
||||||
"cms.ui.role.staff.add")));
|
"cms.ui.role.staff.add")));
|
||||||
|
|
||||||
group.addAction(new VisibilityComponent(
|
group.addAction(
|
||||||
link,
|
new VisibilityComponent(link,
|
||||||
AdminPrivileges.ADMINISTER_ROLES),
|
AdminPrivileges.ADMINISTER_ROLES),
|
||||||
ActionGroup.ADD);
|
ActionGroup.ADD);
|
||||||
|
|
||||||
final RoleAddForm form = new RoleAddForm(m_model);
|
final RoleAddForm form = new RoleAddForm(selectionModel);
|
||||||
getBody().add(form);
|
getBody().add(form);
|
||||||
getBody().connect(link, form);
|
getBody().connect(link, form);
|
||||||
}
|
}
|
||||||
|
|
@ -122,16 +125,16 @@ public class RoleAdminPane extends BaseAdminPane {
|
||||||
private class SelectionListener implements ChangeListener {
|
private class SelectionListener implements ChangeListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void stateChanged(final ChangeEvent e) {
|
public final void stateChanged(final ChangeEvent event) {
|
||||||
s_log.debug("Selection state changed; I may change "
|
LOGGER.debug("Selection state changed; I may change "
|
||||||
+ "the body's visible pane");
|
+ "the body's visible pane");
|
||||||
|
|
||||||
final PageState state = e.getPageState();
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
getBody().reset(state);
|
getBody().reset(state);
|
||||||
|
|
||||||
if (m_model.isSelected(state)) {
|
if (selectionModel.isSelected(state)) {
|
||||||
s_log.debug("The selection model is selected; displaying "
|
LOGGER.debug("The selection model is selected; displaying "
|
||||||
+ "the item pane");
|
+ "the item pane");
|
||||||
|
|
||||||
getBody().push(state, getItemPane());
|
getBody().push(state, getItemPane());
|
||||||
|
|
@ -144,8 +147,7 @@ public class RoleAdminPane extends BaseAdminPane {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final Object initialValue(final PageState state) {
|
protected final Object initialValue(final PageState state) {
|
||||||
final Long id = Long.parseLong(m_model.getSelectedKey(state)
|
final Long id = Long.parseLong(selectionModel.getSelectedKey(state));
|
||||||
.toString());
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final RoleRepository roleRepository = cdiUtil.findBean(
|
final RoleRepository roleRepository = cdiUtil.findBean(
|
||||||
RoleRepository.class);
|
RoleRepository.class);
|
||||||
|
|
@ -187,20 +189,19 @@ public class RoleAdminPane extends BaseAdminPane {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void process(final FormSectionEvent e)
|
public final void process(final FormSectionEvent event)
|
||||||
throws FormProcessException {
|
throws FormProcessException {
|
||||||
final PageState state = e.getPageState();
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final RoleRepository roleRepository = cdiUtil.findBean(
|
final RoleRepository roleRepository = cdiUtil.findBean(
|
||||||
RoleRepository.class);
|
RoleRepository.class);
|
||||||
final Long id = Long.parseLong(m_model.getSelectedKey(state)
|
final Long id = Long.parseLong(selectionModel.getSelectedKey(state));
|
||||||
.toString());
|
|
||||||
final Role role = roleRepository.findById(id);
|
final Role role = roleRepository.findById(id);
|
||||||
|
|
||||||
roleRepository.delete(role);
|
roleRepository.delete(role);
|
||||||
|
|
||||||
m_model.clearSelection(state);
|
selectionModel.clearSelection(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -21,11 +21,8 @@ package com.arsdigita.toolbox.ui;
|
||||||
import com.arsdigita.bebop.SimpleComponent;
|
import com.arsdigita.bebop.SimpleComponent;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.RequestLocal;
|
import com.arsdigita.bebop.RequestLocal;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.Assert;
|
|
||||||
import com.arsdigita.xml.Element;
|
import com.arsdigita.xml.Element;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue