CCM NG/ccm-cms: Several bug fixes for RoleAdminPane

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4623 8810af33-2d31-482b-a856-94f89814c4df

Former-commit-id: 56ba52be5e
pull/2/head
jensp 2017-03-07 18:17:37 +00:00
parent 29b12e1ba3
commit 7414d83525
6 changed files with 141 additions and 35 deletions

View File

@ -18,7 +18,6 @@
*/
package com.arsdigita.cms.ui.role;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
@ -151,15 +150,15 @@ class BaseRoleItemPane extends BaseItemPane {
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())));
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(", "));
final RoleAdminPaneController controller = cdiUtil.findBean(
RoleAdminPaneController.class);
final String permissions = controller
.generateGrantedPermissionsString(role);
if (permissions.length() > 0) {
properties.add(new Property(lz("cms.ui.role.privileges"),

View File

@ -58,12 +58,10 @@ class MemberTableModelBuilder extends AbstractTableModelBuilder {
final PageState state) {
final Role role = roleRequestLocal.getRole(state);
final List<Party> members = role.getMemberships()
.stream()
.map(membership -> membership.getMember())
.collect(Collectors.toList());
members.sort((member1, member2) -> member1.getName().compareTo(
member2.getName()));
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final RoleAdminPaneController controller = cdiUtil.findBean(
RoleAdminPaneController.class);
final List<Party> members = controller.createRoleMemberList(role);
return new Model(members);
}

View File

@ -59,7 +59,7 @@ import org.librecms.contentsection.privileges.AdminPrivileges;
*
* @author Justin Ross &lt;jross@redhat.com&gt;
* @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> {
@ -172,7 +172,13 @@ public class RoleAdminPane extends BaseAdminPane<String> {
public final ListModel makeModel(final List list, final PageState state) {
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);
}
}

View File

@ -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());
}
}

View File

@ -19,38 +19,44 @@
package com.arsdigita.cms.ui.role;
import com.arsdigita.bebop.list.ListModel;
import org.libreccm.security.Role;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/**
* Provides a {@link ListModel} implementation for Collections of Roles.
* This class is usable like an iterator, with an exception.
* The {@link #next()} method only moves the iterator forward. To get elements you need to first
* use {@link #next()} and afterwards {@link #getRole()}, {@link #getElement()} or {@link #getKey()}.
* Provides a {@link ListModel} implementation for Collections of Roles. This
* class is usable like an iterator, with an exception. The {@link #next()}
* method only moves the iterator forward. To get elements you need to first use
* {@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>
*/
class RoleListModel implements ListModel {
private final Collection<Role> m_roles;
private final List<Role> m_roles;
private Iterator<Role> iterator;
private Role currentRole;
RoleListModel(final Collection<Role> roles) {
RoleListModel(final List<Role> roles) {
m_roles = roles;
iterator = roles.iterator();
}
@Override
public final boolean next() {
if (iterator.hasNext()) {
currentRole = iterator.next();
return currentRole != null;
return true;
} else {
return false;
}
}
@Override
@ -74,4 +80,5 @@ class RoleListModel implements ListModel {
public final void reset() {
iterator = m_roles.iterator();
}
}

View File

@ -20,22 +20,23 @@ package com.arsdigita.cms.ui.role;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.util.Assert;
import org.libreccm.security.Role;
import java.util.Optional;
/**
* See {@link RequestLocal} for more information.
*
* @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 {
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;
return role.get();
}
}