CCM NG/ccm-cms: Several bug fixes for RoleAdminPane
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4623 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
09af5101ec
commit
160a947813
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.cms.ui.role;
|
package com.arsdigita.cms.ui.role;
|
||||||
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
import com.arsdigita.bebop.ActionLink;
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
import com.arsdigita.bebop.Label;
|
import com.arsdigita.bebop.Label;
|
||||||
|
|
@ -151,15 +150,15 @@ class BaseRoleItemPane extends BaseItemPane {
|
||||||
properties.add(new Property(lz("cms.ui.name"),
|
properties.add(new Property(lz("cms.ui.name"),
|
||||||
role.getName()));
|
role.getName()));
|
||||||
// Right now just loads the default locale description.
|
// Right now just loads the default locale description.
|
||||||
properties.add(new Property(lz("cms.ui.description"),
|
properties.add(new Property(
|
||||||
role.getDescription().getValue(
|
lz("cms.ui.description"),
|
||||||
config
|
role.getDescription().getValue(config.getDefaultLocale())));
|
||||||
.getDefaultLocale())));
|
|
||||||
|
|
||||||
// Since Permissions don't seem to have a "pretty" form, the granted privilege is used.
|
// Since Permissions don't seem to have a "pretty" form, the granted privilege is used.
|
||||||
final String permissions = role.getPermissions().stream()
|
final RoleAdminPaneController controller = cdiUtil.findBean(
|
||||||
.map(Permission::getGrantedPrivilege)
|
RoleAdminPaneController.class);
|
||||||
.collect(Collectors.joining(", "));
|
final String permissions = controller
|
||||||
|
.generateGrantedPermissionsString(role);
|
||||||
|
|
||||||
if (permissions.length() > 0) {
|
if (permissions.length() > 0) {
|
||||||
properties.add(new Property(lz("cms.ui.role.privileges"),
|
properties.add(new Property(lz("cms.ui.role.privileges"),
|
||||||
|
|
|
||||||
|
|
@ -58,12 +58,10 @@ class MemberTableModelBuilder extends AbstractTableModelBuilder {
|
||||||
final PageState state) {
|
final PageState state) {
|
||||||
final Role role = roleRequestLocal.getRole(state);
|
final Role role = roleRequestLocal.getRole(state);
|
||||||
|
|
||||||
final List<Party> members = role.getMemberships()
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
.stream()
|
final RoleAdminPaneController controller = cdiUtil.findBean(
|
||||||
.map(membership -> membership.getMember())
|
RoleAdminPaneController.class);
|
||||||
.collect(Collectors.toList());
|
final List<Party> members = controller.createRoleMemberList(role);
|
||||||
members.sort((member1, member2) -> member1.getName().compareTo(
|
|
||||||
member2.getName()));
|
|
||||||
|
|
||||||
return new Model(members);
|
return new Model(members);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||||
*
|
*
|
||||||
* @author Justin Ross <jross@redhat.com>
|
* @author Justin Ross <jross@redhat.com>
|
||||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||||
* @authr <a href="mailto:jens.pelzetter@googemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googemail.com">Jens Pelzetter</a>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RoleAdminPane extends BaseAdminPane<String> {
|
public class RoleAdminPane extends BaseAdminPane<String> {
|
||||||
|
|
@ -172,7 +172,13 @@ public class RoleAdminPane extends BaseAdminPane<String> {
|
||||||
public final ListModel makeModel(final List list, final PageState state) {
|
public final ListModel makeModel(final List list, final PageState state) {
|
||||||
final ContentSection section = CMS.getContext().getContentSection();
|
final ContentSection section = CMS.getContext().getContentSection();
|
||||||
|
|
||||||
return new RoleListModel(section.getRoles());
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final RoleAdminPaneController controller = cdiUtil
|
||||||
|
.findBean(RoleAdminPaneController.class);
|
||||||
|
final java.util.List<Role> roles = controller
|
||||||
|
.findRolesForContentSection(section);
|
||||||
|
|
||||||
|
return new RoleListModel(roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* 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., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.ui.role;
|
||||||
|
|
||||||
|
import org.libreccm.security.Party;
|
||||||
|
import org.libreccm.security.Permission;
|
||||||
|
import org.libreccm.security.Role;
|
||||||
|
import org.libreccm.security.RoleRepository;
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.ContentSectionManager;
|
||||||
|
import org.librecms.contentsection.ContentSectionRepository;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class RoleAdminPaneController {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentSectionRepository sectionRepo;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentSectionManager sectionManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private RoleRepository roleRepo;
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public List<Role> findRolesForContentSection(final ContentSection section) {
|
||||||
|
final ContentSection contentSection = sectionRepo
|
||||||
|
.findById(section.getObjectId())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||||
|
"No ContentSection with id %d in the database. "
|
||||||
|
+ "Where did that ID come from?",
|
||||||
|
section.getObjectId())));
|
||||||
|
|
||||||
|
return new ArrayList<>(contentSection.getRoles());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public String generateGrantedPermissionsString(final Role role) {
|
||||||
|
final Role theRole = roleRepo
|
||||||
|
.findById(role.getRoleId())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||||
|
"No role with ID %d in the database. Where did that Id come from?",
|
||||||
|
role.getRoleId())));
|
||||||
|
|
||||||
|
return theRole.getPermissions().stream()
|
||||||
|
.map(Permission::getGrantedPrivilege)
|
||||||
|
.collect(Collectors.joining(", "));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public List<Party> createRoleMemberList(final Role role) {
|
||||||
|
final Role theRole = roleRepo
|
||||||
|
.findById(role.getRoleId())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||||
|
"No role with ID %d in the database. Where did that Id come from?",
|
||||||
|
role.getRoleId())));
|
||||||
|
|
||||||
|
return theRole.getMemberships()
|
||||||
|
.stream()
|
||||||
|
.map(membership -> membership.getMember())
|
||||||
|
.sorted((member1, member2) -> {
|
||||||
|
return member1.getName().compareTo(member2.getName());
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -19,38 +19,44 @@
|
||||||
package com.arsdigita.cms.ui.role;
|
package com.arsdigita.cms.ui.role;
|
||||||
|
|
||||||
import com.arsdigita.bebop.list.ListModel;
|
import com.arsdigita.bebop.list.ListModel;
|
||||||
|
|
||||||
import org.libreccm.security.Role;
|
import org.libreccm.security.Role;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a {@link ListModel} implementation for Collections of Roles.
|
* Provides a {@link ListModel} implementation for Collections of Roles. This
|
||||||
* This class is usable like an iterator, with an exception.
|
* class is usable like an iterator, with an exception. The {@link #next()}
|
||||||
* The {@link #next()} method only moves the iterator forward. To get elements you need to first
|
* method only moves the iterator forward. To get elements you need to first use
|
||||||
* use {@link #next()} and afterwards {@link #getRole()}, {@link #getElement()} or {@link #getKey()}.
|
* {@link #next()} and afterwards {@link #getRole()}, {@link #getElement()} or
|
||||||
|
* {@link #getKey()}.
|
||||||
*
|
*
|
||||||
* Also remember that the iterator does not move unless {@link #next()} is called.
|
* Also remember that the iterator does not move unless {@link #next()} is
|
||||||
|
* called.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||||
*/
|
*/
|
||||||
class RoleListModel implements ListModel {
|
class RoleListModel implements ListModel {
|
||||||
|
|
||||||
private final Collection<Role> m_roles;
|
private final List<Role> m_roles;
|
||||||
|
|
||||||
private Iterator<Role> iterator;
|
private Iterator<Role> iterator;
|
||||||
|
|
||||||
private Role currentRole;
|
private Role currentRole;
|
||||||
|
|
||||||
RoleListModel(final Collection<Role> roles) {
|
RoleListModel(final List<Role> roles) {
|
||||||
m_roles = roles;
|
m_roles = roles;
|
||||||
iterator = roles.iterator();
|
iterator = roles.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean next() {
|
public final boolean next() {
|
||||||
currentRole = iterator.next();
|
if (iterator.hasNext()) {
|
||||||
return currentRole != null;
|
currentRole = iterator.next();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -74,4 +80,5 @@ class RoleListModel implements ListModel {
|
||||||
public final void reset() {
|
public final void reset() {
|
||||||
iterator = m_roles.iterator();
|
iterator = m_roles.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,22 +20,23 @@ package com.arsdigita.cms.ui.role;
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.RequestLocal;
|
import com.arsdigita.bebop.RequestLocal;
|
||||||
import com.arsdigita.util.Assert;
|
|
||||||
import org.libreccm.security.Role;
|
import org.libreccm.security.Role;
|
||||||
|
|
||||||
/**
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
* See {@link RequestLocal} for more information.
|
* See {@link RequestLocal} for more information.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||||
* @version $Id: RoleRequestLocal.java 287 2005-02-22 00:29:02Z sskracic $
|
|
||||||
*/
|
*/
|
||||||
abstract class RoleRequestLocal extends RequestLocal {
|
abstract class RoleRequestLocal extends RequestLocal {
|
||||||
|
|
||||||
final Role getRole(final PageState state) {
|
final Role getRole(final PageState state) {
|
||||||
final Role role = (Role) get(state);
|
@SuppressWarnings("unchecked")
|
||||||
|
final Optional<Role> role = (Optional<Role>) get(state);
|
||||||
Assert.exists(role, "Role role");
|
|
||||||
|
return role.get();
|
||||||
return role;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue