CCM NG/cc-core: Vaadin Prototype: Editing group and role memberships of a user.
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4851 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: c048a1fa15
pull/2/head
parent
4b5c4d4163
commit
00a33b1652
|
|
@ -20,7 +20,6 @@ package org.libreccm.admin.ui.usersgroupsroles;
|
|||
|
||||
import com.arsdigita.ui.admin.AdminUiConstants;
|
||||
|
||||
import com.vaadin.cdi.CDIUI;
|
||||
import com.vaadin.icons.VaadinIcons;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.FormLayout;
|
||||
|
|
@ -36,6 +35,8 @@ import com.vaadin.ui.components.grid.HeaderRow;
|
|||
import com.vaadin.ui.renderers.ButtonRenderer;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.Group;
|
||||
import org.libreccm.security.GroupRepository;
|
||||
import org.libreccm.security.Role;
|
||||
import org.libreccm.security.RoleRepository;
|
||||
import org.libreccm.security.User;
|
||||
|
|
@ -141,16 +142,69 @@ public class UserDetails extends Window {
|
|||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
|
||||
final UserGroupsController groupsController = cdiUtil
|
||||
.findBean(UserGroupsController.class);
|
||||
final Grid<Group> groupsGrid = new Grid<>();
|
||||
groupsGrid
|
||||
.addColumn(Group::getName)
|
||||
.setId(COL_GROUP_NAME)
|
||||
.setCaption("Group");
|
||||
groupsGrid
|
||||
.addColumn(group -> bundle
|
||||
.getString("ui.user.groups.remove"),
|
||||
new ButtonRenderer<>(event -> {
|
||||
groupsController
|
||||
.removeUserFromGroup(user, event.getItem());
|
||||
groupsGrid.getDataProvider().refreshAll();
|
||||
}))
|
||||
.setId(COL_GROUP_REMOVE);
|
||||
|
||||
groupsGrid.setWidth("100%");
|
||||
|
||||
final GroupRepository groupRepo = cdiUtil
|
||||
.findBean(GroupRepository.class);
|
||||
|
||||
final HeaderRow groupsGridHeader = groupsGrid.prependHeaderRow();
|
||||
final Button addGroupButton = new Button("Add group");
|
||||
addGroupButton.setIcon(VaadinIcons.PLUS);
|
||||
addGroupButton.setStyleName(ValoTheme.BUTTON_TINY);
|
||||
addGroupButton.addClickListener(event -> {
|
||||
final GroupSelector groupSelector = new GroupSelector(
|
||||
"Select group(s) to which the user is added.",
|
||||
"Add user to selected groups",
|
||||
usersGroupsRoles,
|
||||
groupRepo.findByMember(user),
|
||||
(selectedGroups -> {
|
||||
selectedGroups.forEach(group -> {
|
||||
groupsController.addUserToGroup(user, group);
|
||||
});
|
||||
groupsGrid.getDataProvider().refreshAll();
|
||||
}));
|
||||
groupSelector.center();
|
||||
groupSelector.setWidth("80%");
|
||||
UI.getCurrent().addWindow(groupSelector);
|
||||
});
|
||||
final HeaderCell groupsGridHeaderCell = groupsGridHeader
|
||||
.join(COL_GROUP_NAME,
|
||||
COL_GROUP_REMOVE);
|
||||
groupsGridHeaderCell
|
||||
.setComponent(new HorizontalLayout(addGroupButton));
|
||||
|
||||
final UserGroupsTableDataProvider groupsDataProvider = cdiUtil
|
||||
.findBean(UserGroupsTableDataProvider.class);
|
||||
groupsDataProvider.setUser(user);
|
||||
groupsGrid.setDataProvider(groupsDataProvider);
|
||||
|
||||
final UserRolesController rolesController = cdiUtil
|
||||
.findBean(UserRolesController.class);
|
||||
final Grid<Role> rolesGrid = new Grid<>();
|
||||
rolesGrid
|
||||
.addColumn(Role::getName)
|
||||
.setId(COL_ROLE_NAME)
|
||||
.setCaption("Role name");
|
||||
.setCaption("Role");
|
||||
rolesGrid
|
||||
.addColumn(role -> bundle
|
||||
.getString("ui.groups.roles.remove"),
|
||||
.getString("ui.user.roles.remove"),
|
||||
new ButtonRenderer<>(event -> {
|
||||
rolesController
|
||||
.removeRoleFromUser(event.getItem(), user);
|
||||
|
|
@ -175,8 +229,8 @@ public class UserDetails extends Window {
|
|||
(selectedRoles -> {
|
||||
selectedRoles.forEach(role -> {
|
||||
rolesController.assignRoleToUser(role, user);
|
||||
rolesGrid.getDataProvider().refreshAll();
|
||||
});
|
||||
rolesGrid.getDataProvider().refreshAll();
|
||||
}));
|
||||
roleSelector.center();
|
||||
roleSelector.setWidth("80%");
|
||||
|
|
@ -192,10 +246,10 @@ public class UserDetails extends Window {
|
|||
.findBean(UserRolesTableDataProvider.class);
|
||||
rolesDataProvider.setUser(user);
|
||||
rolesGrid.setDataProvider(rolesDataProvider);
|
||||
|
||||
|
||||
final TabSheet tabs = new TabSheet();
|
||||
tabs.addTab(layout, "Details");
|
||||
tabs.addTab(layout, "Groups");
|
||||
tabs.addTab(groupsGrid, "Groups");
|
||||
tabs.addTab(rolesGrid, "Roles");
|
||||
|
||||
setContent(tabs);
|
||||
|
|
|
|||
|
|
@ -28,11 +28,9 @@ import com.vaadin.ui.Button;
|
|||
import com.vaadin.ui.CheckBox;
|
||||
import com.vaadin.ui.FormLayout;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Panel;
|
||||
import com.vaadin.ui.PasswordField;
|
||||
import com.vaadin.ui.RadioButtonGroup;
|
||||
import com.vaadin.ui.TabSheet;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import org.libreccm.security.Group;
|
|||
import org.libreccm.security.GroupMembership;
|
||||
import org.libreccm.security.User;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
|
@ -42,7 +41,7 @@ import javax.transaction.Transactional;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@ViewScoped
|
||||
class UserGroupsDataProvider extends AbstractDataProvider<Group, String> {
|
||||
class UserGroupsTableDataProvider extends AbstractDataProvider<Group, String> {
|
||||
|
||||
private static final long serialVersionUID = 3321330114174366998L;
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ class UserRolesController {
|
|||
.format("No user with ID %d in the database. ",
|
||||
user.getPartyId())));
|
||||
|
||||
roleManager.assignRoleToParty(role, theUser);
|
||||
roleManager.assignRoleToParty(theRole, theUser);
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
|
|
|
|||
|
|
@ -49,9 +49,6 @@ public class UserSelector extends Window {
|
|||
private static final String COL_FAMILY_NAME = "family_name";
|
||||
private static final String COL_EMAIL = "email";
|
||||
|
||||
private final UserRepository userRepo;
|
||||
|
||||
private final UserSelectionAction groupSelectionAction;
|
||||
|
||||
public UserSelector(final String caption,
|
||||
final String actionLabel,
|
||||
|
|
@ -59,10 +56,6 @@ public class UserSelector extends Window {
|
|||
final List<User> excludedUsers,
|
||||
final UserSelectionAction action) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
userRepo = cdiUtil.findBean(UserRepository.class);
|
||||
this.groupSelectionAction = action;
|
||||
|
||||
addWidgets(caption, actionLabel, excludedUsers, action);
|
||||
}
|
||||
|
||||
|
|
@ -80,13 +73,16 @@ public class UserSelector extends Window {
|
|||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
|
||||
final Grid<User> usersGrid = new Grid<>();
|
||||
usersGrid.addColumn(User::getName)
|
||||
usersGrid
|
||||
.addColumn(User::getName)
|
||||
.setId(COL_USER_NAME)
|
||||
.setCaption("User Name");
|
||||
usersGrid.addColumn(User::getGivenName)
|
||||
usersGrid
|
||||
.addColumn(User::getGivenName)
|
||||
.setId(COL_GIVEN_NAME)
|
||||
.setCaption("Given name");
|
||||
usersGrid.addColumn(User::getFamilyName)
|
||||
usersGrid
|
||||
.addColumn(User::getFamilyName)
|
||||
.setId(COL_FAMILY_NAME)
|
||||
.setCaption("Family name");
|
||||
usersGrid
|
||||
|
|
|
|||
|
|
@ -57,10 +57,10 @@ public class UserSelectorDataProvider extends AbstractDataProvider<User, String>
|
|||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public int size(final Query<User, String> query) {
|
||||
|
||||
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
|
||||
final Root<User> from = criteriaQuery.from(User.class);
|
||||
|
||||
criteriaQuery = criteriaQuery.select(builder.count(from));
|
||||
criteriaQuery = criteriaQuery.distinct(true);
|
||||
|
||||
|
|
@ -83,6 +83,7 @@ public class UserSelectorDataProvider extends AbstractDataProvider<User, String>
|
|||
@Transactional
|
||||
@Override
|
||||
public Stream<User> fetch(final Query<User, String> query) {
|
||||
|
||||
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<User> criteriaQuery = builder
|
||||
.createQuery(User.class);
|
||||
|
|
|
|||
|
|
@ -59,21 +59,31 @@ import static org.libreccm.core.CoreConstants.DB_SCHEMA;
|
|||
@NamedQuery(
|
||||
name = "Group.findByName",
|
||||
query = "SELECT g FROM Group g WHERE g.name = :name "
|
||||
+ "ORDER BY g.name"),
|
||||
+ "ORDER BY g.name")
|
||||
,
|
||||
@NamedQuery(
|
||||
name = "Group.searchByName",
|
||||
query = "SELECT g FROM Group g "
|
||||
+ "WHERE LOWER(g.name) LIKE CONCAT(LOWER(:name), '%') "
|
||||
+ "ORDER BY g.name"),
|
||||
+ "ORDER BY g.name")
|
||||
,
|
||||
@NamedQuery(
|
||||
name = "Group.findAllOrderedByGroupName",
|
||||
query = "SELECT g FROM Group g ORDER BY g.name")
|
||||
,
|
||||
@NamedQuery(
|
||||
name = "Group.findByMember",
|
||||
query = "SELECT g FROM Group g "
|
||||
+ "JOIN g.memberships m "
|
||||
+ "WHERE m.member = :member"
|
||||
)
|
||||
})
|
||||
@NamedEntityGraphs({
|
||||
@NamedEntityGraph(
|
||||
name = "Group.withMembersAndRoleMemberships",
|
||||
attributeNodes = {
|
||||
@NamedAttributeNode(value = "memberships"),
|
||||
@NamedAttributeNode(value = "memberships")
|
||||
,
|
||||
@NamedAttributeNode(value = "roleMemberships",
|
||||
subgraph = "role")},
|
||||
subgraphs = {
|
||||
|
|
@ -82,7 +92,8 @@ import static org.libreccm.core.CoreConstants.DB_SCHEMA;
|
|||
attributeNodes = {
|
||||
@NamedAttributeNode(value = "role",
|
||||
subgraph = "permissions")
|
||||
}),
|
||||
})
|
||||
,
|
||||
@NamedSubgraph(
|
||||
name = "permissions",
|
||||
attributeNodes = {
|
||||
|
|
|
|||
|
|
@ -74,6 +74,15 @@ public class GroupRepository extends AbstractEntityRepository<Long, Group> {
|
|||
}
|
||||
}
|
||||
|
||||
public List<Group> findByMember(final Party member) {
|
||||
|
||||
final TypedQuery<Group> query = getEntityManager()
|
||||
.createNamedQuery("Group.findByMember", Group.class);
|
||||
query.setParameter("member", member);
|
||||
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find a group which name contains a provided token.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -43,12 +43,12 @@ import javax.persistence.NamedQueries;
|
|||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
|
|||
|
|
@ -611,3 +611,4 @@ ui.admin.importexport.import.status.locked=This should not happen.
|
|||
ui.admin.importexport.import.current_status=Import current status
|
||||
ui.admin.importexport.import.report=Report from last import process
|
||||
ui.groups.roles.remove=Remove
|
||||
ui.user.groups.remove=Remove
|
||||
|
|
|
|||
|
|
@ -615,3 +615,4 @@ ui.admin.importexport.import.status.locked=This should not happen.
|
|||
ui.admin.importexport.import.current_status=Aktueller Status des Import-Prozesses
|
||||
ui.admin.importexport.import.report=Bericht des letzten Import-Prozesses
|
||||
ui.groups.roles.remove=Entfernen
|
||||
ui.user.groups.remove=Entfernen
|
||||
|
|
|
|||
|
|
@ -608,3 +608,4 @@ ui.admin.importexport.import.status.locked=This should not happen.
|
|||
ui.admin.importexport.import.current_status=Import current status
|
||||
ui.admin.importexport.import.report=Report from last import process
|
||||
ui.groups.roles.remove=Remove
|
||||
ui.user.groups.remove=Remove
|
||||
|
|
|
|||
|
|
@ -599,3 +599,4 @@ ui.admin.importexport.import.status.locked=This should not happen.
|
|||
ui.admin.importexport.import.current_status=Import current status
|
||||
ui.admin.importexport.import.report=Report from last import process
|
||||
ui.groups.roles.remove=Remove
|
||||
ui.user.groups.remove=Remove
|
||||
|
|
|
|||
Loading…
Reference in New Issue