Removed depcrecated package com.arsdigita.ui.admin
parent
285e8c977c
commit
c0fb04533d
|
|
@ -1,55 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2015 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.ui.admin.applications;
|
|
||||||
|
|
||||||
import org.libreccm.web.ApplicationCreator;
|
|
||||||
import org.libreccm.web.ApplicationRepository;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
@RequestScoped
|
|
||||||
public class AdminApplicationCreator
|
|
||||||
implements ApplicationCreator<CcmApplication> {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ApplicationRepository appRepository;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CcmApplication createInstance(final String primaryUrl,
|
|
||||||
final ApplicationType type) {
|
|
||||||
if (!ADMIN_PAGE_URL.equals(primaryUrl)) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"CCM Admin is a singleton application"
|
|
||||||
+ "which is mounted at /admin");
|
|
||||||
}
|
|
||||||
|
|
||||||
return appRepository.retrieveApplicationForPath(primaryUrl).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.applications;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.libreccm.modules.InstallEvent;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
import org.libreccm.web.AbstractCcmApplicationSetup;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class AdminApplicationSetup extends AbstractCcmApplicationSetup {
|
|
||||||
|
|
||||||
public static final String ADMIN_APP_NAME = "CcmAdmin";
|
|
||||||
|
|
||||||
public AdminApplicationSetup(final InstallEvent event) {
|
|
||||||
super(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setup() {
|
|
||||||
final CcmApplication admin = new CcmApplication();
|
|
||||||
admin.setUuid(UUID.randomUUID().toString());
|
|
||||||
admin.setApplicationType(ADMIN_APP_TYPE);
|
|
||||||
admin.setPrimaryUrl(ADMIN_PAGE_URL);
|
|
||||||
|
|
||||||
getEntityManager().persist(admin);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,197 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles;
|
|
||||||
|
|
||||||
import com.arsdigita.ui.admin.usersgroupsroles.users.UserAdmin;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.List;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.Resettable;
|
|
||||||
import com.arsdigita.bebop.list.ListModel;
|
|
||||||
import com.arsdigita.bebop.list.ListModelBuilder;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
|
||||||
import com.arsdigita.ui.admin.usersgroupsroles.groups.GroupAdmin;
|
|
||||||
import com.arsdigita.ui.admin.usersgroupsroles.roles.RoleAdmin;
|
|
||||||
import com.arsdigita.util.Assert;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Root component of the administration UI for users, groups and roles.
|
|
||||||
* This class creates the menu on the left side and connects the menu with the
|
|
||||||
* specific UIs for users, groups and roles.
|
|
||||||
*
|
|
||||||
* @see UserAdmin
|
|
||||||
* @see GroupAdmin
|
|
||||||
* @see RoleAdmin
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class UsersGroupsRolesTab extends LayoutPanel {
|
|
||||||
|
|
||||||
private final List sections;
|
|
||||||
private final java.util.List<Component> components = new ArrayList<>();
|
|
||||||
private final java.util.List<Label> keys = new ArrayList<>();
|
|
||||||
|
|
||||||
public UsersGroupsRolesTab() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
setClassAttr("sidebarNavPanel");
|
|
||||||
|
|
||||||
sections = new List(new SectionsListModelBuilder());
|
|
||||||
sections.addChangeListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final int selectedIndex = Integer.parseInt((String) sections
|
|
||||||
.getSelectedKey(state));
|
|
||||||
setSection(selectedIndex, state);
|
|
||||||
});
|
|
||||||
sections.setClassAttr("navbar");
|
|
||||||
|
|
||||||
final BoxPanel body = new BoxPanel();
|
|
||||||
addSection(
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.users_groups_roles.users.title",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
new UserAdmin(),
|
|
||||||
body);
|
|
||||||
addSection(
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.users_groups_roles.groups.title",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
new GroupAdmin(),
|
|
||||||
body);
|
|
||||||
addSection(
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.users_roles_roles.users.title",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
new RoleAdmin(),
|
|
||||||
body);
|
|
||||||
|
|
||||||
setLeft(sections);
|
|
||||||
setBody(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method for adding a section
|
|
||||||
*
|
|
||||||
* @param label The label of the section.
|
|
||||||
* @param component The component which provides the section.
|
|
||||||
* @param panel The panel to which the component is added.
|
|
||||||
*/
|
|
||||||
private void addSection(final Label label,
|
|
||||||
final Component component,
|
|
||||||
final BoxPanel panel) {
|
|
||||||
Assert.isUnlocked(this);
|
|
||||||
components.add(component);
|
|
||||||
component.setClassAttr("main");
|
|
||||||
panel.add(component);
|
|
||||||
keys.add(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the components in the page
|
|
||||||
*
|
|
||||||
* @param page The Admin UI page.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void register(final Page page) {
|
|
||||||
Assert.isUnlocked(this);
|
|
||||||
|
|
||||||
components.forEach(c -> page.setVisibleDefault(c, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the current section.
|
|
||||||
*
|
|
||||||
* @param index The index of the section.
|
|
||||||
* @param state The page state.
|
|
||||||
*/
|
|
||||||
public void setSection(final int index, final PageState state) {
|
|
||||||
sections.setSelectedKey(state, String.valueOf(index));
|
|
||||||
for(int i = 0; i < components.size(); i++) {
|
|
||||||
if (i == index) {
|
|
||||||
final Component component = components.get(i);
|
|
||||||
component.setVisible(state, true);
|
|
||||||
if (component instanceof Resettable) {
|
|
||||||
final Resettable resettable = (Resettable) component;
|
|
||||||
resettable.reset(state);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
components.get(i).setVisible(state, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model Builder for the section list.
|
|
||||||
*/
|
|
||||||
private class SectionsListModelBuilder extends LockableImpl
|
|
||||||
implements ListModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ListModel makeModel(final List list,
|
|
||||||
final PageState state) {
|
|
||||||
if (sections.getSelectedKey(state) == null) {
|
|
||||||
sections.setSelectedKey(state, String.valueOf(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SectionsListModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model for the section list.
|
|
||||||
*/
|
|
||||||
private class SectionsListModel implements ListModel {
|
|
||||||
|
|
||||||
private int index = -1;
|
|
||||||
private final PageState state;
|
|
||||||
|
|
||||||
public SectionsListModel(final PageState state) {
|
|
||||||
this.state = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean next() {
|
|
||||||
final boolean result = (index < keys.size() - 1);
|
|
||||||
index++;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElement() {
|
|
||||||
return keys.get(index).getLabel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKey() {
|
|
||||||
return String.valueOf(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,288 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.groups;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
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.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Group;
|
|
||||||
import org.libreccm.security.GroupManager;
|
|
||||||
import org.libreccm.security.GroupRepository;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form for adding a new member to group. The form contains a form for searching
|
|
||||||
* members (uses the user name, the family name, the given name and the primary
|
|
||||||
* email address). After a search term was send, a table with all matching users
|
|
||||||
* is displayed. The table also contains an action link for adding a user to the
|
|
||||||
* group which is currently selected..
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class GroupAddMemberForm extends Form {
|
|
||||||
|
|
||||||
private static final String MEMBER_NAME = "membername";
|
|
||||||
|
|
||||||
private static final int COL_MEMBER_NAME = 0;
|
|
||||||
private static final int COL_MEMBER_FAMILY_NAME = 1;
|
|
||||||
private static final int COL_MEMBER_GIVEN_NAME = 2;
|
|
||||||
private static final int COL_MEMBER_EMAIL = 3;
|
|
||||||
private static final int COL_MEMBER_ADD = 4;
|
|
||||||
|
|
||||||
private final TextField memberName;
|
|
||||||
|
|
||||||
public GroupAddMemberForm(
|
|
||||||
final GroupAdmin groupAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedGroupId) {
|
|
||||||
|
|
||||||
super("groupAddMemberForm");
|
|
||||||
|
|
||||||
final BoxPanel links = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
final ActionLink backToGroup = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_member.back", ADMIN_BUNDLE));
|
|
||||||
backToGroup.addActionListener(e -> {
|
|
||||||
groupAdmin.hideGroupMemberAddForm(e.getPageState());
|
|
||||||
});
|
|
||||||
links.add(backToGroup);
|
|
||||||
|
|
||||||
final Label heading = new Label();
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
heading.addPrintListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final GroupRepository groupRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(GroupRepository.class);
|
|
||||||
final Group group = groupRepository.findById(Long.parseLong(
|
|
||||||
selectedGroupId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_member.header",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{group.getName()}));
|
|
||||||
|
|
||||||
});
|
|
||||||
links.add(heading);
|
|
||||||
|
|
||||||
add(links);
|
|
||||||
|
|
||||||
memberName = new TextField(MEMBER_NAME);
|
|
||||||
memberName.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_member.find", ADMIN_BUNDLE));
|
|
||||||
add(memberName);
|
|
||||||
|
|
||||||
final Submit submit = new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_member.search", ADMIN_BUNDLE));
|
|
||||||
add(submit);
|
|
||||||
|
|
||||||
add(new UsersToAddTable(groupAdmin, selectedGroupId));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class UsersToAddTable extends Table {
|
|
||||||
|
|
||||||
public UsersToAddTable(
|
|
||||||
final GroupAdmin groupAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedGroupId) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_member.table.empty", ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_NAME,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_member.table.name",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_FAMILY_NAME,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_member.table.family_name",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_GIVEN_NAME,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_member.table.given_name",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_EMAIL,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_member.table.email",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_ADD,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_member.table.add",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_MEMBER_ADD).setCellRenderer(
|
|
||||||
new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final String key = (String) event.getRowKey();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_MEMBER_ADD:
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UserRepository userRepository = cdiUtil
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final GroupRepository groupRepository = cdiUtil
|
|
||||||
.findBean(GroupRepository.class);
|
|
||||||
final GroupManager groupManager = cdiUtil.findBean(
|
|
||||||
GroupManager.class);
|
|
||||||
final User user = userRepository.findById(Long
|
|
||||||
.parseLong(key)).get();
|
|
||||||
final Group group = groupRepository.findById(
|
|
||||||
Long.parseLong(
|
|
||||||
selectedGroupId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
groupManager.addMemberToGroup(user, group);
|
|
||||||
groupAdmin.hideGroupMemberAddForm(state);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Invalid value for column");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
// Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new UsersToAddTableModelBuilder());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class UsersToAddTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
return new UsersToAddTableModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class UsersToAddTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final List<User> users;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public UsersToAddTableModel(final PageState state) {
|
|
||||||
final String term = (String) memberName.getValue(state);
|
|
||||||
if (term == null || term.isEmpty()) {
|
|
||||||
users = new ArrayList<>();
|
|
||||||
} else {
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
users = userRepository.filtered(term);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < users.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
final User user = users.get(index);
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_MEMBER_NAME:
|
|
||||||
return user.getName();
|
|
||||||
case COL_MEMBER_FAMILY_NAME:
|
|
||||||
return user.getFamilyName();
|
|
||||||
case COL_MEMBER_GIVEN_NAME:
|
|
||||||
return user.getGivenName();
|
|
||||||
case COL_MEMBER_EMAIL:
|
|
||||||
return user.getPrimaryEmailAddress().getAddress();
|
|
||||||
case COL_MEMBER_ADD:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_member.table.add",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return users.get(index).getPartyId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,230 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.groups;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* UI for managing the groups (collections of users) in the system.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class GroupAdmin extends BoxPanel {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parameter for the currently selected group.
|
|
||||||
*/
|
|
||||||
private final StringParameter groupIdParameter;
|
|
||||||
/**
|
|
||||||
* Model for the current selected group.
|
|
||||||
*/
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedGroupId;
|
|
||||||
/**
|
|
||||||
* Text field for the filter UI for filtering the groups table.
|
|
||||||
*/
|
|
||||||
private final TextField groupsTableFilter;
|
|
||||||
/**
|
|
||||||
* The panel containing the groups table and some supporting UI elements.
|
|
||||||
*/
|
|
||||||
private final BoxPanel groupsTablePanel;
|
|
||||||
/**
|
|
||||||
* The groups table itself.
|
|
||||||
*/
|
|
||||||
private final GroupsTable groupsTable;
|
|
||||||
/**
|
|
||||||
* The form for creating new groups and editing the properties of existing
|
|
||||||
* groups.
|
|
||||||
*/
|
|
||||||
private final GroupForm groupForm;
|
|
||||||
/**
|
|
||||||
* The component which displays the details of a group.
|
|
||||||
*/
|
|
||||||
private final GroupDetails groupDetails;
|
|
||||||
/**
|
|
||||||
* The form for adding members to a group.
|
|
||||||
*/
|
|
||||||
private final GroupAddMemberForm groupAddMemberForm;
|
|
||||||
|
|
||||||
public GroupAdmin() {
|
|
||||||
super(BoxPanel.VERTICAL);
|
|
||||||
|
|
||||||
setIdAttr("groupAdmin");
|
|
||||||
|
|
||||||
final Label heading = new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.groups.heading", ADMIN_BUNDLE));
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
groupsTablePanel = new BoxPanel();
|
|
||||||
groupsTablePanel.setIdAttr("groupsTablePanel");
|
|
||||||
|
|
||||||
final Form filterForm = new Form("groupsTableFilterForm");
|
|
||||||
groupsTableFilter = new TextField("groupsTableFilter");
|
|
||||||
groupsTableFilter.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.groups.table.filter.term", ADMIN_BUNDLE));
|
|
||||||
filterForm.add(groupsTableFilter);
|
|
||||||
filterForm.add(new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.groups.table.filter.submit", ADMIN_BUNDLE)));
|
|
||||||
final ActionLink clearLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.groups.table.filter.clear", ADMIN_BUNDLE));
|
|
||||||
clearLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
groupsTableFilter.setValue(state, null);
|
|
||||||
});
|
|
||||||
filterForm.add(clearLink);
|
|
||||||
groupsTablePanel.add(filterForm);
|
|
||||||
|
|
||||||
groupIdParameter = new StringParameter("selected_group_id");
|
|
||||||
selectedGroupId = new ParameterSingleSelectionModel<>(
|
|
||||||
groupIdParameter);
|
|
||||||
|
|
||||||
groupsTable = new GroupsTable(this, groupsTableFilter, selectedGroupId);
|
|
||||||
groupsTablePanel.add(groupsTable);
|
|
||||||
|
|
||||||
final ActionLink addNewGroupLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_group_link", ADMIN_BUNDLE));
|
|
||||||
addNewGroupLink.addActionListener(e -> {
|
|
||||||
showGroupForm(e.getPageState());
|
|
||||||
});
|
|
||||||
groupsTablePanel.add(addNewGroupLink);
|
|
||||||
|
|
||||||
add(groupsTablePanel);
|
|
||||||
|
|
||||||
groupForm = new GroupForm(this, selectedGroupId);
|
|
||||||
add(groupForm);
|
|
||||||
|
|
||||||
groupDetails = new GroupDetails(this, selectedGroupId);
|
|
||||||
add(groupDetails);
|
|
||||||
|
|
||||||
groupAddMemberForm = new GroupAddMemberForm(this, selectedGroupId);
|
|
||||||
add(groupAddMemberForm);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the top level components of the UI in the page. Otherwise we
|
|
||||||
* can't control their visibility.
|
|
||||||
*
|
|
||||||
* @param page
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void register(final Page page) {
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
page.addGlobalStateParam(groupIdParameter);
|
|
||||||
|
|
||||||
page.setVisibleDefault(groupsTablePanel, true);
|
|
||||||
page.setVisibleDefault(groupForm, false);
|
|
||||||
page.setVisibleDefault(groupDetails, false);
|
|
||||||
page.setVisibleDefault(groupAddMemberForm, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the groups details visible and all other components invisible.
|
|
||||||
*
|
|
||||||
* @param state The current {@link PageState}.
|
|
||||||
*/
|
|
||||||
protected void showGroupDetails(final PageState state) {
|
|
||||||
groupsTablePanel.setVisible(state, false);
|
|
||||||
groupForm.setVisible(state, false);
|
|
||||||
groupDetails.setVisible(state, true);
|
|
||||||
groupAddMemberForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the groups details invisible and sets the groups table visible. Also
|
|
||||||
* clears the {@link #selectedGroupId}.
|
|
||||||
*
|
|
||||||
* @param state The current {@link PageState}.
|
|
||||||
*/
|
|
||||||
protected void hideGroupDetails(final PageState state) {
|
|
||||||
selectedGroupId.clearSelection(state);
|
|
||||||
groupsTablePanel.setVisible(state, true);
|
|
||||||
groupForm.setVisible(state, false);
|
|
||||||
groupDetails.setVisible(state, false);
|
|
||||||
groupAddMemberForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows the form for creating new groups or editing the properties of
|
|
||||||
* existing groups.
|
|
||||||
*
|
|
||||||
* @param state The current {@link PageState}.
|
|
||||||
*/
|
|
||||||
protected void showGroupForm(final PageState state) {
|
|
||||||
groupsTablePanel.setVisible(state, false);
|
|
||||||
groupForm.setVisible(state, true);
|
|
||||||
groupDetails.setVisible(state, false);
|
|
||||||
groupAddMemberForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hides the group form and shows the groups table or the groups details
|
|
||||||
* depending of a group is selected or not.
|
|
||||||
*
|
|
||||||
* @param state The current {@link PageState}.
|
|
||||||
*/
|
|
||||||
protected void hideGroupForm(final PageState state) {
|
|
||||||
//We want to show the groups table if no group is selected and the
|
|
||||||
//group details if a group is selected.
|
|
||||||
boolean groupSelected = selectedGroupId.isSelected(state);
|
|
||||||
|
|
||||||
groupsTablePanel.setVisible(state, !groupSelected);
|
|
||||||
groupForm.setVisible(state, false);
|
|
||||||
groupDetails.setVisible(state, groupSelected);
|
|
||||||
groupAddMemberForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows the form for adding a member to a group. A group must be selected.
|
|
||||||
*
|
|
||||||
* @param state The current {@link PageState}.
|
|
||||||
*/
|
|
||||||
protected void showGroupMemberAddForm(final PageState state) {
|
|
||||||
groupsTablePanel.setVisible(state, false);
|
|
||||||
groupForm.setVisible(state, false);
|
|
||||||
groupDetails.setVisible(state, false);
|
|
||||||
groupAddMemberForm.setVisible(state, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hides the form for adding members to a group and shows the group details.
|
|
||||||
*
|
|
||||||
* @param state The current {@link PageState}.
|
|
||||||
*/
|
|
||||||
protected void hideGroupMemberAddForm(final PageState state) {
|
|
||||||
groupsTablePanel.setVisible(state, false);
|
|
||||||
groupForm.setVisible(state, false);
|
|
||||||
groupDetails.setVisible(state, true);
|
|
||||||
groupAddMemberForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,99 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.groups;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Group;
|
|
||||||
import org.libreccm.security.GroupRepository;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Panel which contains several components showing the properties of a group
|
|
||||||
* including a table of the members of the group.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class GroupDetails extends BoxPanel {
|
|
||||||
|
|
||||||
public GroupDetails(
|
|
||||||
final GroupAdmin groupAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedGroupId) {
|
|
||||||
|
|
||||||
super(BoxPanel.VERTICAL);
|
|
||||||
|
|
||||||
final ActionLink backLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.back", ADMIN_BUNDLE));
|
|
||||||
backLink.setClassAttr("back-link");
|
|
||||||
backLink.addActionListener(e -> {
|
|
||||||
groupAdmin.hideGroupDetails(e.getPageState());
|
|
||||||
});
|
|
||||||
add(backLink);
|
|
||||||
|
|
||||||
final Label header = new Label();
|
|
||||||
header.setClassAttr("heading");
|
|
||||||
header.addPrintListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
final GroupRepository groupRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(GroupRepository.class);
|
|
||||||
final Group group = groupRepository.findById(Long.parseLong(
|
|
||||||
selectedGroupId.getSelectedKey(state))).get();
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.header",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{group.getName()}));
|
|
||||||
});
|
|
||||||
add(header);
|
|
||||||
|
|
||||||
final PropertySheet propertySheet = new PropertySheet(
|
|
||||||
new GroupPropertySheetModelBuilder(selectedGroupId));
|
|
||||||
|
|
||||||
add(propertySheet);
|
|
||||||
|
|
||||||
final BoxPanel links = new BoxPanel(BoxPanel.HORIZONTAL);
|
|
||||||
final ActionLink editProperties = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.edit_properties", ADMIN_BUNDLE));
|
|
||||||
editProperties.addActionListener(e -> {
|
|
||||||
groupAdmin.showGroupForm(e.getPageState());
|
|
||||||
});
|
|
||||||
links.add(editProperties);
|
|
||||||
add(links);
|
|
||||||
|
|
||||||
final GroupMembersTable membersTable = new GroupMembersTable(
|
|
||||||
selectedGroupId);
|
|
||||||
add(membersTable);
|
|
||||||
|
|
||||||
final ActionLink addMember = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_member", ADMIN_BUNDLE));
|
|
||||||
addMember.addActionListener(e -> {
|
|
||||||
groupAdmin.showGroupMemberAddForm(e.getPageState());
|
|
||||||
});
|
|
||||||
add(addMember);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,176 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.groups;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Group;
|
|
||||||
import org.libreccm.security.GroupRepository;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form used for creating new groups and editing the properties of existing
|
|
||||||
* groups.
|
|
||||||
*
|
|
||||||
* If a group is selected (the provided {@link ParameterSingleSelectionModel}
|
|
||||||
* has a none null value) the group identified by that ID is loaded and the
|
|
||||||
* values are put into the fields and the changes are written back to the group
|
|
||||||
* when the form is submitted.
|
|
||||||
*
|
|
||||||
* If no group is selected a new group is created when the form is submitted.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class GroupForm extends Form {
|
|
||||||
|
|
||||||
private static final String GROUP_NAME = "groupname";
|
|
||||||
|
|
||||||
private final TextField groupName;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public GroupForm(
|
|
||||||
final GroupAdmin groupAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedGroupId) {
|
|
||||||
|
|
||||||
super("groupform");
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final String selectedGroupIdStr = selectedGroupId.getSelectedKey(
|
|
||||||
state);
|
|
||||||
if (selectedGroupIdStr == null || selectedGroupIdStr.isEmpty()) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.group.create_new",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
} else {
|
|
||||||
target.setLabel(new GlobalizedMessage("ui.admin.group.edit",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
groupName = new TextField(GROUP_NAME);
|
|
||||||
groupName.setLabel(new GlobalizedMessage("ui.admin.group.name",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
|
|
||||||
add(groupName);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String groupNameData = data.getString(GROUP_NAME);
|
|
||||||
|
|
||||||
if (groupNameData == null || groupNameData.isEmpty()) {
|
|
||||||
data.addError(GROUP_NAME, new GlobalizedMessage(
|
|
||||||
"ui.admin.group.name.error.notempty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (groupNameData.length() > 256) {
|
|
||||||
data.addError(GROUP_NAME, new GlobalizedMessage(
|
|
||||||
"ui.admin.group.name.error.length",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final GroupRepository groupRepository = cdiUtil.findBean(
|
|
||||||
GroupRepository.class);
|
|
||||||
|
|
||||||
final Optional<Group> group = groupRepository.findByName(groupNameData);
|
|
||||||
if (group.isPresent()) {
|
|
||||||
data.addError(GROUP_NAME, new GlobalizedMessage(
|
|
||||||
"ui.admin.group.error.name_already_in_use",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addInitListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final String selectedGroupIdStr = selectedGroupId.getSelectedKey(
|
|
||||||
state);
|
|
||||||
|
|
||||||
if (selectedGroupIdStr != null && !selectedGroupIdStr.isEmpty()) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final GroupRepository groupRepository = cdiUtil.findBean(
|
|
||||||
GroupRepository.class);
|
|
||||||
|
|
||||||
final Group group = groupRepository.findById(Long.parseLong(
|
|
||||||
selectedGroupIdStr)).get();
|
|
||||||
groupName.setValue(state, group.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
final String groupNameData = data.getString(GROUP_NAME);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final GroupRepository groupRepository = cdiUtil.findBean(
|
|
||||||
GroupRepository.class);
|
|
||||||
|
|
||||||
final String selectedGroupIdStr = selectedGroupId.
|
|
||||||
getSelectedKey(state);
|
|
||||||
if (selectedGroupIdStr == null
|
|
||||||
|| selectedGroupIdStr.isEmpty()) {
|
|
||||||
final Group group = new Group();
|
|
||||||
group.setName(groupNameData);
|
|
||||||
|
|
||||||
groupRepository.save(group);
|
|
||||||
} else {
|
|
||||||
final Group group = groupRepository.findById(Long.parseLong(
|
|
||||||
selectedGroupIdStr)).get();
|
|
||||||
group.setName(groupNameData);
|
|
||||||
|
|
||||||
groupRepository.save(group);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
groupAdmin.hideGroupForm(state);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,242 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.groups;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
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.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Group;
|
|
||||||
import org.libreccm.security.GroupManager;
|
|
||||||
import org.libreccm.security.GroupRepository;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table which all members of a group.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class GroupMembersTable extends Table {
|
|
||||||
|
|
||||||
private static final int COL_MEMBER_NAME = 0;
|
|
||||||
private static final int COL_MEMBER_FAMILY_NAME = 1;
|
|
||||||
private static final int COL_MEMBER_GIVEN_NAME = 2;
|
|
||||||
private static final int COL_MEMBER_EMAIL = 3;
|
|
||||||
private static final int COL_MEMBER_REMOVE = 4;
|
|
||||||
|
|
||||||
public GroupMembersTable(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedGroupId) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
setIdAttr("groupMembersTable");
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.members.none", ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_NAME,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.members_table.cols.name",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_FAMILY_NAME,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.members_table.cols.family_name",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_GIVEN_NAME,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.members_table.cols.given_name",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_EMAIL,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.members_table.cols.email",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_REMOVE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.members_table.cols.remove",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_MEMBER_REMOVE).setCellRenderer(
|
|
||||||
new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.members_table.member.remove",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final String key = (String) event.getRowKey();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_MEMBER_REMOVE:
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UserRepository userRepository = cdiUtil
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final GroupRepository groupRepository = cdiUtil
|
|
||||||
.findBean(GroupRepository.class);
|
|
||||||
final GroupManager groupManager = cdiUtil.findBean(
|
|
||||||
GroupManager.class);
|
|
||||||
final User user = userRepository.findById(Long
|
|
||||||
.parseLong(key)).get();
|
|
||||||
final Group group = groupRepository.findById(
|
|
||||||
Long.parseLong(
|
|
||||||
selectedGroupId.getSelectedKey(state))).get();
|
|
||||||
groupManager.removeMemberFromGroup(user, group);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Invalid value for column");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new GroupMembersTableModelBuilder(selectedGroupId));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class GroupMembersTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedGroupId;
|
|
||||||
|
|
||||||
public GroupMembersTableModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedGroupId) {
|
|
||||||
|
|
||||||
this.selectedGroupId = selectedGroupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table, final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new GroupMembersTableModel(selectedGroupId, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class GroupMembersTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final List<User> members;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public GroupMembersTableModel(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedGroupId,
|
|
||||||
final PageState state) {
|
|
||||||
|
|
||||||
final GroupRepository groupRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(GroupRepository.class);
|
|
||||||
final Group group = groupRepository.findById(Long.parseLong(
|
|
||||||
selectedGroupId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
members = new ArrayList<>();
|
|
||||||
|
|
||||||
group.getMemberships().forEach(m -> {
|
|
||||||
members.add(m.getMember());
|
|
||||||
});
|
|
||||||
|
|
||||||
members.sort((m1, m2) -> {
|
|
||||||
return m1.getName().compareTo(m2.getName());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < members.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
final User member = members.get(index);
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_MEMBER_NAME:
|
|
||||||
return member.getName();
|
|
||||||
case COL_MEMBER_FAMILY_NAME:
|
|
||||||
return member.getFamilyName();
|
|
||||||
case COL_MEMBER_GIVEN_NAME:
|
|
||||||
return member.getGivenName();
|
|
||||||
case COL_MEMBER_EMAIL:
|
|
||||||
return member.getPrimaryEmailAddress().getAddress();
|
|
||||||
case COL_MEMBER_REMOVE:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.members_table.remove",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return members.get(index).getPartyId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,135 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.groups;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.security.Group;
|
|
||||||
import org.libreccm.security.RoleMembership;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The model for the property sheet of a group. The {@link GroupProperty} enum
|
|
||||||
* contains a list of all rows of the property sheet. The {@link #nextRow()}
|
|
||||||
* method of this model uses an iterator to iterate over the values of the enum
|
|
||||||
* and sets value of the {@link #currentProperty} field. Based on the value of
|
|
||||||
* the {@link #currentProperty} field the {@link #getValue()} method decides
|
|
||||||
* which information is shown.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class GroupPropertySheetModel implements PropertySheetModel {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An enum which identifies the rows of the property sheet. The
|
|
||||||
* {@link #nextRow()} method uses an iterator to iterate over all values the
|
|
||||||
* property.
|
|
||||||
*/
|
|
||||||
private static enum GroupProperty {
|
|
||||||
GROUP_NAME,
|
|
||||||
ROLES
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Group selectedGroup;
|
|
||||||
private final Iterator<GroupProperty> propertyIterator;
|
|
||||||
private GroupProperty currentProperty;
|
|
||||||
|
|
||||||
public GroupPropertySheetModel(final Group selectedGroup) {
|
|
||||||
this.selectedGroup = selectedGroup;
|
|
||||||
propertyIterator = Arrays.asList(GroupProperty.values()).iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
if (selectedGroup == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propertyIterator.hasNext()) {
|
|
||||||
currentProperty = propertyIterator.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLabel() {
|
|
||||||
return currentProperty.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GlobalizedMessage getGlobalizedLabel() {
|
|
||||||
return generateGlobalizedLabel(currentProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
private GlobalizedMessage generateGlobalizedLabel(
|
|
||||||
final GroupProperty property) {
|
|
||||||
|
|
||||||
final String key = String.join("",
|
|
||||||
"ui.admin.group.property_sheet.",
|
|
||||||
property.toString().toLowerCase());
|
|
||||||
return new GlobalizedMessage(key, ADMIN_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
switch (currentProperty) {
|
|
||||||
case GROUP_NAME:
|
|
||||||
return selectedGroup.getName();
|
|
||||||
case ROLES:
|
|
||||||
return retrieveRoles();
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method for retrieving all roles assigned to group. The roles are
|
|
||||||
* retrieved from the selected group, their names are than put into a sorted
|
|
||||||
* set which sorted alphabetically and the passed to a {@link StringJoiner}
|
|
||||||
* which creates a string which all roles separated by a comma.
|
|
||||||
*
|
|
||||||
* @return A string containing the names of all roles assigned to the group
|
|
||||||
* in alphabetical order separated by a comma.
|
|
||||||
*/
|
|
||||||
private String retrieveRoles() {
|
|
||||||
final Set<RoleMembership> roleMemberships = selectedGroup
|
|
||||||
.getRoleMemberships();
|
|
||||||
|
|
||||||
final SortedSet<String> roles = new TreeSet<>((r1, r2) -> {
|
|
||||||
return r1.compareTo(r2);
|
|
||||||
});
|
|
||||||
|
|
||||||
roleMemberships.forEach(m -> {
|
|
||||||
roles.add(m.getRole().getName());
|
|
||||||
});
|
|
||||||
|
|
||||||
return String.join(", ", roles.toArray(new String[roles.size()]));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.groups;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Group;
|
|
||||||
import org.libreccm.security.GroupRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model builder for the group property sheet creating the
|
|
||||||
* {@link GroupPropertySheetModel}.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class GroupPropertySheetModelBuilder
|
|
||||||
extends LockableImpl implements PropertySheetModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedGroupId;
|
|
||||||
|
|
||||||
public GroupPropertySheetModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedGroupId) {
|
|
||||||
this.selectedGroupId = selectedGroupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertySheetModel makeModel(final PropertySheet sheet,
|
|
||||||
final PageState state) {
|
|
||||||
final String groupIdStr = selectedGroupId.getSelectedKey(state);
|
|
||||||
final Group selectedGroup;
|
|
||||||
if (groupIdStr == null || groupIdStr.isEmpty()) {
|
|
||||||
selectedGroup = null;
|
|
||||||
} else {
|
|
||||||
final GroupRepository groupRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(GroupRepository.class);
|
|
||||||
selectedGroup = groupRepository.findById(Long.parseLong(groupIdStr)).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new GroupPropertySheetModel(selectedGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,232 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.groups;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
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.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
import java.util.List;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Group;
|
|
||||||
import org.libreccm.security.GroupRepository;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table listing all groups.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class GroupsTable extends Table {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(GroupsTable.class);
|
|
||||||
|
|
||||||
private static final int COL_GROUP_NAME = 0;
|
|
||||||
private static final int COL_DELETE = 1;
|
|
||||||
|
|
||||||
private final TextField groupsTableFilter;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedGroupId;
|
|
||||||
|
|
||||||
public GroupsTable(
|
|
||||||
final GroupAdmin parent,
|
|
||||||
final TextField groupsTableFilter,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedGroupId) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
super.setIdAttr("groupsTable");
|
|
||||||
super.setStyleAttr("width: 30em");
|
|
||||||
|
|
||||||
this.groupsTableFilter = groupsTableFilter;
|
|
||||||
this.selectedGroupId = selectedGroupId;
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.groups.table.no_groups", ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_GROUP_NAME,
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.groups.table.name",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DELETE,
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.groups.table.delete",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_GROUP_NAME).setCellRenderer(
|
|
||||||
new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
return new ControlLink((String) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
columnModel.get(COL_DELETE).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.group.delete.confirm", ADMIN_BUNDLE));
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final String key = (String) event.getRowKey();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_GROUP_NAME:
|
|
||||||
selectedGroupId.setSelectedKey(state, key);
|
|
||||||
parent.showGroupDetails(state);
|
|
||||||
break;
|
|
||||||
case COL_DELETE:
|
|
||||||
final GroupRepository groupRepository = CdiUtil
|
|
||||||
.createCdiUtil().findBean(GroupRepository.class);
|
|
||||||
final Group group = groupRepository.findById(
|
|
||||||
Long.parseLong(key)).get();
|
|
||||||
groupRepository.delete(group);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Invalid value for column.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new GroupsTableModelBuilder());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class GroupsTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new GroupsTableModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class GroupsTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final List<Group> groups;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public GroupsTableModel(final PageState state) {
|
|
||||||
LOGGER.debug("Creating GroupsTableModel");
|
|
||||||
final String filterTerm = (String) groupsTableFilter.getValue(state);
|
|
||||||
LOGGER.debug("Value of filter is: \"{}\"", filterTerm);
|
|
||||||
final GroupRepository groupRepository = CdiUtil.createCdiUtil().
|
|
||||||
findBean(GroupRepository.class);
|
|
||||||
if (filterTerm == null || filterTerm.isEmpty()) {
|
|
||||||
groups = groupRepository.findAllOrderedByGroupName();
|
|
||||||
LOGGER.debug("Found {} groups in database.", groups.size());
|
|
||||||
} else {
|
|
||||||
groups = groupRepository.searchGroupByName(filterTerm);
|
|
||||||
LOGGER.debug("Found {} groups in database which match the "
|
|
||||||
+ "filter \"{}\".",
|
|
||||||
groups.size(),
|
|
||||||
filterTerm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
LOGGER.debug("Next row called. Index is now {}", index);
|
|
||||||
return index < groups.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
LOGGER.debug("Getting element for row {}, column {}...",
|
|
||||||
index,
|
|
||||||
columnIndex);
|
|
||||||
final Group group = groups.get(index);
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_GROUP_NAME:
|
|
||||||
return group.getName();
|
|
||||||
case COL_DELETE:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.groups.table.delete", ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
LOGGER.debug("Getting key for row {}, column {}...",
|
|
||||||
index,
|
|
||||||
columnIndex);
|
|
||||||
return groups.get(index).getPartyId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,274 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.roles;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
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.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Group;
|
|
||||||
import org.libreccm.security.Party;
|
|
||||||
import org.libreccm.security.PartyRepository;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleManager;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form for adding members (users or groups) to a role.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class RoleAddMemberForm extends Form {
|
|
||||||
|
|
||||||
private static final String MEMBER_NAME = "membername";
|
|
||||||
|
|
||||||
private static final int COL_MEMBER_NAME = 0;
|
|
||||||
private static final int COL_MEMBER_TYPE = 1;
|
|
||||||
private static final int COL_MEMBER_ADD = 2;
|
|
||||||
|
|
||||||
private final TextField memberName;
|
|
||||||
|
|
||||||
public RoleAddMemberForm(
|
|
||||||
final RoleAdmin roleAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId) {
|
|
||||||
|
|
||||||
super("roleAddMemberForm");
|
|
||||||
|
|
||||||
final ActionLink backToRole = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.add.back", ADMIN_BUNDLE));
|
|
||||||
backToRole.addActionListener(e -> {
|
|
||||||
roleAdmin.hideRoleMemberAddForm(e.getPageState());
|
|
||||||
});
|
|
||||||
add(backToRole);
|
|
||||||
|
|
||||||
final Label heading = new Label();
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
heading.addPrintListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final RoleRepository roleRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(RoleRepository.class);
|
|
||||||
final Role role = roleRepository.findById(Long.parseLong(
|
|
||||||
selectedRoleId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.add.heading",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{role.getName()}));
|
|
||||||
});
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
memberName = new TextField(MEMBER_NAME);
|
|
||||||
memberName.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.add.find", ADMIN_BUNDLE));
|
|
||||||
add(memberName);
|
|
||||||
|
|
||||||
final Submit submit = new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.add.search", ADMIN_BUNDLE));
|
|
||||||
add(submit);
|
|
||||||
|
|
||||||
add(new PartiesToAdd(roleAdmin, selectedRoleId));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PartiesToAdd extends Table {
|
|
||||||
|
|
||||||
public PartiesToAdd(
|
|
||||||
final RoleAdmin roleAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.add.table.empty", ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_NAME,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.add.table.name", ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_TYPE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.add.table.type", ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_ADD,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.add.table.add", ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_MEMBER_ADD).setCellRenderer(
|
|
||||||
new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final String key = (String) event.getRowKey();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_MEMBER_ADD:
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
|
|
||||||
final RolesController controller = cdiUtil
|
|
||||||
.findBean(RolesController.class);
|
|
||||||
final PartyRepository partyRepository = cdiUtil
|
|
||||||
.findBean(PartyRepository.class);
|
|
||||||
final RoleRepository roleRepository = cdiUtil
|
|
||||||
.findBean(RoleRepository.class);
|
|
||||||
final RoleManager roleManager = cdiUtil.findBean(
|
|
||||||
RoleManager.class);
|
|
||||||
final Party party = partyRepository.findById(
|
|
||||||
Long.parseLong(key)).get();
|
|
||||||
|
|
||||||
final Role role = roleRepository.findById(
|
|
||||||
Long.parseLong(
|
|
||||||
selectedRoleId.getSelectedKey(state))).get();
|
|
||||||
controller.assignRoleToParty(role, party);
|
|
||||||
|
|
||||||
roleAdmin.hideRoleMemberAddForm(state);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Invalid value for column");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new PartiesToAddTableModelBuilder());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PartiesToAddTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
return new PartiesToAddTableModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PartiesToAddTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final List<Party> parties;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public PartiesToAddTableModel(final PageState state) {
|
|
||||||
final String term = (String) memberName.getValue(state);
|
|
||||||
if (term == null || term.isEmpty()) {
|
|
||||||
parties = new ArrayList<>();
|
|
||||||
} else {
|
|
||||||
final PartyRepository partyRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(PartyRepository.class);
|
|
||||||
parties = partyRepository.searchByName(term);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < parties.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
final Party party = parties.get(index);
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_MEMBER_NAME:
|
|
||||||
return party.getName();
|
|
||||||
case COL_MEMBER_TYPE:
|
|
||||||
if (party instanceof User) {
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.type.user",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
} else if (party instanceof Group) {
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.type.group",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
} else {
|
|
||||||
return "?";
|
|
||||||
}
|
|
||||||
case COL_MEMBER_ADD:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.table.add"));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return parties.get(index).getPartyId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,268 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.roles;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* UI for managing roles.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class RoleAdmin extends BoxPanel {
|
|
||||||
|
|
||||||
private final StringParameter roleIdParameter;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedRoleId;
|
|
||||||
private final BoxPanel rolesTablePanel;
|
|
||||||
private final RoleForm roleForm;
|
|
||||||
private final RoleDetails roleDetails;
|
|
||||||
private final BoxPanel roleMembersPanel;
|
|
||||||
private final RoleAddMemberForm roleAddMemberForm;
|
|
||||||
private final BoxPanel rolePermissionsPanel;
|
|
||||||
private final RolePermissionsForm rolePermissionsForm;
|
|
||||||
|
|
||||||
public RoleAdmin() {
|
|
||||||
super(BoxPanel.VERTICAL);
|
|
||||||
|
|
||||||
setIdAttr("roleAdmin");
|
|
||||||
|
|
||||||
roleIdParameter = new StringParameter("selected_role_id");
|
|
||||||
selectedRoleId = new ParameterSingleSelectionModel<>(roleIdParameter);
|
|
||||||
|
|
||||||
rolesTablePanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
rolesTablePanel.setIdAttr("rolesTablePanel");
|
|
||||||
|
|
||||||
final Form filterForm = new Form("rolesTableFilter");
|
|
||||||
final TextField rolesTableFilter = new TextField("rolesTableFilter");
|
|
||||||
rolesTableFilter.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.roles.table.filter.term", ADMIN_BUNDLE));
|
|
||||||
filterForm.add(rolesTableFilter);
|
|
||||||
filterForm.add(new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.roles.table.filter.submit", ADMIN_BUNDLE)));
|
|
||||||
final ActionLink clearLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.roles.table.filter.clear", ADMIN_BUNDLE));
|
|
||||||
clearLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
rolesTableFilter.setValue(state, null);
|
|
||||||
});
|
|
||||||
filterForm.add(clearLink);
|
|
||||||
rolesTablePanel.add(filterForm);
|
|
||||||
|
|
||||||
final RolesTable rolesTable = new RolesTable(this,
|
|
||||||
rolesTableFilter,
|
|
||||||
selectedRoleId);
|
|
||||||
rolesTablePanel.add(rolesTable);
|
|
||||||
|
|
||||||
final ActionLink addNewRole = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_role_link", ADMIN_BUNDLE));
|
|
||||||
addNewRole.addActionListener(e -> {
|
|
||||||
showRoleForm(e.getPageState());
|
|
||||||
});
|
|
||||||
rolesTablePanel.add(addNewRole);
|
|
||||||
|
|
||||||
add(rolesTablePanel);
|
|
||||||
|
|
||||||
roleForm = new RoleForm(this, selectedRoleId);
|
|
||||||
add(roleForm);
|
|
||||||
|
|
||||||
roleDetails = new RoleDetails(this, selectedRoleId);
|
|
||||||
add(roleDetails);
|
|
||||||
|
|
||||||
roleMembersPanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
final Label roleMembersHeading = new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.heading",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
roleMembersHeading.setClassAttr("heading");
|
|
||||||
roleMembersPanel.add(roleMembersHeading);
|
|
||||||
roleMembersPanel.add(new RoleMembersTable(selectedRoleId));
|
|
||||||
final ActionLink addRoleMember = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.add", ADMIN_BUNDLE));
|
|
||||||
addRoleMember.addActionListener(e -> {
|
|
||||||
showRoleMemberAddForm(e.getPageState());
|
|
||||||
});
|
|
||||||
roleMembersPanel.add(addRoleMember);
|
|
||||||
add(roleMembersPanel);
|
|
||||||
|
|
||||||
roleAddMemberForm = new RoleAddMemberForm(this, selectedRoleId);
|
|
||||||
add(roleAddMemberForm);
|
|
||||||
|
|
||||||
rolePermissionsPanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
final Label rolePermissionsHeading = new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_permissions.heading",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
rolePermissionsHeading.setClassAttr("heading");
|
|
||||||
rolePermissionsPanel.add(rolePermissionsHeading);
|
|
||||||
rolePermissionsPanel.add(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_permissions.note", ADMIN_BUNDLE)));
|
|
||||||
rolePermissionsPanel.add(new RolePermissionsTable(selectedRoleId));
|
|
||||||
final ActionLink addRolePermission = new ActionLink(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.role_permissions.add_permission", ADMIN_BUNDLE));
|
|
||||||
addRolePermission.addActionListener(e -> {
|
|
||||||
showRolePermissionAddForm(e.getPageState());
|
|
||||||
});
|
|
||||||
rolePermissionsPanel.add(addRolePermission);
|
|
||||||
add(rolePermissionsPanel);
|
|
||||||
|
|
||||||
rolePermissionsForm = new RolePermissionsForm(this, selectedRoleId);
|
|
||||||
add(rolePermissionsForm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(final Page page) {
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
page.addGlobalStateParam(roleIdParameter);
|
|
||||||
|
|
||||||
page.setVisibleDefault(rolesTablePanel, true);
|
|
||||||
page.setVisibleDefault(roleForm, false);
|
|
||||||
page.setVisibleDefault(roleDetails, false);
|
|
||||||
page.setVisibleDefault(roleMembersPanel, false);
|
|
||||||
page.setVisibleDefault(roleAddMemberForm, false);
|
|
||||||
page.setVisibleDefault(rolePermissionsPanel, false);
|
|
||||||
page.setVisibleDefault(rolePermissionsForm, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showRoleDetails(final PageState state) {
|
|
||||||
rolesTablePanel.setVisible(state, false);
|
|
||||||
roleForm.setVisible(state, false);
|
|
||||||
roleDetails.setVisible(state, true);
|
|
||||||
roleMembersPanel.setVisible(state, true);
|
|
||||||
roleAddMemberForm.setVisible(state, false);
|
|
||||||
rolePermissionsPanel.setVisible(state, false);
|
|
||||||
rolePermissionsForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideRoleDetails(final PageState state) {
|
|
||||||
selectedRoleId.clearSelection(state);
|
|
||||||
|
|
||||||
rolesTablePanel.setVisible(state, true);
|
|
||||||
roleForm.setVisible(state, false);
|
|
||||||
roleDetails.setVisible(state, false);
|
|
||||||
roleMembersPanel.setVisible(state, false);
|
|
||||||
roleAddMemberForm.setVisible(state, false);
|
|
||||||
rolePermissionsPanel.setVisible(state, false);
|
|
||||||
rolePermissionsForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showRoleForm(final PageState state) {
|
|
||||||
rolesTablePanel.setVisible(state, false);
|
|
||||||
roleForm.setVisible(state, true);
|
|
||||||
roleDetails.setVisible(state, false);
|
|
||||||
roleMembersPanel.setVisible(state, false);
|
|
||||||
roleAddMemberForm.setVisible(state, false);
|
|
||||||
rolePermissionsPanel.setVisible(state, false);
|
|
||||||
rolePermissionsForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideRoleForm(final PageState state) {
|
|
||||||
//We want to show the roles table if no role is selected and the
|
|
||||||
//role details if a role is selected.
|
|
||||||
boolean roleSelected = selectedRoleId.isSelected(state);
|
|
||||||
|
|
||||||
rolesTablePanel.setVisible(state, !roleSelected);
|
|
||||||
roleForm.setVisible(state, false);
|
|
||||||
roleDetails.setVisible(state, roleSelected);
|
|
||||||
roleMembersPanel.setVisible(state, roleSelected);
|
|
||||||
roleAddMemberForm.setVisible(state, false);
|
|
||||||
rolePermissionsPanel.setVisible(state, false);
|
|
||||||
rolePermissionsForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showRoleMemberAddForm(final PageState state) {
|
|
||||||
rolesTablePanel.setVisible(state, false);
|
|
||||||
roleForm.setVisible(state, false);
|
|
||||||
roleDetails.setVisible(state, false);
|
|
||||||
roleMembersPanel.setVisible(state, false);
|
|
||||||
roleAddMemberForm.setVisible(state, true);
|
|
||||||
rolePermissionsPanel.setVisible(state, false);
|
|
||||||
rolePermissionsForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showRoleMembersPanel(final PageState state) {
|
|
||||||
rolesTablePanel.setVisible(state, false);
|
|
||||||
roleForm.setVisible(state, false);
|
|
||||||
roleDetails.setVisible(state, true);
|
|
||||||
roleMembersPanel.setVisible(state, true);
|
|
||||||
roleAddMemberForm.setVisible(state, false);
|
|
||||||
rolePermissionsPanel.setVisible(state, false);
|
|
||||||
rolePermissionsForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideRoleMemberAddForm(final PageState state) {
|
|
||||||
rolesTablePanel.setVisible(state, false);
|
|
||||||
roleForm.setVisible(state, false);
|
|
||||||
roleDetails.setVisible(state, true);
|
|
||||||
roleMembersPanel.setVisible(state, true);
|
|
||||||
roleAddMemberForm.setVisible(state, false);
|
|
||||||
rolePermissionsPanel.setVisible(state, false);
|
|
||||||
rolePermissionsForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showRolePermissionsPanel(final PageState state) {
|
|
||||||
rolesTablePanel.setVisible(state, false);
|
|
||||||
roleForm.setVisible(state, false);
|
|
||||||
roleDetails.setVisible(state, true);
|
|
||||||
roleMembersPanel.setVisible(state, false);
|
|
||||||
roleAddMemberForm.setVisible(state, false);
|
|
||||||
rolePermissionsPanel.setVisible(state, true);
|
|
||||||
rolePermissionsForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// protected void hideRolePermissionsPanel(final PageState state) {
|
|
||||||
// rolesTablePanel.setVisible(state, false);
|
|
||||||
// roleForm.setVisible(state, false);
|
|
||||||
// roleDetails.setVisible(state, true);
|
|
||||||
// roleMembersPanel.setVisible(state, true);
|
|
||||||
// roleAddMemberForm.setVisible(state, false);
|
|
||||||
// rolePermissionsPanel.setVisible(state, false);
|
|
||||||
// }
|
|
||||||
protected void showRolePermissionAddForm(final PageState state) {
|
|
||||||
rolesTablePanel.setVisible(state, false);
|
|
||||||
roleForm.setVisible(state, false);
|
|
||||||
roleDetails.setVisible(state, false);
|
|
||||||
roleMembersPanel.setVisible(state, false);
|
|
||||||
roleAddMemberForm.setVisible(state, false);
|
|
||||||
rolePermissionsPanel.setVisible(state, false);
|
|
||||||
rolePermissionsForm.setVisible(state, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideRolePermissionAddForm(final PageState state) {
|
|
||||||
rolesTablePanel.setVisible(state, false);
|
|
||||||
roleForm.setVisible(state, false);
|
|
||||||
roleDetails.setVisible(state, true);
|
|
||||||
roleMembersPanel.setVisible(state, false);
|
|
||||||
roleAddMemberForm.setVisible(state, false);
|
|
||||||
rolePermissionsPanel.setVisible(state, true);
|
|
||||||
rolePermissionsForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,105 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.roles;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows the properties of a role including the members of the role.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class RoleDetails extends BoxPanel {
|
|
||||||
|
|
||||||
public RoleDetails(
|
|
||||||
final RoleAdmin roleAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId) {
|
|
||||||
|
|
||||||
super(BoxPanel.VERTICAL);
|
|
||||||
|
|
||||||
final ActionLink backLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.back", ADMIN_BUNDLE));
|
|
||||||
backLink.setClassAttr("back-link");
|
|
||||||
backLink.addActionListener(event -> {
|
|
||||||
roleAdmin.hideRoleDetails(event.getPageState());
|
|
||||||
});
|
|
||||||
super.add(backLink);
|
|
||||||
|
|
||||||
final Label heading = new Label();
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
heading.addPrintListener(event -> {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final Label target = (Label) event.getTarget();
|
|
||||||
final RoleRepository roleRepository = CdiUtil
|
|
||||||
.createCdiUtil()
|
|
||||||
.findBean(RoleRepository.class);
|
|
||||||
final Role role = roleRepository
|
|
||||||
.findById(Long.parseLong(selectedRoleId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.heading",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{role.getName()}));
|
|
||||||
});
|
|
||||||
super.add(heading);
|
|
||||||
|
|
||||||
final PropertySheet propertySheet = new PropertySheet(
|
|
||||||
new RolePropertySheetModelBuilder(selectedRoleId));
|
|
||||||
super.add(propertySheet);
|
|
||||||
|
|
||||||
final BoxPanel links = new BoxPanel(BoxPanel.HORIZONTAL);
|
|
||||||
|
|
||||||
final ActionLink editProperties = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.edit_properties", ADMIN_BUNDLE));
|
|
||||||
editProperties.addActionListener(event -> {
|
|
||||||
roleAdmin.showRoleForm(event.getPageState());
|
|
||||||
});
|
|
||||||
links.add(editProperties);
|
|
||||||
|
|
||||||
final ActionLink manageMembers = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.manage_members", ADMIN_BUNDLE));
|
|
||||||
manageMembers.addActionListener(event -> {
|
|
||||||
roleAdmin.showRoleMembersPanel(event.getPageState());
|
|
||||||
});
|
|
||||||
links.add(manageMembers);
|
|
||||||
|
|
||||||
|
|
||||||
final ActionLink managePermissions = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.manage_permissions", ADMIN_BUNDLE));
|
|
||||||
managePermissions.addActionListener(event -> {
|
|
||||||
roleAdmin.showRolePermissionsPanel(event.getPageState());
|
|
||||||
});
|
|
||||||
links.add(managePermissions);
|
|
||||||
|
|
||||||
super.add(links);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,168 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.roles;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form for creating new roles and editing existing roles. If a role
|
|
||||||
* is selected the form is populated with the values of an existing role. When
|
|
||||||
* the form is submitted either a new role is created or an existing group
|
|
||||||
* is updated.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class RoleForm extends Form {
|
|
||||||
|
|
||||||
private static final String ROLE_NAME = "rolename";
|
|
||||||
|
|
||||||
private final TextField roleName;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public RoleForm(
|
|
||||||
final RoleAdmin roleAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId) {
|
|
||||||
|
|
||||||
super("roleform");
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final String selectedRoleIdStr = selectedRoleId.getSelectedKey(
|
|
||||||
state);
|
|
||||||
if (selectedRoleIdStr == null || selectedRoleIdStr.isEmpty()) {
|
|
||||||
target.setLabel(
|
|
||||||
new GlobalizedMessage("ui.admin.role.create_new",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
} else {
|
|
||||||
target.setLabel(new GlobalizedMessage("ui.admin.role.edit",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
roleName = new TextField(ROLE_NAME);
|
|
||||||
roleName.setLabel(new GlobalizedMessage("ui.admin.role_name",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
add(roleName);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String roleNameData = data.getString(ROLE_NAME);
|
|
||||||
|
|
||||||
if (roleNameData == null || roleNameData.isEmpty()) {
|
|
||||||
data.addError(ROLE_NAME, new GlobalizedMessage(
|
|
||||||
"ui.admin.role.name.error.notempty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (roleNameData.length() > 256) {
|
|
||||||
data.addError(ROLE_NAME, new GlobalizedMessage(
|
|
||||||
"ui.admin.role.name.error.length",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final RoleRepository roleRepository = cdiUtil.findBean(
|
|
||||||
RoleRepository.class);
|
|
||||||
final Optional<Role> role = roleRepository.findByName(roleNameData);
|
|
||||||
if (role.isPresent()) {
|
|
||||||
data.addError(ROLE_NAME, new GlobalizedMessage(
|
|
||||||
"ui.admin.role.error.name_already_in_use",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addInitListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final String selectedRoleIdStr = selectedRoleId
|
|
||||||
.getSelectedKey(state);
|
|
||||||
|
|
||||||
if (selectedRoleIdStr != null && !selectedRoleIdStr.isEmpty()) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final RoleRepository roleRepository = cdiUtil.findBean(
|
|
||||||
RoleRepository.class);
|
|
||||||
|
|
||||||
final Role role = roleRepository.findById(Long.parseLong(
|
|
||||||
selectedRoleIdStr)).get();
|
|
||||||
roleName.setValue(state, role.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
final String roleNameData = data.getString(ROLE_NAME);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final RoleRepository roleRepository = cdiUtil.findBean(
|
|
||||||
RoleRepository.class);
|
|
||||||
|
|
||||||
final String selectedRoleIdStr = selectedRoleId.getSelectedKey(
|
|
||||||
state);
|
|
||||||
if (selectedRoleIdStr == null || selectedRoleIdStr.isEmpty()) {
|
|
||||||
final Role role = new Role();
|
|
||||||
role.setName(roleNameData);
|
|
||||||
|
|
||||||
roleRepository.save(role);
|
|
||||||
} else {
|
|
||||||
final Role role = roleRepository.findById(Long.parseLong(
|
|
||||||
selectedRoleIdStr)).get();
|
|
||||||
role.setName(roleNameData);
|
|
||||||
|
|
||||||
roleRepository.save(role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
roleAdmin.hideRoleForm(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,240 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.roles;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
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.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Group;
|
|
||||||
import org.libreccm.security.Party;
|
|
||||||
import org.libreccm.security.PartyRepository;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleManager;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table showing all members (users or groups) of a role.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class RoleMembersTable extends Table {
|
|
||||||
|
|
||||||
private static final int COL_MEMBER_NAME = 0;
|
|
||||||
private static final int COL_MEMBER_TYPE = 1;
|
|
||||||
private static final int COL_MEMBER_REMOVE = 2;
|
|
||||||
|
|
||||||
public RoleMembersTable(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
setIdAttr("roleMembersTable");
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.none", ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_NAME,
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.role_members.name",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_TYPE,
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.role_members.type",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_MEMBER_REMOVE,
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.role_members.remove",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_MEMBER_REMOVE).setCellRenderer(
|
|
||||||
new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.remove_member.confirm",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final String key = (String) event.getRowKey();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_MEMBER_REMOVE:
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final PartyRepository partyRepository = cdiUtil
|
|
||||||
.findBean(PartyRepository.class);
|
|
||||||
final RoleRepository roleRepository = cdiUtil.findBean(
|
|
||||||
RoleRepository.class);
|
|
||||||
final RoleManager roleManager = cdiUtil.findBean(
|
|
||||||
RoleManager.class);
|
|
||||||
final Party party = partyRepository.findById(Long
|
|
||||||
.parseLong(key)).get();
|
|
||||||
final Role role = roleRepository.findById(
|
|
||||||
Long.parseLong(selectedRoleId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
roleManager.removeRoleFromParty(role, party);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Invalid value for column");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new RoleMembersTableModelBuilder(selectedRoleId));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RoleMembersTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedRoleId;
|
|
||||||
|
|
||||||
public RoleMembersTableModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId) {
|
|
||||||
|
|
||||||
this.selectedRoleId = selectedRoleId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new RoleMembersTableModel(selectedRoleId, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RoleMembersTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final List<Party> members;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public RoleMembersTableModel(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId,
|
|
||||||
final PageState state) {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final RoleRepository roleRepository = cdiUtil
|
|
||||||
.findBean(RoleRepository.class);
|
|
||||||
final Role role = roleRepository.findById(Long.parseLong(
|
|
||||||
selectedRoleId.getSelectedKey(state))).get();
|
|
||||||
//
|
|
||||||
// members = new ArrayList<>();
|
|
||||||
//
|
|
||||||
// role.getMemberships().forEach(m -> {
|
|
||||||
// members.add(m.getMember());
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// members.sort((m1, m2) -> {
|
|
||||||
// return m1.getName().compareTo(m2.getName());
|
|
||||||
// });
|
|
||||||
|
|
||||||
final RolesController controller = cdiUtil
|
|
||||||
.findBean(RolesController.class);
|
|
||||||
members = controller.getMembersOfRole(role);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < members.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
final Party member = members.get(index);
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_MEMBER_NAME:
|
|
||||||
return member.getName();
|
|
||||||
case COL_MEMBER_TYPE:
|
|
||||||
if (member instanceof User) {
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.type.user",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
} else if (member instanceof Group) {
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.type.group",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
} else {
|
|
||||||
return "?";
|
|
||||||
}
|
|
||||||
case COL_MEMBER_REMOVE:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_members.remove", ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return members.get(index).getPartyId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,193 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.roles;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.core.CcmObject;
|
|
||||||
import org.libreccm.core.CcmObjectRepository;
|
|
||||||
import org.libreccm.security.PermissionManager;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A basic form for add permissions to role. Usually the applications should
|
|
||||||
* provide better and more comfortable forms for editing their specific
|
|
||||||
* permissions. This form is provided to give the administrator the possibility
|
|
||||||
* to manage permissions in a generic way.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class RolePermissionsForm extends Form {
|
|
||||||
|
|
||||||
private static final String OBJECT_ID = "objectId";
|
|
||||||
private static final String PRIVILEGE = "privilege";
|
|
||||||
|
|
||||||
private final TextField objectId;
|
|
||||||
private final TextField privilege;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public RolePermissionsForm(
|
|
||||||
final RoleAdmin roleAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId) {
|
|
||||||
|
|
||||||
super("rolePermissionsForm");
|
|
||||||
|
|
||||||
final ActionLink backToRole = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.group_details.add_permission.back",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
backToRole.addActionListener(e -> {
|
|
||||||
roleAdmin.showRolePermissionsPanel(e.getPageState());
|
|
||||||
});
|
|
||||||
add(backToRole);
|
|
||||||
|
|
||||||
final Label heading = new Label();
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
heading.addPrintListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final RoleRepository roleRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(RoleRepository.class);
|
|
||||||
final Role role = roleRepository.findById(Long.parseLong(
|
|
||||||
selectedRoleId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.add_permission.heading",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{role.getName()}));
|
|
||||||
});
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
objectId = new TextField(OBJECT_ID);
|
|
||||||
objectId.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.add_permission.object_id.label",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
objectId.setHint(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.add_permission.object_id.hint",
|
|
||||||
ADMIN_BUNDLE
|
|
||||||
));
|
|
||||||
add(objectId);
|
|
||||||
|
|
||||||
privilege = new TextField(PRIVILEGE);
|
|
||||||
privilege.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.add_permission.privilege.label",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
privilege.setHint(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.add_permission.privilege.hint",
|
|
||||||
ADMIN_BUNDLE
|
|
||||||
));
|
|
||||||
add(privilege);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addValidationListener(event -> {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = event.getFormData();
|
|
||||||
|
|
||||||
final String privilegeData = data.getString(PRIVILEGE);
|
|
||||||
if (privilegeData == null || privilegeData.isEmpty()) {
|
|
||||||
data.addError(PRIVILEGE, new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.add_permission."
|
|
||||||
+ "privilege.error.notempty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
final String objectIdData = data.getString(OBJECT_ID);
|
|
||||||
if (objectIdData != null && !objectIdData.isEmpty()) {
|
|
||||||
final CcmObjectRepository objectRepository = CdiUtil
|
|
||||||
.createCdiUtil().findBean(CcmObjectRepository.class);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Long.parseLong(objectIdData);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
data.addError(
|
|
||||||
OBJECT_ID,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.add_permission.object_id"
|
|
||||||
+ ".error.nan",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Optional<CcmObject> object = objectRepository.
|
|
||||||
findObjectById(
|
|
||||||
Long.parseLong(objectIdData));
|
|
||||||
if (!object.isPresent()) {
|
|
||||||
data.addError(
|
|
||||||
OBJECT_ID,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.role_details.add_permission.object_id"
|
|
||||||
+ ".error.no_object",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(event -> {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = event.getFormData();
|
|
||||||
|
|
||||||
final String privilegeData = data.getString(PRIVILEGE);
|
|
||||||
final String objectIdData = data.getString(OBJECT_ID);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final RoleRepository roleRepository = cdiUtil.findBean(
|
|
||||||
RoleRepository.class);
|
|
||||||
|
|
||||||
final Role role = roleRepository.findById(Long.parseLong(
|
|
||||||
selectedRoleId.getSelectedKey(state))).get();
|
|
||||||
final PermissionManager permissionManager = cdiUtil.findBean(
|
|
||||||
PermissionManager.class);
|
|
||||||
if (objectIdData == null || objectIdData.isEmpty()) {
|
|
||||||
permissionManager.grantPrivilege(privilegeData, role);
|
|
||||||
} else {
|
|
||||||
final CcmObjectRepository objectRepository = cdiUtil
|
|
||||||
.findBean(CcmObjectRepository.class);
|
|
||||||
final Optional<CcmObject> object = objectRepository
|
|
||||||
.findObjectById(Long.parseLong(objectIdData));
|
|
||||||
permissionManager.grantPrivilege(privilegeData,
|
|
||||||
role,
|
|
||||||
object.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
roleAdmin.showRolePermissionsPanel(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,244 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.roles;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
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.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.core.CcmObject;
|
|
||||||
import org.libreccm.security.Permission;
|
|
||||||
import org.libreccm.security.PermissionManager;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table displaying all permissions granted to a role.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class RolePermissionsTable extends Table {
|
|
||||||
|
|
||||||
private static final int COL_PRIVILEGE = 0;
|
|
||||||
private static final int COL_ON_OBJECT = 1;
|
|
||||||
private static final int COL_REVOKE = 2;
|
|
||||||
|
|
||||||
public RolePermissionsTable(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
setIdAttr("rolePermissionsTable");
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_permissions.none", ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_PRIVILEGE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_permissions.privilege", ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_ON_OBJECT,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_permissions.on_object", ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_REVOKE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_permissions.revoke", ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_REVOKE).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_permissions.revoke.confirm", ADMIN_BUNDLE));
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final String key = (String) event.getRowKey();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_REVOKE:
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final RoleRepository roleRepository = cdiUtil.findBean(
|
|
||||||
RoleRepository.class);
|
|
||||||
final PermissionManager permissionManager = cdiUtil
|
|
||||||
.findBean(PermissionManager.class);
|
|
||||||
final Role role = roleRepository.findById(
|
|
||||||
Long.parseLong(selectedRoleId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
final Permission permission = permissionManager
|
|
||||||
.findById(Long.parseLong(key)).get();
|
|
||||||
if (permission.getObject() == null) {
|
|
||||||
permissionManager.revokePrivilege(
|
|
||||||
permission.getGrantedPrivilege(), role);
|
|
||||||
} else {
|
|
||||||
permissionManager.revokePrivilege(
|
|
||||||
permission.getGrantedPrivilege(),
|
|
||||||
role,
|
|
||||||
permission.getObject());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Invalid value for column");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new RolePermissionsTableModelBuilder(selectedRoleId));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RolePermissionsTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedRoleId;
|
|
||||||
|
|
||||||
public RolePermissionsTableModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId) {
|
|
||||||
|
|
||||||
this.selectedRoleId = selectedRoleId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new RolePermissionsTableModel(selectedRoleId, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RolePermissionsTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final List<Permission> permissions;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public RolePermissionsTableModel(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId,
|
|
||||||
final PageState state) {
|
|
||||||
|
|
||||||
final RoleRepository roleRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(RoleRepository.class);
|
|
||||||
final Role role = roleRepository.findById(
|
|
||||||
Long.parseLong(selectedRoleId.getSelectedKey(state)),
|
|
||||||
Role.ENTITY_GRPAH_WITH_PERMISSIONS).get();
|
|
||||||
|
|
||||||
permissions = new ArrayList<>(role.getPermissions());
|
|
||||||
|
|
||||||
permissions.sort((p1, p2) -> {
|
|
||||||
final int result = p1.getGrantedPrivilege()
|
|
||||||
.compareTo(p2.getGrantedPrivilege());
|
|
||||||
if (result != 0) {
|
|
||||||
return result;
|
|
||||||
} else if (p1.getObject() != null
|
|
||||||
&& p1.getObject().getDisplayName() != null
|
|
||||||
&& p2.getObject() != null
|
|
||||||
&& p2.getObject().getDisplayName() != null) {
|
|
||||||
return p1.getObject().getDisplayName()
|
|
||||||
.compareTo(p2.getObject().getDisplayName());
|
|
||||||
} else {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < permissions.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
final Permission permission = permissions.get(index);
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_PRIVILEGE:
|
|
||||||
return permission.getGrantedPrivilege();
|
|
||||||
case COL_ON_OBJECT:
|
|
||||||
if (permission.getObject() == null) {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
final CcmObject object = permission.getObject();
|
|
||||||
return String.join(" ",
|
|
||||||
Long.toString(object.getObjectId()),
|
|
||||||
object.getDisplayName());
|
|
||||||
}
|
|
||||||
case COL_REVOKE:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.role_permissions.revoke", ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return permissions.get(index).getPermissionId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,98 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.roles;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The model for the property sheet of a role. The {@link RoleProperty}
|
|
||||||
* enum contains all properties which are shown in the property sheet. The
|
|
||||||
* {@link #nextRow()} method iterates over these properties and sets the
|
|
||||||
* value {@link #currentProperty} field. The {@link #getValue()} method
|
|
||||||
* returns the value for the {@code currentProperty}.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class RolePropertySheetModel implements PropertySheetModel {
|
|
||||||
|
|
||||||
private static enum RoleProperty {
|
|
||||||
ROLE_NAME
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Role selectedRole;
|
|
||||||
private final Iterator<RoleProperty> propertyIterator;
|
|
||||||
private RoleProperty currentProperty;
|
|
||||||
|
|
||||||
public RolePropertySheetModel(final Role selectedRole) {
|
|
||||||
this.selectedRole = selectedRole;
|
|
||||||
propertyIterator = Arrays.asList(RoleProperty.values()).iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
if (selectedRole == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propertyIterator.hasNext()) {
|
|
||||||
currentProperty = propertyIterator.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLabel() {
|
|
||||||
return currentProperty.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GlobalizedMessage getGlobalizedLabel() {
|
|
||||||
return generateGlobalizedLabel(currentProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
private GlobalizedMessage generateGlobalizedLabel(
|
|
||||||
final RoleProperty roleProperty) {
|
|
||||||
|
|
||||||
final String key = String.join("",
|
|
||||||
"ui.admin.role.property_sheet.",
|
|
||||||
roleProperty.toString().toLowerCase());
|
|
||||||
return new GlobalizedMessage(key, ADMIN_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
switch(currentProperty) {
|
|
||||||
case ROLE_NAME:
|
|
||||||
return selectedRole.getName();
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.roles;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model builder for the {@link RolePropertySheetModel}.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class RolePropertySheetModelBuilder extends LockableImpl
|
|
||||||
implements PropertySheetModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedRoleId;
|
|
||||||
|
|
||||||
public RolePropertySheetModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId) {
|
|
||||||
this.selectedRoleId = selectedRoleId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertySheetModel makeModel(final PropertySheet sheet,
|
|
||||||
final PageState state) {
|
|
||||||
final String roleIdStr = selectedRoleId.getSelectedKey(state);
|
|
||||||
final Role selectedRole;
|
|
||||||
if (roleIdStr == null || roleIdStr.isEmpty()) {
|
|
||||||
selectedRole = null;
|
|
||||||
} else {
|
|
||||||
final RoleRepository roleRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(RoleRepository.class);
|
|
||||||
selectedRole = roleRepository.findById(Long.parseLong(roleIdStr))
|
|
||||||
.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new RolePropertySheetModel(selectedRole);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,90 +0,0 @@
|
||||||
package com.arsdigita.ui.admin.usersgroupsroles.roles;
|
|
||||||
|
|
||||||
import org.libreccm.security.Party;
|
|
||||||
import org.libreccm.security.PartyRepository;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleManager;
|
|
||||||
import org.libreccm.security.RoleMembership;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
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 RolesController implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 4127664283856716723L;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private PartyRepository partyRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private RoleRepository roleRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private RoleManager roleManager;
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected List<Party> getMembersOfRole(final Role role) {
|
|
||||||
|
|
||||||
final Role theRole = roleRepo
|
|
||||||
.findById(role.getRoleId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Role with ID %d in the database.",
|
|
||||||
role.getRoleId())));
|
|
||||||
|
|
||||||
return theRole
|
|
||||||
.getMemberships()
|
|
||||||
.stream()
|
|
||||||
.map(RoleMembership::getMember)
|
|
||||||
.sorted((role1, role2) -> role1.getName().compareTo(role2.getName()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected List<String> getNamesOfMembersOfRole(final Role role) {
|
|
||||||
|
|
||||||
final Role theRole = roleRepo
|
|
||||||
.findById(role.getRoleId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Role with ID %d in the database.",
|
|
||||||
role.getRoleId())));
|
|
||||||
|
|
||||||
return theRole
|
|
||||||
.getMemberships()
|
|
||||||
.stream()
|
|
||||||
.map(RoleMembership::getMember)
|
|
||||||
.map(Party::getName)
|
|
||||||
.sorted((name1, name2) -> name1.compareTo(name2))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected void assignRoleToParty(final Role role, final Party party) {
|
|
||||||
|
|
||||||
final Party assignee = partyRepo
|
|
||||||
.findById(party.getPartyId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Party with ID %d in the database.",
|
|
||||||
party.getPartyId())));
|
|
||||||
|
|
||||||
final Role assignTo = roleRepo
|
|
||||||
.findById(role.getRoleId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Role with ID %d in the database.",
|
|
||||||
role.getRoleId())));
|
|
||||||
|
|
||||||
roleManager.assignRoleToParty(assignTo, assignee);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,215 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.roles;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
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.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filterable table showing all roles.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class RolesTable extends Table {
|
|
||||||
|
|
||||||
private static final int COL_ROLE_NAME = 0;
|
|
||||||
private static final int COL_DELETE = 1;
|
|
||||||
|
|
||||||
private final TextField rolesTableFilter;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedRoleId;
|
|
||||||
|
|
||||||
public RolesTable(
|
|
||||||
final RoleAdmin parent,
|
|
||||||
final TextField rolesTableFilter,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedRoleId) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
setIdAttr("rolesTable");
|
|
||||||
setStyleAttr("width: 30em");
|
|
||||||
|
|
||||||
this.rolesTableFilter = rolesTableFilter;
|
|
||||||
this.selectedRoleId = selectedRoleId;
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.roles.table.empty", ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_ROLE_NAME,
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.roles.table.name",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DELETE,
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.roles.table.delete",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_ROLE_NAME).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
return new ControlLink((String) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
columnModel.get(COL_DELETE).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.roles.delete.confirm", ADMIN_BUNDLE));
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final String key = (String) event.getRowKey();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_ROLE_NAME:
|
|
||||||
selectedRoleId.setSelectedKey(state, key);
|
|
||||||
parent.showRoleDetails(state);
|
|
||||||
break;
|
|
||||||
case COL_DELETE:
|
|
||||||
final RoleRepository roleRepository = CdiUtil
|
|
||||||
.createCdiUtil().findBean(RoleRepository.class);
|
|
||||||
final Role role = roleRepository.findById(Long
|
|
||||||
.parseLong(key)).get();
|
|
||||||
roleRepository.delete(role);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Invalid value for column.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new RolesTableModelBuilder());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RolesTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new RolesTableModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RolesTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final List<Role> roles;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public RolesTableModel(final PageState state) {
|
|
||||||
final String filterTerm = (String) rolesTableFilter.getValue(state);
|
|
||||||
final RoleRepository roleRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(RoleRepository.class);
|
|
||||||
if (filterTerm == null || filterTerm.isEmpty()) {
|
|
||||||
roles = roleRepository.findAllOrderedByRoleName();
|
|
||||||
} else {
|
|
||||||
roles = roleRepository.searchByName(filterTerm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < roles.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
final Role role = roles.get(index);
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_ROLE_NAME:
|
|
||||||
return role.getName();
|
|
||||||
case COL_DELETE:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.roles.table.delete", ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return roles.get(index).getRoleId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.ChallengeManager;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
import javax.mail.MessagingException;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A panel contains several action links used in the {@link UserDetails}
|
|
||||||
* component.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class ActionLinks extends BoxPanel {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(ActionLinks.class);
|
|
||||||
|
|
||||||
public ActionLinks(final UserAdmin userAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
|
|
||||||
super(BoxPanel.HORIZONTAL);
|
|
||||||
|
|
||||||
setIdAttr("userDetailsActionLinks");
|
|
||||||
|
|
||||||
final ActionLink editUserDetailsLink = new ActionLink(
|
|
||||||
new GlobalizedMessage("ui.admin.user_details.edit", ADMIN_BUNDLE));
|
|
||||||
editUserDetailsLink.addActionListener(e -> {
|
|
||||||
userAdmin.showUserEditForm(e.getPageState());
|
|
||||||
});
|
|
||||||
add(editUserDetailsLink);
|
|
||||||
add(new Text(" | "));
|
|
||||||
|
|
||||||
final ActionLink setPasswordLink = new ActionLink(
|
|
||||||
new GlobalizedMessage("ui.admin.user_details.set_password",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
setPasswordLink.addActionListener(e -> {
|
|
||||||
userAdmin.showPasswordSetForm(e.getPageState());
|
|
||||||
});
|
|
||||||
add(setPasswordLink);
|
|
||||||
add(new Text(" | "));
|
|
||||||
|
|
||||||
final ActionLink generatePasswordLink = new ActionLink(
|
|
||||||
new GlobalizedMessage("ui.admin.user_details.generate_password",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
generatePasswordLink.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.user_details.generate_password.confirm",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
generatePasswordLink.addActionListener(e -> {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UserRepository userRepository = cdiUtil.findBean(
|
|
||||||
UserRepository.class);
|
|
||||||
final User user = userRepository.findById(Long.parseLong(
|
|
||||||
selectedUserId.getSelectedKey(e.getPageState()))).get();
|
|
||||||
final ChallengeManager challengeManager = cdiUtil.findBean(
|
|
||||||
ChallengeManager.class);
|
|
||||||
try {
|
|
||||||
challengeManager.sendPasswordRecover(user);
|
|
||||||
} catch (MessagingException ex) {
|
|
||||||
LOGGER.error("Failed to send email to user.", ex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
add(generatePasswordLink);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,202 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.CheckboxGroup;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.core.EmailAddress;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form for editing and adding email addresses to a user.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class EmailForm extends Form {
|
|
||||||
|
|
||||||
private static final String ADDRESS = "address";
|
|
||||||
private static final String VERIFIED = "verified";
|
|
||||||
private static final String BOUNCING = "bouncing";
|
|
||||||
|
|
||||||
private final TextField address;
|
|
||||||
private final CheckboxGroup verified;
|
|
||||||
private final CheckboxGroup bouncing;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public EmailForm(
|
|
||||||
final UserAdmin userAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedEmailAddress) {
|
|
||||||
|
|
||||||
super("email_form");
|
|
||||||
|
|
||||||
address = new TextField(ADDRESS);
|
|
||||||
address.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_form.address", ADMIN_BUNDLE));
|
|
||||||
add(address);
|
|
||||||
|
|
||||||
verified = new CheckboxGroup(VERIFIED);
|
|
||||||
verified.addOption(
|
|
||||||
new Option("true",
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_form.verified",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
add(verified);
|
|
||||||
|
|
||||||
bouncing = new CheckboxGroup(BOUNCING);
|
|
||||||
bouncing.addOption(
|
|
||||||
new Option("true",
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_form.bouncing",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
add(bouncing);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addInitListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final String selected = selectedEmailAddress.getSelectedKey(state);
|
|
||||||
final String userIdStr = selectedUserId.getSelectedKey(state);
|
|
||||||
if (selected != null && !selected.isEmpty()) {
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final User user = userRepository.findById(Long.parseLong(
|
|
||||||
userIdStr)).get();
|
|
||||||
EmailAddress email = null;
|
|
||||||
if (user.getPrimaryEmailAddress().getAddress().equals(selected)) {
|
|
||||||
email = user.getPrimaryEmailAddress();
|
|
||||||
} else {
|
|
||||||
for (EmailAddress current : user.getEmailAddresses()) {
|
|
||||||
if (current.getAddress().equals(selected)) {
|
|
||||||
email = current;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (email != null) {
|
|
||||||
address.setValue(state, email.getAddress());
|
|
||||||
if (email.isVerified()) {
|
|
||||||
verified.setValue(state, "true");
|
|
||||||
}
|
|
||||||
if (email.isBouncing()) {
|
|
||||||
bouncing.setValue(state, "true");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String addressData = data.getString(ADDRESS);
|
|
||||||
|
|
||||||
if (Strings.isEmpty(addressData)) {
|
|
||||||
data.addError(ADDRESS, new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_form.address.not_empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String selected = selectedEmailAddress.getSelectedKey(
|
|
||||||
state);
|
|
||||||
final String userIdStr = selectedUserId.getSelectedKey(state);
|
|
||||||
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final User user = userRepository.findById(Long.parseLong(
|
|
||||||
userIdStr)).get();
|
|
||||||
EmailAddress email = null;
|
|
||||||
if (selected == null) {
|
|
||||||
email = new EmailAddress();
|
|
||||||
user.addEmailAddress(email);
|
|
||||||
} else if (user.getPrimaryEmailAddress().getAddress().equals(
|
|
||||||
selected)) {
|
|
||||||
email = user.getPrimaryEmailAddress();
|
|
||||||
} else {
|
|
||||||
for (EmailAddress current : user.getEmailAddresses()) {
|
|
||||||
if (current.getAddress().equals(selected)) {
|
|
||||||
email = current;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (email != null) {
|
|
||||||
email.setAddress(data.getString(ADDRESS));
|
|
||||||
|
|
||||||
final String[] verifiedValues = (String[]) data
|
|
||||||
.get(VERIFIED);
|
|
||||||
if (verifiedValues != null && verifiedValues.length > 0) {
|
|
||||||
if ("true".equals(verifiedValues[0])) {
|
|
||||||
email.setVerified(true);
|
|
||||||
} else {
|
|
||||||
email.setVerified(false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
email.setVerified(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
final String[] bouncingValues = (String[]) data
|
|
||||||
.get(BOUNCING);
|
|
||||||
if (bouncingValues != null && bouncingValues.length > 0) {
|
|
||||||
if ("true".equals(bouncingValues[0])) {
|
|
||||||
email.setBouncing(true);
|
|
||||||
} else {
|
|
||||||
email.setBouncing(false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
email.setBouncing(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
userRepository.save(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
userAdmin.closeEmailForm(e.getPageState());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,166 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
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.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.core.EmailAddress;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table showing the additional email addresses associated with a user.
|
|
||||||
* Please note that the additional email addresses property will maybe removed.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class EmailTable extends Table {
|
|
||||||
|
|
||||||
public EmailTable(
|
|
||||||
final UserAdmin userAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedEmailAddress) {
|
|
||||||
|
|
||||||
setModelBuilder(
|
|
||||||
new EmailTableModelBuilder(selectedUserId));
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
EmailTableModel.COL_ADDRESS,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_addresses.address",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
EmailTableModel.COL_VERIFIED,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_addresses.verified",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
EmailTableModel.COL_BOUNCING,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_addresses.bouncing",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
EmailTableModel.COL_EDIT,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_addresses.edit",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
EmailTableModel.COL_DELETE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_addresses.delete",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.get(EmailTableModel.COL_EDIT).setCellRenderer(
|
|
||||||
new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
return new ControlLink((Component) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
columnModel.get(EmailTableModel.COL_DELETE)
|
|
||||||
.setCellRenderer(
|
|
||||||
new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
if (column == EmailTableModel.COL_DELETE) {
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_addresses.delete.confirm",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
final String key = (String) event.getRowKey();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case EmailTableModel.COL_EDIT:
|
|
||||||
selectedEmailAddress.setSelectedKey(state, key);
|
|
||||||
userAdmin.showEmailForm(state);
|
|
||||||
break;
|
|
||||||
case EmailTableModel.COL_DELETE:
|
|
||||||
final String userIdStr = selectedUserId.getSelectedKey(
|
|
||||||
state);
|
|
||||||
final UserRepository userRepository = CdiUtil
|
|
||||||
.createCdiUtil().findBean(UserRepository.class);
|
|
||||||
final User user = userRepository.findById(Long
|
|
||||||
.parseLong(userIdStr)).get();
|
|
||||||
EmailAddress email = null;
|
|
||||||
for (EmailAddress current : user.getEmailAddresses()) {
|
|
||||||
if (current.getAddress().equals(key)) {
|
|
||||||
email = current;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (email != null) {
|
|
||||||
user.removeEmailAddress(email);
|
|
||||||
userRepository.save(user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_addresses.none", ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,101 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.core.EmailAddress;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model for the {@link EmailTable}.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class EmailTableModel implements TableModel {
|
|
||||||
|
|
||||||
protected static final int COL_ADDRESS = 0;
|
|
||||||
protected static final int COL_VERIFIED = 1;
|
|
||||||
protected static final int COL_BOUNCING = 2;
|
|
||||||
protected static final int COL_EDIT = 3;
|
|
||||||
protected static final int COL_DELETE = 4;
|
|
||||||
|
|
||||||
private final List<EmailAddress> emailAddresses;
|
|
||||||
private int index = -1;
|
|
||||||
private boolean finished;
|
|
||||||
|
|
||||||
public EmailTableModel(final User user) {
|
|
||||||
this.emailAddresses = user.getEmailAddresses();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
if (emailAddresses == null || emailAddresses.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// if (index < emailAddresses.size()) {
|
|
||||||
// index++;
|
|
||||||
// return true;
|
|
||||||
// } else {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
index++;
|
|
||||||
return index < emailAddresses.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_ADDRESS:
|
|
||||||
return emailAddresses.get(index).getAddress();
|
|
||||||
case COL_VERIFIED:
|
|
||||||
return Boolean.toString(emailAddresses.get(index).isVerified());
|
|
||||||
case COL_BOUNCING:
|
|
||||||
return Boolean.toString(emailAddresses.get(index).isBouncing());
|
|
||||||
case COL_EDIT:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_addresses.edit",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
case COL_DELETE:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_addresses.delete",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Invalid column index.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return emailAddresses.get(index).getAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model builder for the {@link EmailTableModel}.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class EmailTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedUserId;
|
|
||||||
|
|
||||||
public EmailTableModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
this.selectedUserId = selectedUserId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table, final PageState state) {
|
|
||||||
final String userIdStr = selectedUserId.getSelectedKey(state);
|
|
||||||
final User selectedUser;
|
|
||||||
if (userIdStr == null || userIdStr.isEmpty()) {
|
|
||||||
selectedUser = null;
|
|
||||||
} else {
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final long userId = Long.parseLong(userIdStr);
|
|
||||||
selectedUser = userRepository.findById(userId).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new EmailTableModel(selectedUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,209 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.form.CheckboxGroup;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Group;
|
|
||||||
import org.libreccm.security.GroupManager;
|
|
||||||
import org.libreccm.security.GroupRepository;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.TooManyListenersException;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form for editing the group memberships of a user.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class GroupMembershipsForm extends Form {
|
|
||||||
|
|
||||||
private static final String GROUPS_SELECTOR = "groupsselector";
|
|
||||||
|
|
||||||
private final CheckboxGroup groups;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public GroupMembershipsForm(
|
|
||||||
final UserAdmin userAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
|
|
||||||
super("edit-usergroupmemberships-form");
|
|
||||||
|
|
||||||
final BoxPanel links = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final String userIdStr = selectedUserId.getSelectedKey(state);
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final User user = userRepository.findById(Long.parseLong(userIdStr))
|
|
||||||
.get();
|
|
||||||
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.edit_group_memberships",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{user.getName()}));
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
links.add(heading);
|
|
||||||
|
|
||||||
final ActionLink backLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.edit_group_memberships.back_to_user_details",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
backLink.addActionListener(e -> {
|
|
||||||
userAdmin.closeEditGroupMembershipsForm(e.getPageState());
|
|
||||||
});
|
|
||||||
links.add(backLink);
|
|
||||||
|
|
||||||
add(links);
|
|
||||||
|
|
||||||
groups = new CheckboxGroup(GROUPS_SELECTOR);
|
|
||||||
try {
|
|
||||||
groups.addPrintListener(e -> {
|
|
||||||
final CheckboxGroup target = (CheckboxGroup) e.getTarget();
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final GroupRepository groupRepository = cdiUtil.findBean(
|
|
||||||
GroupRepository.class);
|
|
||||||
|
|
||||||
target.clearOptions();
|
|
||||||
|
|
||||||
final SortedSet<Group> allGroups = new TreeSet<>(
|
|
||||||
(g1, g2) -> {
|
|
||||||
return g1.getName().compareTo(g2.getName());
|
|
||||||
});
|
|
||||||
allGroups.addAll(groupRepository.findAll());
|
|
||||||
|
|
||||||
allGroups.forEach(g -> {
|
|
||||||
final Option option = new Option(
|
|
||||||
Long.toString(g.getPartyId()), new Text(g.getName()));
|
|
||||||
target.addOption(option);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (TooManyListenersException ex) {
|
|
||||||
//This should never happen, and if its happens something is
|
|
||||||
//seriously wrong...
|
|
||||||
throw new UncheckedWrapperException(ex);
|
|
||||||
}
|
|
||||||
add(groups);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addInitListener(e -> {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UserRepository userRepository = cdiUtil.findBean(
|
|
||||||
UserRepository.class);
|
|
||||||
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final User user = userRepository.findById(Long.parseLong(
|
|
||||||
selectedUserId.getSelectedKey(state))).get();
|
|
||||||
final List<Group> assignedGroups = new ArrayList<>();
|
|
||||||
user.getGroupMemberships().forEach(m -> {
|
|
||||||
assignedGroups.add(m.getGroup());
|
|
||||||
});
|
|
||||||
|
|
||||||
final String[] selectedGroups = new String[assignedGroups.size()];
|
|
||||||
IntStream.range(0, assignedGroups.size()).forEach(i -> {
|
|
||||||
selectedGroups[i] = Long.toString(assignedGroups.get(i)
|
|
||||||
.getPartyId());
|
|
||||||
});
|
|
||||||
|
|
||||||
groups.setValue(state, selectedGroups);
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UserRepository userRepository = cdiUtil.findBean(
|
|
||||||
UserRepository.class);
|
|
||||||
final GroupRepository groupRepository = cdiUtil.findBean(
|
|
||||||
GroupRepository.class);
|
|
||||||
final GroupManager groupManager = cdiUtil.findBean(
|
|
||||||
GroupManager.class);
|
|
||||||
|
|
||||||
final String[] selectedGroupIds = (String[]) data.get(
|
|
||||||
GROUPS_SELECTOR);
|
|
||||||
|
|
||||||
final User user = userRepository.findById(Long.parseLong(
|
|
||||||
selectedUserId.getSelectedKey(state))).get();
|
|
||||||
final List<Group> selectedGroups = new ArrayList<>();
|
|
||||||
if (selectedGroupIds != null) {
|
|
||||||
Arrays.stream(selectedGroupIds).forEach(id -> {
|
|
||||||
final Group group = groupRepository.findById(
|
|
||||||
Long.parseLong(id)).get();
|
|
||||||
selectedGroups.add(group);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
final List<Group> assignedGroups = new ArrayList<>();
|
|
||||||
user.getGroupMemberships().forEach(m -> {
|
|
||||||
assignedGroups.add(m.getGroup());
|
|
||||||
});
|
|
||||||
|
|
||||||
//First check for newly added groups
|
|
||||||
selectedGroups.forEach(g -> {
|
|
||||||
if (!assignedGroups.contains(g)) {
|
|
||||||
groupManager.addMemberToGroup(user, g);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Than check for removed groups
|
|
||||||
assignedGroups.forEach(g -> {
|
|
||||||
if (!selectedGroups.contains(g)) {
|
|
||||||
//The group is maybe detached or not fully loaded,
|
|
||||||
//therefore we load the group from the database.
|
|
||||||
final Group group = groupRepository.findById(
|
|
||||||
g.getPartyId()).get();
|
|
||||||
groupManager.removeMemberFromGroup(user, group);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
userAdmin.closeEditGroupMembershipsForm(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,109 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table showing the roles and groups of a user. The table has three rows. The
|
|
||||||
* first one show the groups to which the user is assigned. The second row
|
|
||||||
* shows all roles to which are <strong>directly</strong> assigned to a user.
|
|
||||||
* The third row shows all roles which are assigned to the user, either directly
|
|
||||||
* or via one of the groups the user is assigned to.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class GroupsRolesTable extends Table {
|
|
||||||
|
|
||||||
public GroupsRolesTable(
|
|
||||||
final UserAdmin userAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
|
|
||||||
setModelBuilder(new GroupsRolesTableModelBuilder(
|
|
||||||
selectedUserId));
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
GroupsRolesTableModel.COL_LABEL));
|
|
||||||
columnModel
|
|
||||||
.add(new TableColumn(GroupsRolesTableModel.COL_VALUE));
|
|
||||||
columnModel.add(
|
|
||||||
new TableColumn(GroupsRolesTableModel.COL_ACTION));
|
|
||||||
columnModel.get(GroupsRolesTableModel.COL_ACTION)
|
|
||||||
.setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
switch (row) {
|
|
||||||
case GroupsRolesTableModel.ROW_GROUPS: {
|
|
||||||
return new ControlLink((Component) value);
|
|
||||||
}
|
|
||||||
case GroupsRolesTableModel.ROW_ROLES: {
|
|
||||||
return new ControlLink((Component) value);
|
|
||||||
}
|
|
||||||
case GroupsRolesTableModel.ROW_ALL_ROLES:
|
|
||||||
return new Text("");
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final int selectedRow = Integer.parseInt((String) event
|
|
||||||
.getRowKey());
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
switch (selectedRow) {
|
|
||||||
case GroupsRolesTableModel.ROW_GROUPS:
|
|
||||||
userAdmin.showEditGroupMembershipsForm(state);
|
|
||||||
break;
|
|
||||||
case GroupsRolesTableModel.ROW_ROLES:
|
|
||||||
userAdmin.showEditRoleMembershipsForm(state);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,147 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model for the {@link GroupsRolesTable}.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class GroupsRolesTableModel implements TableModel {
|
|
||||||
|
|
||||||
protected static final int COL_LABEL = 0;
|
|
||||||
protected static final int COL_VALUE = 1;
|
|
||||||
protected static final int COL_ACTION = 2;
|
|
||||||
|
|
||||||
protected static final int ROW_GROUPS = 0;
|
|
||||||
protected static final int ROW_ROLES = 1;
|
|
||||||
protected static final int ROW_ALL_ROLES = 2;
|
|
||||||
|
|
||||||
private int row = -1;
|
|
||||||
|
|
||||||
private final User user;
|
|
||||||
|
|
||||||
public GroupsRolesTableModel(final User user) {
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
row++;
|
|
||||||
return row < 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
switch (row) {
|
|
||||||
case ROW_GROUPS:
|
|
||||||
return buildGroupRow(columnIndex);
|
|
||||||
case ROW_ROLES:
|
|
||||||
return buildRolesRow(columnIndex);
|
|
||||||
case ROW_ALL_ROLES:
|
|
||||||
return buildAllRolesRow(columnIndex);
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object buildGroupRow(final int columnIndex) {
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_LABEL:
|
|
||||||
return new Label(new GlobalizedMessage("ui.admin.user.groups",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
case COL_VALUE: {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UsersController controller = cdiUtil
|
|
||||||
.findBean(UsersController.class);
|
|
||||||
|
|
||||||
return controller.getNamesOfAssignedGroups(user);
|
|
||||||
}
|
|
||||||
case COL_ACTION:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.groups.edit", ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object buildRolesRow(final int columnIndex) {
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_LABEL:
|
|
||||||
return new Label(new GlobalizedMessage("ui.admin.user.roles",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
case COL_VALUE: {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UsersController controller = cdiUtil
|
|
||||||
.findBean(UsersController.class);
|
|
||||||
|
|
||||||
return controller.getNamesOfAssignedGroups(user);
|
|
||||||
}
|
|
||||||
case COL_ACTION:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.roles.edit", ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object buildAllRolesRow(final int columnIndex) {
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_LABEL:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.all_roles", ADMIN_BUNDLE));
|
|
||||||
case COL_VALUE: {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UsersController controller = cdiUtil
|
|
||||||
.findBean(UsersController.class);
|
|
||||||
|
|
||||||
return controller.getNamesOfAllAssignedRoles(user);
|
|
||||||
}
|
|
||||||
case COL_ACTION:
|
|
||||||
return "";
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model builder for the {@link GroupsRolesTableModel}.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class GroupsRolesTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder{
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedUserId;
|
|
||||||
|
|
||||||
public GroupsRolesTableModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
this.selectedUserId = selectedUserId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table, final PageState state) {
|
|
||||||
final String userIdStr = selectedUserId.getSelectedKey(state);
|
|
||||||
final User selectedUser ;
|
|
||||||
if (userIdStr == null || userIdStr.isEmpty()) {
|
|
||||||
selectedUser = null;
|
|
||||||
} else {
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final long userId = Long.parseLong(userIdStr);
|
|
||||||
selectedUser = userRepository.findById(userId).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new GroupsRolesTableModel(selectedUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,316 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.Password;
|
|
||||||
import com.arsdigita.bebop.form.RadioGroup;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.ChallengeManager;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserManager;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
import javax.mail.MessagingException;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form for creating new users.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class NewUserForm extends Form {
|
|
||||||
|
|
||||||
private static final String USER_NAME = "userName";
|
|
||||||
private static final String FAMILY_NAME = "familyName";
|
|
||||||
private static final String GIVEN_NAME = "givenName";
|
|
||||||
private static final String EMAIL = "email";
|
|
||||||
private static final String PASSWORD_OPTIONS = "passwordOptions";
|
|
||||||
private static final String PASSWORD_OPTION_SET = "passwordOptionSet";
|
|
||||||
private static final String PASSWORD_OPTION_SEND = "passwordOptionSend";
|
|
||||||
private static final String PASSWORD = "password";
|
|
||||||
private static final String PASSWORD_CONFIRMATION = "passwordConfirmation";
|
|
||||||
|
|
||||||
private final TextField userName;
|
|
||||||
private final TextField familyName;
|
|
||||||
private final TextField givenName;
|
|
||||||
private final TextField email;
|
|
||||||
private final RadioGroup passwordOptionsGroup;
|
|
||||||
private final Password password;
|
|
||||||
private final Password passwordConfirmation;
|
|
||||||
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public NewUserForm(
|
|
||||||
final UserAdmin userAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
|
|
||||||
super("new_user_form");
|
|
||||||
|
|
||||||
userName = new TextField(USER_NAME);
|
|
||||||
userName.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.username.label", ADMIN_BUNDLE));
|
|
||||||
userName.setSize(32);
|
|
||||||
userName.setMaxLength(32);
|
|
||||||
add(userName);
|
|
||||||
|
|
||||||
familyName = new TextField(FAMILY_NAME);
|
|
||||||
familyName.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.familyname.label", ADMIN_BUNDLE));
|
|
||||||
familyName.setSize(32);
|
|
||||||
familyName.setMaxLength(256);
|
|
||||||
add(familyName);
|
|
||||||
|
|
||||||
givenName = new TextField(GIVEN_NAME);
|
|
||||||
givenName.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.givenname.label", ADMIN_BUNDLE));
|
|
||||||
givenName.setSize(32);
|
|
||||||
givenName.setMaxLength(256);
|
|
||||||
add(givenName);
|
|
||||||
|
|
||||||
email = new TextField(EMAIL);
|
|
||||||
email.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.email.label", ADMIN_BUNDLE));
|
|
||||||
email.setSize(48);
|
|
||||||
email.setMaxLength(256);
|
|
||||||
add(email);
|
|
||||||
|
|
||||||
passwordOptionsGroup = new RadioGroup(PASSWORD_OPTIONS);
|
|
||||||
final Option sendPasswordOption = new Option(
|
|
||||||
PASSWORD_OPTION_SEND,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.password_options.send_password.label",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
passwordOptionsGroup.addOption(sendPasswordOption);
|
|
||||||
final Option setPasswordOption = new Option(
|
|
||||||
PASSWORD_OPTION_SET,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.password_options.set_password",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
passwordOptionsGroup.addOption(setPasswordOption);
|
|
||||||
add(passwordOptionsGroup);
|
|
||||||
|
|
||||||
password = new Password(PASSWORD);
|
|
||||||
password.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.password_options.set_password.password.label",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
password.setMaxLength(256);
|
|
||||||
password.setSize(32);
|
|
||||||
add(password);
|
|
||||||
|
|
||||||
passwordConfirmation = new Password(PASSWORD_CONFIRMATION);
|
|
||||||
passwordConfirmation.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.password_options."
|
|
||||||
+ "set_password.password_confirmation.label",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
passwordConfirmation.setMaxLength(256);
|
|
||||||
passwordConfirmation.setSize(32);
|
|
||||||
add(passwordConfirmation);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String userNameData = data.getString(USER_NAME);
|
|
||||||
final String familyNameData = data.getString(FAMILY_NAME);
|
|
||||||
final String givenNameData = data.getString(GIVEN_NAME);
|
|
||||||
final String emailData = data.getString(EMAIL);
|
|
||||||
|
|
||||||
if (Strings.isBlank(userNameData)) {
|
|
||||||
data.addError(
|
|
||||||
USER_NAME,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.username.is_empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
if (userNameData != null && userNameData.length() > 32) {
|
|
||||||
data.addError(
|
|
||||||
USER_NAME,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.username.too_long",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Strings.isBlank(familyNameData)) {
|
|
||||||
data.addError(
|
|
||||||
FAMILY_NAME,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.familyname.is_empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
if (familyNameData != null && familyNameData.length() > 256) {
|
|
||||||
data.addError(
|
|
||||||
FAMILY_NAME,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.familyname.too_long",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Strings.isBlank(givenNameData)) {
|
|
||||||
data.addError(
|
|
||||||
GIVEN_NAME,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.givenname.is_empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
if (givenNameData != null && givenNameData.length() > 256) {
|
|
||||||
data.addError(
|
|
||||||
GIVEN_NAME,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.givenname.too_long",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Strings.isBlank(emailData)) {
|
|
||||||
data.addError(
|
|
||||||
EMAIL,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.email.is_empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
if (emailData != null && emailData.length() > 256) {
|
|
||||||
data.addError(
|
|
||||||
EMAIL,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.email.too_long",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
final String selectedPasswordOption = data.getString(
|
|
||||||
PASSWORD_OPTIONS);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UserRepository userRepository = cdiUtil.findBean(
|
|
||||||
UserRepository.class);
|
|
||||||
|
|
||||||
if (userRepository.findByName(userNameData) != null) {
|
|
||||||
data.addError(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.username_already_in_use",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userRepository.findByEmailAddress(emailData) != null) {
|
|
||||||
data.addError(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.email_already_in_use",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PASSWORD_OPTION_SET.equals(selectedPasswordOption)) {
|
|
||||||
final String passwordData = data.getString(PASSWORD);
|
|
||||||
final String passwordConfirmData = data.getString(
|
|
||||||
PASSWORD_CONFIRMATION);
|
|
||||||
|
|
||||||
if (Strings.isBlank(passwordData)) {
|
|
||||||
data.addError(
|
|
||||||
PASSWORD,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.password.is_empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Strings.isBlank(passwordConfirmData)) {
|
|
||||||
data.addError(
|
|
||||||
PASSWORD_CONFIRMATION,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.password.is_empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!passwordData.equals(passwordConfirmData)) {
|
|
||||||
data.addError(
|
|
||||||
PASSWORD,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.password_do_not_match",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UserManager userManager = cdiUtil.findBean(
|
|
||||||
UserManager.class);
|
|
||||||
|
|
||||||
final String dataUserName = data.getString(USER_NAME);
|
|
||||||
final String dataFamilyName = data.getString(FAMILY_NAME);
|
|
||||||
final String dataGivenName = data.getString(GIVEN_NAME);
|
|
||||||
final String dataEmail = data.getString(EMAIL);
|
|
||||||
final String dataSelectedPasswordOption = data.getString(
|
|
||||||
PASSWORD_OPTIONS);
|
|
||||||
|
|
||||||
final String dataPassword;
|
|
||||||
if (PASSWORD_OPTION_SET.equals(dataSelectedPasswordOption)) {
|
|
||||||
dataPassword = data.getString(PASSWORD);
|
|
||||||
} else {
|
|
||||||
dataPassword = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final User user = userManager.createUser(dataGivenName,
|
|
||||||
dataFamilyName,
|
|
||||||
dataUserName,
|
|
||||||
dataEmail,
|
|
||||||
dataPassword);
|
|
||||||
|
|
||||||
if (PASSWORD_OPTION_SEND.equals(dataSelectedPasswordOption)) {
|
|
||||||
final ChallengeManager challengeManager = cdiUtil.findBean(
|
|
||||||
ChallengeManager.class);
|
|
||||||
|
|
||||||
try {
|
|
||||||
challengeManager.sendPasswordRecover(user);
|
|
||||||
} catch (MessagingException ex) {
|
|
||||||
throw new FormProcessException(
|
|
||||||
"Failed to send password challenge to new user.",
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user_form.error.failed_to_send_password",
|
|
||||||
ADMIN_BUNDLE),
|
|
||||||
ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
userAdmin.closeNewUserForm(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,128 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.Password;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserManager;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form for setting the password of a user.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class PasswordSetForm extends Form {
|
|
||||||
|
|
||||||
private static final String NEW_PASSWORD = "new_password";
|
|
||||||
private static final String PASSWORD_CONFIRM = "password_confirm";
|
|
||||||
|
|
||||||
private final Password newPassword;
|
|
||||||
private final Password passwordConfirm;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public PasswordSetForm(
|
|
||||||
final UserAdmin userAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
|
|
||||||
super("password_set_form");
|
|
||||||
|
|
||||||
newPassword = new Password(NEW_PASSWORD);
|
|
||||||
newPassword.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.user_set_password.new_password.label", ADMIN_BUNDLE));
|
|
||||||
add(newPassword);
|
|
||||||
|
|
||||||
passwordConfirm = new Password(PASSWORD_CONFIRM);
|
|
||||||
passwordConfirm.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.user_set_password.confirm_password.label",
|
|
||||||
ADMIN_BUNDLE
|
|
||||||
));
|
|
||||||
add(passwordConfirm);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String passwordData = data.getString(NEW_PASSWORD);
|
|
||||||
final String confirmData = data.getString(PASSWORD_CONFIRM);
|
|
||||||
|
|
||||||
if (Strings.isEmpty(passwordData)) {
|
|
||||||
data.addError(
|
|
||||||
NEW_PASSWORD,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.set_password.new_password.error.not_empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Strings.isEmpty(confirmData)) {
|
|
||||||
data.addError(
|
|
||||||
PASSWORD_CONFIRM,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.set_password.password_confirm.error.not_empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!passwordData.equals(confirmData)) {
|
|
||||||
data.addError(new GlobalizedMessage(
|
|
||||||
"ui.admin.user_set_password.error.do_not_match",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final String userIdStr = selectedUserId.getSelectedKey(state);
|
|
||||||
final String password = (String) newPassword.getValue(state);
|
|
||||||
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final User user = userRepository.findById(Long.parseLong(
|
|
||||||
userIdStr)).get();
|
|
||||||
|
|
||||||
final UserManager userManager = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(
|
|
||||||
UserManager.class);
|
|
||||||
userManager.updatePassword(user, password);
|
|
||||||
}
|
|
||||||
userAdmin.closePasswordSetForm(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
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.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table showing the primary email of an user.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class PrimaryEmailTable extends Table {
|
|
||||||
|
|
||||||
public PrimaryEmailTable(
|
|
||||||
final UserAdmin userAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedEmailAddress) {
|
|
||||||
|
|
||||||
setModelBuilder(new PrimaryEmailTableModelBuilder(selectedUserId));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
PrimaryEmailTableModel.COL_ADDRESS,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.primary_email.address",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
PrimaryEmailTableModel.COL_VERIFIED,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.primary_email.verified",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
PrimaryEmailTableModel.COL_BOUNCING,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.primary_email.bouncing",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
PrimaryEmailTableModel.COL_ACTION,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.primary_email.action",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.get(
|
|
||||||
PrimaryEmailTableModel.COL_ACTION).setCellRenderer(
|
|
||||||
new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
return new ControlLink((Component) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final String key = (String) event.getRowKey();
|
|
||||||
selectedEmailAddress.setSelectedKey(event.getPageState(), key);
|
|
||||||
userAdmin.showEmailForm(event.getPageState());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model for the {@link PrimaryEmailTable}.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class PrimaryEmailTableModel implements TableModel {
|
|
||||||
|
|
||||||
protected static final int COL_ADDRESS = 0;
|
|
||||||
protected static final int COL_VERIFIED = 1;
|
|
||||||
protected static final int COL_BOUNCING = 2;
|
|
||||||
protected static final int COL_ACTION = 3;
|
|
||||||
|
|
||||||
private final User user;
|
|
||||||
private boolean finished = false;
|
|
||||||
|
|
||||||
public PrimaryEmailTableModel(final User user) {
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
if (finished) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
finished = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
switch(columnIndex) {
|
|
||||||
case COL_ADDRESS:
|
|
||||||
return user.getPrimaryEmailAddress().getAddress();
|
|
||||||
case COL_VERIFIED:
|
|
||||||
return Boolean.toString(user.getPrimaryEmailAddress().isVerified());
|
|
||||||
case COL_BOUNCING:
|
|
||||||
return Boolean.toString(user.getPrimaryEmailAddress().isBouncing());
|
|
||||||
case COL_ACTION:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.primary_email_address.edit", ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Invalid column index.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return user.getPrimaryEmailAddress().getAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model builder for the {@link PrimaryEmailTableModel}.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class PrimaryEmailTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedUserId;
|
|
||||||
|
|
||||||
public PrimaryEmailTableModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
this.selectedUserId = selectedUserId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table, final PageState state) {
|
|
||||||
final String userIdStr = selectedUserId.getSelectedKey(state);
|
|
||||||
final User selectedUser;
|
|
||||||
if (userIdStr == null || userIdStr.isEmpty()) {
|
|
||||||
selectedUser = null;
|
|
||||||
} else {
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final long userId = Long.parseLong(userIdStr);
|
|
||||||
selectedUser = userRepository.findById(userId).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new PrimaryEmailTableModel(selectedUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,221 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.form.CheckboxGroup;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleManager;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.TooManyListenersException;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form for editing the role memberships of a user.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class RoleMembershipsForm extends Form {
|
|
||||||
|
|
||||||
private static final String ROLES_SELECTOR = "rolesselector";
|
|
||||||
|
|
||||||
private final CheckboxGroup roles;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public RoleMembershipsForm(
|
|
||||||
final UserAdmin userAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
|
|
||||||
super("edit-userrolesmemberships-form");
|
|
||||||
|
|
||||||
final BoxPanel links = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final String userIdStr = selectedUserId.getSelectedKey(state);
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final User user = userRepository.findById(Long.parseLong(userIdStr))
|
|
||||||
.get();
|
|
||||||
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.user_edit_role_memberships",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{user.getName()}));
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
links.add(heading);
|
|
||||||
|
|
||||||
final ActionLink backLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.edit_role_memberships.back_to_user_details",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
backLink.addActionListener(e -> {
|
|
||||||
userAdmin.closeEditRoleMembershipsForm(e.getPageState());
|
|
||||||
});
|
|
||||||
links.add(backLink);
|
|
||||||
|
|
||||||
add(links);
|
|
||||||
|
|
||||||
roles = new CheckboxGroup(ROLES_SELECTOR);
|
|
||||||
try {
|
|
||||||
roles.addPrintListener(e -> {
|
|
||||||
final CheckboxGroup target = (CheckboxGroup) e.getTarget();
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
|
|
||||||
final RoleRepository roleRepository = cdiUtil.findBean(
|
|
||||||
RoleRepository.class);
|
|
||||||
|
|
||||||
target.clearOptions();
|
|
||||||
|
|
||||||
final SortedSet<Role> allRoles = new TreeSet<>(
|
|
||||||
(r1, r2) -> {
|
|
||||||
return r1.getName().compareTo(r2.getName());
|
|
||||||
});
|
|
||||||
allRoles.addAll(roleRepository.findAll());
|
|
||||||
|
|
||||||
allRoles.forEach(r -> {
|
|
||||||
final Option option = new Option(Long.toString(
|
|
||||||
r.getRoleId()), new Text(r.getName()));
|
|
||||||
target.addOption(option);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (TooManyListenersException ex) {
|
|
||||||
//This should never happen, and if its happens something is
|
|
||||||
//seriously wrong...
|
|
||||||
throw new UncheckedWrapperException(ex);
|
|
||||||
}
|
|
||||||
add(roles);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addInitListener(event -> {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UserRepository userRepository = cdiUtil
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final UsersController controller = cdiUtil
|
|
||||||
.findBean(UsersController.class);
|
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
final User user = userRepository
|
|
||||||
.findById(Long.parseLong(selectedUserId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
final List<Role> assignedRoles = controller
|
|
||||||
.getAssignedRoles(user);
|
|
||||||
|
|
||||||
final String[] selectedRoles = new String[assignedRoles.size()];
|
|
||||||
IntStream.range(0, assignedRoles.size()).forEach(i -> {
|
|
||||||
selectedRoles[i] = Long.toString(assignedRoles.get(i)
|
|
||||||
.getRoleId());
|
|
||||||
});
|
|
||||||
|
|
||||||
roles.setValue(state, selectedRoles);
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(event -> {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
|
|
||||||
final FormData data = event.getFormData();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final UserRepository userRepository = cdiUtil
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final RoleRepository roleRepository = cdiUtil
|
|
||||||
.findBean(RoleRepository.class);
|
|
||||||
final RoleManager roleManager = cdiUtil
|
|
||||||
.findBean(RoleManager.class);
|
|
||||||
final UsersController controller = cdiUtil
|
|
||||||
.findBean(UsersController.class);
|
|
||||||
|
|
||||||
final String[] selectedRolesIds = (String[]) data
|
|
||||||
.get(ROLES_SELECTOR);
|
|
||||||
|
|
||||||
final User user = userRepository
|
|
||||||
.findById(Long
|
|
||||||
.parseLong(selectedUserId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
final List<Role> selectedRoles = new ArrayList<>();
|
|
||||||
if (selectedRolesIds != null) {
|
|
||||||
Arrays
|
|
||||||
.stream(selectedRolesIds)
|
|
||||||
.forEach(id -> {
|
|
||||||
final Role role = roleRepository
|
|
||||||
.findById(Long.parseLong(id))
|
|
||||||
.get();
|
|
||||||
selectedRoles.add(role);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
controller.updateAssignedRoles(user, selectedRoles);
|
|
||||||
|
|
||||||
// final List<Role> assignedRoles = controller
|
|
||||||
// .getAssignedRoles(user);
|
|
||||||
//
|
|
||||||
// //First check for newly added roles
|
|
||||||
// selectedRoles.forEach(role -> {
|
|
||||||
// if (!assignedRoles.contains(role)) {
|
|
||||||
// roleManager.assignRoleToParty(role, user);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// //Than check for removed roles
|
|
||||||
// assignedRoles.forEach(role -> {
|
|
||||||
// if (!selectedRoles.contains(role)) {
|
|
||||||
// //Role is maybe detached or not fully loaded,
|
|
||||||
// //therefore we load the role from the database.
|
|
||||||
// final Role roleToRemove = roleRepository
|
|
||||||
// .findById(role.getRoleId())
|
|
||||||
// .get();
|
|
||||||
// roleManager.removeRoleFromParty(roleToRemove, user);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
|
|
||||||
userAdmin.closeEditRoleMembershipsForm(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,263 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* UI for managing users.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class UserAdmin extends BoxPanel {
|
|
||||||
|
|
||||||
private final StringParameter userIdParameter;
|
|
||||||
private final StringParameter emailParameter;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedUserId;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedEmailAddress;
|
|
||||||
private final UsersTablePanel usersTablePanel;
|
|
||||||
private final UserEditForm userEditForm;
|
|
||||||
private final PasswordSetForm passwordSetForm;
|
|
||||||
private final UserDetails userDetails;
|
|
||||||
private final EmailForm emailForm;
|
|
||||||
private final GroupMembershipsForm groupMembershipsForm;
|
|
||||||
private final RoleMembershipsForm editRoleMembershipsForm;
|
|
||||||
private final NewUserForm newUserForm;
|
|
||||||
|
|
||||||
public UserAdmin() {
|
|
||||||
super(BoxPanel.VERTICAL);
|
|
||||||
|
|
||||||
setBasicProperties();
|
|
||||||
userIdParameter = new StringParameter("selected_user_id");
|
|
||||||
selectedUserId = new ParameterSingleSelectionModel<>(userIdParameter);
|
|
||||||
|
|
||||||
emailParameter = new StringParameter("selected_email_address");
|
|
||||||
selectedEmailAddress = new ParameterSingleSelectionModel<>(
|
|
||||||
emailParameter);
|
|
||||||
|
|
||||||
usersTablePanel = new UsersTablePanel(this, selectedUserId);
|
|
||||||
add(usersTablePanel);
|
|
||||||
|
|
||||||
userDetails = new UserDetails(this,
|
|
||||||
selectedUserId,
|
|
||||||
selectedEmailAddress);
|
|
||||||
|
|
||||||
userEditForm = new UserEditForm(this, selectedUserId);
|
|
||||||
add(userEditForm);
|
|
||||||
|
|
||||||
passwordSetForm = new PasswordSetForm(this, selectedUserId);
|
|
||||||
add(passwordSetForm);
|
|
||||||
|
|
||||||
emailForm = new EmailForm(this, selectedUserId, selectedEmailAddress);
|
|
||||||
add(emailForm);
|
|
||||||
|
|
||||||
add(userDetails);
|
|
||||||
|
|
||||||
groupMembershipsForm = new GroupMembershipsForm(this,
|
|
||||||
selectedUserId);
|
|
||||||
add(groupMembershipsForm);
|
|
||||||
|
|
||||||
editRoleMembershipsForm = new RoleMembershipsForm(this, selectedUserId);
|
|
||||||
add(editRoleMembershipsForm);
|
|
||||||
|
|
||||||
newUserForm = new NewUserForm(this, selectedUserId);
|
|
||||||
add(newUserForm);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setBasicProperties() {
|
|
||||||
setIdAttr("userAdmin");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(final Page page) {
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
page.addGlobalStateParam(userIdParameter);
|
|
||||||
page.addGlobalStateParam(emailParameter);
|
|
||||||
|
|
||||||
page.setVisibleDefault(usersTablePanel, true);
|
|
||||||
page.setVisibleDefault(userDetails, false);
|
|
||||||
page.setVisibleDefault(userEditForm, false);
|
|
||||||
page.setVisibleDefault(passwordSetForm, false);
|
|
||||||
page.setVisibleDefault(emailForm, false);
|
|
||||||
page.setVisibleDefault(groupMembershipsForm, false);
|
|
||||||
page.setVisibleDefault(editRoleMembershipsForm, false);
|
|
||||||
page.setVisibleDefault(newUserForm, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showUserDetails(final PageState state) {
|
|
||||||
usersTablePanel.setVisible(state, false);
|
|
||||||
userDetails.setVisible(state, true);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
editRoleMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void closeUserDetails(final PageState state) {
|
|
||||||
selectedUserId.clearSelection(state);
|
|
||||||
usersTablePanel.setVisible(state, true);
|
|
||||||
userDetails.setVisible(state, false);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
editRoleMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showUserEditForm(final PageState state) {
|
|
||||||
usersTablePanel.setVisible(state, false);
|
|
||||||
userDetails.setVisible(state, false);
|
|
||||||
userEditForm.setVisible(state, true);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
editRoleMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void closeUserEditForm(final PageState state) {
|
|
||||||
usersTablePanel.setVisible(state, false);
|
|
||||||
userDetails.setVisible(state, true);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
editRoleMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showPasswordSetForm(final PageState state) {
|
|
||||||
usersTablePanel.setVisible(state, false);
|
|
||||||
userDetails.setVisible(state, false);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, true);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
editRoleMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void closePasswordSetForm(final PageState state) {
|
|
||||||
usersTablePanel.setVisible(state, false);
|
|
||||||
userDetails.setVisible(state, true);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
editRoleMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showEmailForm(final PageState state) {
|
|
||||||
usersTablePanel.setVisible(state, false);
|
|
||||||
userDetails.setVisible(state, false);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, true);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
editRoleMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void closeEmailForm(final PageState state) {
|
|
||||||
selectedEmailAddress.clearSelection(state);
|
|
||||||
usersTablePanel.setVisible(state, false);
|
|
||||||
userDetails.setVisible(state, true);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showEditGroupMembershipsForm(final PageState state) {
|
|
||||||
usersTablePanel.setVisible(state, false);
|
|
||||||
userDetails.setVisible(state, false);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, true);
|
|
||||||
editRoleMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void closeEditGroupMembershipsForm(final PageState state) {
|
|
||||||
usersTablePanel.setVisible(state, false);
|
|
||||||
userDetails.setVisible(state, true);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
editRoleMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showEditRoleMembershipsForm(final PageState state) {
|
|
||||||
usersTablePanel.setVisible(state, false);
|
|
||||||
userDetails.setVisible(state, false);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
editRoleMembershipsForm.setVisible(state, true);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void closeEditRoleMembershipsForm(final PageState state) {
|
|
||||||
usersTablePanel.setVisible(state, false);
|
|
||||||
userDetails.setVisible(state, true);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
editRoleMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showNewUserForm(final PageState state) {
|
|
||||||
usersTablePanel.setVisible(state, false);
|
|
||||||
userDetails.setVisible(state, false);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
editRoleMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void closeNewUserForm(final PageState state) {
|
|
||||||
usersTablePanel.setVisible(state, true);
|
|
||||||
userDetails.setVisible(state, false);
|
|
||||||
userEditForm.setVisible(state, false);
|
|
||||||
passwordSetForm.setVisible(state, false);
|
|
||||||
emailForm.setVisible(state, false);
|
|
||||||
groupMembershipsForm.setVisible(state, false);
|
|
||||||
editRoleMembershipsForm.setVisible(state, false);
|
|
||||||
newUserForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Displays the properties of a user.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class UserDetails extends BoxPanel {
|
|
||||||
|
|
||||||
public UserDetails(
|
|
||||||
final UserAdmin userAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedEmailAddress) {
|
|
||||||
|
|
||||||
super(BoxPanel.VERTICAL);
|
|
||||||
|
|
||||||
setIdAttr("userDetails");
|
|
||||||
|
|
||||||
final ActionLink backToUsersTable = new ActionLink(
|
|
||||||
new GlobalizedMessage("ui.admin.user_details.back", ADMIN_BUNDLE));
|
|
||||||
backToUsersTable.setIdAttr("userDetailsBackLink");
|
|
||||||
backToUsersTable.addActionListener(e -> {
|
|
||||||
userAdmin.closeUserDetails(e.getPageState());
|
|
||||||
});
|
|
||||||
add(backToUsersTable);
|
|
||||||
|
|
||||||
final PropertySheet userProperties = new PropertySheet(
|
|
||||||
new UserPropertySheetModelBuilder(selectedUserId));
|
|
||||||
userProperties.setIdAttr("userProperties");
|
|
||||||
add(userProperties);
|
|
||||||
|
|
||||||
add(new ActionLinks(userAdmin, selectedUserId));
|
|
||||||
add(new PrimaryEmailTable(userAdmin,
|
|
||||||
selectedUserId,
|
|
||||||
selectedEmailAddress));
|
|
||||||
add(new EmailTable(userAdmin, selectedUserId, selectedEmailAddress));
|
|
||||||
final ActionLink addEmailLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.user.email_addresses.add", ADMIN_BUNDLE));
|
|
||||||
addEmailLink.addActionListener(e -> {
|
|
||||||
userAdmin.showEmailForm(e.getPageState());
|
|
||||||
});
|
|
||||||
add(addEmailLink);
|
|
||||||
|
|
||||||
add(new GroupsRolesTable(userAdmin, selectedUserId));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,194 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.CheckboxGroup;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form for editing the properties of a user. There separate forms for some
|
|
||||||
* properties like the password, the group memberships or the role memberships.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class UserEditForm extends Form {
|
|
||||||
|
|
||||||
private static final String USER_NAME = "username";
|
|
||||||
private static final String FAMILY_NAME = "familyName";
|
|
||||||
private static final String BANNED = "banned";
|
|
||||||
private static final String GIVEN_NAME = "givenName";
|
|
||||||
|
|
||||||
private final TextField userName;
|
|
||||||
private final TextField familyName;
|
|
||||||
private final TextField givenName;
|
|
||||||
private final CheckboxGroup banned;
|
|
||||||
private final CheckboxGroup passwordResetRequired;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public UserEditForm(
|
|
||||||
final UserAdmin userAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
|
|
||||||
super("userEditForm");
|
|
||||||
|
|
||||||
userName = new TextField(USER_NAME);
|
|
||||||
userName.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.user_edit.username.label", ADMIN_BUNDLE));
|
|
||||||
add(userName);
|
|
||||||
|
|
||||||
familyName = new TextField(FAMILY_NAME);
|
|
||||||
familyName.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.user_edit.familyname.label", ADMIN_BUNDLE));
|
|
||||||
add(familyName);
|
|
||||||
|
|
||||||
givenName = new TextField(GIVEN_NAME);
|
|
||||||
givenName.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.user_edit.givenname.label", ADMIN_BUNDLE));
|
|
||||||
add(givenName);
|
|
||||||
|
|
||||||
banned = new CheckboxGroup(BANNED);
|
|
||||||
banned.addOption(new Option(
|
|
||||||
"banned",
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.user_edit.banned.label",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
add(banned);
|
|
||||||
|
|
||||||
passwordResetRequired = new CheckboxGroup(
|
|
||||||
"password_reset_required");
|
|
||||||
passwordResetRequired.addOption(new Option(
|
|
||||||
"password_reset_required",
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.user_edit.password_reset_required.label",
|
|
||||||
ADMIN_BUNDLE))
|
|
||||||
));
|
|
||||||
add(passwordResetRequired);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addInitListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final String userIdStr = selectedUserId.getSelectedKey(state);
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final User user = userRepository.findById(Long.parseLong(userIdStr))
|
|
||||||
.get();
|
|
||||||
|
|
||||||
userName.setValue(state, user.getName());
|
|
||||||
familyName.setValue(state, user.getFamilyName());
|
|
||||||
givenName.setValue(state, user.getGivenName());
|
|
||||||
if (user.isBanned()) {
|
|
||||||
banned.setValue(state, "banned");
|
|
||||||
}
|
|
||||||
if (user.isPasswordResetRequired()) {
|
|
||||||
passwordResetRequired.setValue(state,
|
|
||||||
"password_reset_required");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String userNameData = data.getString(USER_NAME);
|
|
||||||
if (Strings.isEmpty(userNameData)) {
|
|
||||||
data.addError(
|
|
||||||
USER_NAME,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.user_edit.username.error.not_empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
final String familyNameData = data.getString(FAMILY_NAME);
|
|
||||||
if (Strings.isEmpty(familyNameData)) {
|
|
||||||
data.addError(
|
|
||||||
FAMILY_NAME,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.user_edit.familyname.error_not_empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
final String givenNameData = data.getString(GIVEN_NAME);
|
|
||||||
if (Strings.isEmpty(givenNameData)) {
|
|
||||||
data.addError(
|
|
||||||
GIVEN_NAME,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.user_edit.givenname.error.not_empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final String userIdStr = selectedUserId.getSelectedKey(state);
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
final User user = userRepository.findById(Long.parseLong(
|
|
||||||
userIdStr)).get();
|
|
||||||
|
|
||||||
if (!user.getName().equals(userName.getValue(state))) {
|
|
||||||
user.setName((String) userName.getValue(state));
|
|
||||||
}
|
|
||||||
if (!user.getFamilyName().equals(familyName.getValue(state))) {
|
|
||||||
user.setFamilyName((String) familyName.getValue(state));
|
|
||||||
}
|
|
||||||
if (!user.getGivenName().equals(givenName.getValue(state))) {
|
|
||||||
user.setGivenName((String) familyName.getValue(state));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("banned".equals(banned.getValue(state)) && !user.isBanned()) {
|
|
||||||
user.setBanned(true);
|
|
||||||
} else {
|
|
||||||
user.setBanned(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("password_reset_required".equals(passwordResetRequired
|
|
||||||
.getValue(
|
|
||||||
state))
|
|
||||||
&& !user.isPasswordResetRequired()) {
|
|
||||||
user.setPasswordResetRequired(true);
|
|
||||||
} else {
|
|
||||||
user.setPasswordResetRequired(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
userRepository.save(user);
|
|
||||||
}
|
|
||||||
userAdmin.closeUserEditForm(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,113 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model for the user properties sheet in the {@link UserDetails}. the
|
|
||||||
* {@link UserProperty} enum contains the properties the show. The
|
|
||||||
* {@link #nextRow()} method iterators over this properties and sets the
|
|
||||||
* {@link #currentProperty} field. The {@link #getValue()} returns the value for
|
|
||||||
* the current property.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class UserPropertySheetModel implements PropertySheetModel {
|
|
||||||
|
|
||||||
private static enum UserProperty {
|
|
||||||
USER_NAME,
|
|
||||||
FAMILY_NAME,
|
|
||||||
GIVEN_NAME,
|
|
||||||
PASSWORD_SET,
|
|
||||||
BANNED,
|
|
||||||
PASSWORD_RESET_REQUIRED
|
|
||||||
}
|
|
||||||
|
|
||||||
private final User selectedUser;
|
|
||||||
private final Iterator<UserProperty> propertyIterator;
|
|
||||||
private UserProperty currentProperty;
|
|
||||||
|
|
||||||
public UserPropertySheetModel(final User selectedUser) {
|
|
||||||
this.selectedUser = selectedUser;
|
|
||||||
propertyIterator = Arrays.asList(UserProperty.values()).iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
if (selectedUser == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propertyIterator.hasNext()) {
|
|
||||||
currentProperty = propertyIterator.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLabel() {
|
|
||||||
return currentProperty.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GlobalizedMessage getGlobalizedLabel() {
|
|
||||||
return generateGlobalizedLabel(currentProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
private GlobalizedMessage generateGlobalizedLabel(
|
|
||||||
final UserProperty property) {
|
|
||||||
final String key = String.join("", "ui.admin.user.property_sheet.",
|
|
||||||
property.toString().toLowerCase());
|
|
||||||
return new GlobalizedMessage(key, ADMIN_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
switch (currentProperty) {
|
|
||||||
case USER_NAME:
|
|
||||||
return selectedUser.getName();
|
|
||||||
case FAMILY_NAME:
|
|
||||||
return selectedUser.getFamilyName();
|
|
||||||
case GIVEN_NAME:
|
|
||||||
return selectedUser.getGivenName();
|
|
||||||
case PASSWORD_SET:
|
|
||||||
return Boolean.toString(
|
|
||||||
(selectedUser.getPassword() != null
|
|
||||||
&& !selectedUser.getPassword().isEmpty()));
|
|
||||||
case BANNED:
|
|
||||||
return Boolean.toString(selectedUser.isBanned());
|
|
||||||
case PASSWORD_RESET_REQUIRED:
|
|
||||||
return Boolean.toString(selectedUser.isPasswordResetRequired());
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model builder for the {@link UserPropertySheetModelBuilder}.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class UserPropertySheetModelBuilder
|
|
||||||
extends LockableImpl implements PropertySheetModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedUserId;
|
|
||||||
|
|
||||||
public UserPropertySheetModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
this.selectedUserId = selectedUserId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertySheetModel makeModel(final PropertySheet sheet,
|
|
||||||
final PageState state) {
|
|
||||||
final String userIdStr = selectedUserId.getSelectedKey(state);
|
|
||||||
final User selectedUser;
|
|
||||||
if (userIdStr == null || userIdStr.isEmpty()) {
|
|
||||||
selectedUser = null;
|
|
||||||
} else {
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil().
|
|
||||||
findBean(UserRepository.class);
|
|
||||||
selectedUser = userRepository.findById(Long.parseLong(userIdStr))
|
|
||||||
.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new UserPropertySheetModel(selectedUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,227 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import org.libreccm.security.Group;
|
|
||||||
import org.libreccm.security.GroupMembership;
|
|
||||||
import org.libreccm.security.Party;
|
|
||||||
import org.libreccm.security.PermissionChecker;
|
|
||||||
import org.libreccm.security.Role;
|
|
||||||
import org.libreccm.security.RoleManager;
|
|
||||||
import org.libreccm.security.RoleMembership;
|
|
||||||
import org.libreccm.security.RoleRepository;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
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
|
|
||||||
class UsersController {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private UserRepository userRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private RoleRepository roleRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private RoleManager roleManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private PermissionChecker permissionChecker;
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected List<Group> getAssignedGroups(final User user) {
|
|
||||||
|
|
||||||
final User theUser = userRepo
|
|
||||||
.findById(user.getPartyId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No User with ID %d in the database.",
|
|
||||||
user.getPartyId())));
|
|
||||||
|
|
||||||
return theUser
|
|
||||||
.getGroupMemberships()
|
|
||||||
.stream()
|
|
||||||
.map(GroupMembership::getGroup)
|
|
||||||
.sorted((group1, group2) -> {
|
|
||||||
return group1.getName().compareTo(group2.getName());
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected String getNamesOfAssignedGroups(final User user) {
|
|
||||||
|
|
||||||
final User theUser = userRepo
|
|
||||||
.findById(user.getPartyId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No User with ID %d in the database.",
|
|
||||||
user.getPartyId())));
|
|
||||||
|
|
||||||
return theUser
|
|
||||||
.getGroupMemberships()
|
|
||||||
.stream()
|
|
||||||
.map(GroupMembership::getGroup)
|
|
||||||
.map(Group::getName)
|
|
||||||
.sorted((name1, name2) -> name1.compareTo(name2))
|
|
||||||
.collect(Collectors.joining(", "));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected List<Role> getAssignedRoles(final User user) {
|
|
||||||
|
|
||||||
final User theUser = userRepo
|
|
||||||
.findById(user.getPartyId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No User with ID %d in the database.",
|
|
||||||
user.getPartyId())));
|
|
||||||
|
|
||||||
return theUser
|
|
||||||
.getRoleMemberships()
|
|
||||||
.stream()
|
|
||||||
.map(RoleMembership::getRole)
|
|
||||||
.sorted((role1, role2) -> {
|
|
||||||
return role1.getName().compareTo(role2.getName());
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected String getNamesOfAssignedRoles(final User user) {
|
|
||||||
|
|
||||||
final User theUser = userRepo
|
|
||||||
.findById(user.getPartyId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No User with ID %d in the database.",
|
|
||||||
user.getPartyId())));
|
|
||||||
|
|
||||||
return theUser
|
|
||||||
.getRoleMemberships()
|
|
||||||
.stream()
|
|
||||||
.map(RoleMembership::getRole)
|
|
||||||
.map(Role::getName)
|
|
||||||
.sorted((name1, name2) -> name1.compareTo(name2))
|
|
||||||
.collect(Collectors.joining(", "));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected String getNamesOfAllAssignedRoles(final User user) {
|
|
||||||
|
|
||||||
final User theUser = userRepo
|
|
||||||
.findById(user.getPartyId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No User with ID %d in the database.",
|
|
||||||
user.getPartyId())));
|
|
||||||
|
|
||||||
final Set<Role> rolesFromGroups = new HashSet<>();
|
|
||||||
theUser
|
|
||||||
.getGroupMemberships()
|
|
||||||
.stream()
|
|
||||||
.map(GroupMembership::getGroup)
|
|
||||||
.forEach(group -> {
|
|
||||||
group
|
|
||||||
.getRoleMemberships()
|
|
||||||
.stream()
|
|
||||||
.map(RoleMembership::getRole)
|
|
||||||
.forEach(role -> rolesFromGroups.add(role));
|
|
||||||
});
|
|
||||||
|
|
||||||
return Stream.concat(
|
|
||||||
theUser
|
|
||||||
.getRoleMemberships()
|
|
||||||
.stream()
|
|
||||||
.map(RoleMembership::getRole)
|
|
||||||
.map(Role::getName),
|
|
||||||
rolesFromGroups
|
|
||||||
.stream()
|
|
||||||
.map(Role::getName)
|
|
||||||
.sorted((name1, name2) -> name1.compareTo(name2)))
|
|
||||||
.collect(Collectors.joining(", "));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected void updateAssignedRoles(final User user,
|
|
||||||
final List<Role> selectedRoles) {
|
|
||||||
|
|
||||||
final User theUser = userRepo
|
|
||||||
.findById(user.getPartyId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No User with ID %d in the database.",
|
|
||||||
user.getPartyId())));
|
|
||||||
|
|
||||||
final List<Role> assignedRoles = getAssignedRoles(user);
|
|
||||||
final List<Long> assignedRolesIds = getAssignedRoles(user)
|
|
||||||
.stream()
|
|
||||||
.map(Role::getRoleId)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
final List<Long> selectedRolesIds = selectedRoles
|
|
||||||
.stream()
|
|
||||||
.map(Role::getRoleId)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
//First check for newly added role
|
|
||||||
selectedRoles
|
|
||||||
.stream()
|
|
||||||
.filter(role -> !assignedRolesIds.contains(role.getRoleId()))
|
|
||||||
.forEach(role -> assignRoleToParty(role, theUser));
|
|
||||||
|
|
||||||
assignedRoles
|
|
||||||
.stream()
|
|
||||||
.filter(role -> !selectedRolesIds.contains(role.getRoleId()))
|
|
||||||
.forEach(role -> removeRoleFromParty(role, theUser));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assignRoleToParty(final Role role, final Party party) {
|
|
||||||
|
|
||||||
final Role roleToAdd = roleRepo
|
|
||||||
.findById(role.getRoleId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Role with ID %d in the database.",
|
|
||||||
role.getRoleId())));
|
|
||||||
|
|
||||||
roleManager.assignRoleToParty(roleToAdd, party);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeRoleFromParty(final Role role, final Party party) {
|
|
||||||
|
|
||||||
final Role roleToRemove = roleRepo
|
|
||||||
.findById(role.getRoleId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Role with ID %d in the database.",
|
|
||||||
role.getRoleId())));
|
|
||||||
|
|
||||||
roleManager.removeRoleFromParty(roleToRemove, party);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,223 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
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.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.security.User;
|
|
||||||
import org.libreccm.security.UserRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A filterable table showing all users.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class UsersTable extends Table {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(UsersTable.class);
|
|
||||||
|
|
||||||
private static final int COL_SCREEN_NAME = 0;
|
|
||||||
private static final int COL_GIVEN_NAME = 1;
|
|
||||||
private static final int COL_FAMILY_NAME = 2;
|
|
||||||
private static final int COL_PRIMARY_EMAIL = 3;
|
|
||||||
private static final int COL_BANNED = 4;
|
|
||||||
|
|
||||||
private final TextField usersTableFilter;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedUserId;
|
|
||||||
|
|
||||||
public UsersTable(final UserAdmin parent,
|
|
||||||
final TextField usersTableFilter,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
setIdAttr("usersTable");
|
|
||||||
|
|
||||||
this.usersTableFilter = usersTableFilter;
|
|
||||||
this.selectedUserId = selectedUserId;
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.users.table.no_users", ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_SCREEN_NAME,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.users.table.screenname",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_GIVEN_NAME,
|
|
||||||
new Label(
|
|
||||||
new GlobalizedMessage("ui.admin.users.table.givenname",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_FAMILY_NAME,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.users.table.familyname",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_PRIMARY_EMAIL,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.users.table.primary_email", ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_BANNED,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.users.table.banned", ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_SCREEN_NAME).setCellRenderer(
|
|
||||||
new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
return new ControlLink((String) value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final String key = (String) event.getRowKey();
|
|
||||||
selectedUserId.setSelectedKey(state, key);
|
|
||||||
parent.showUserDetails(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new UsersTableModelBuilder());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class UsersTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table, final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new UsersTableModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class UsersTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final List<User> users;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public UsersTableModel(final PageState state) {
|
|
||||||
LOGGER.debug("Creating UsersTableModel...");
|
|
||||||
final String filterTerm = (String) usersTableFilter
|
|
||||||
.getValue(state);
|
|
||||||
LOGGER.debug("Value of filter is: \"{}\"", filterTerm);
|
|
||||||
final UserRepository userRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(UserRepository.class);
|
|
||||||
if (filterTerm == null || filterTerm.isEmpty()) {
|
|
||||||
users = userRepository.findAllOrderdByUsername();
|
|
||||||
LOGGER.debug("Found {} users in database.", users.size());
|
|
||||||
} else {
|
|
||||||
users = userRepository.filtered(filterTerm);
|
|
||||||
LOGGER.debug("Found {} users in database which match the "
|
|
||||||
+ "filter \"{}\".",
|
|
||||||
users.size(),
|
|
||||||
filterTerm);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
LOGGER.debug("Next row called. Index is {}", index);
|
|
||||||
return index < users.size();
|
|
||||||
// index++;
|
|
||||||
// LOGGER.debug("Result is '{}'. Index is now {}", result, index);
|
|
||||||
// return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
LOGGER.debug("Getting element for row {}, column {}...",
|
|
||||||
index,
|
|
||||||
columnIndex);
|
|
||||||
final User user = users.get(index);
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_BANNED:
|
|
||||||
return Boolean.toString(user.isBanned());
|
|
||||||
case COL_FAMILY_NAME:
|
|
||||||
return user.getFamilyName();
|
|
||||||
case COL_GIVEN_NAME:
|
|
||||||
return user.getGivenName();
|
|
||||||
case COL_PRIMARY_EMAIL:
|
|
||||||
return user.getPrimaryEmailAddress().getAddress();
|
|
||||||
case COL_SCREEN_NAME:
|
|
||||||
return user.getName();
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
LOGGER.debug("Getting key for row {}, column {}...",
|
|
||||||
index,
|
|
||||||
columnIndex);
|
|
||||||
return users.get(index).getPartyId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles.users;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Panel containing the {@link UsersTable} and the filter form for the table.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class UsersTablePanel extends BoxPanel {
|
|
||||||
|
|
||||||
private final TextField usersTableFilter;
|
|
||||||
|
|
||||||
public UsersTablePanel(
|
|
||||||
final UserAdmin userAdmin,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedUserId) {
|
|
||||||
|
|
||||||
setIdAttr("usersTablePanel");
|
|
||||||
|
|
||||||
final Form filterForm = new Form("usersTableFilterForm");
|
|
||||||
usersTableFilter = new TextField("usersTableFilter");
|
|
||||||
usersTableFilter.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.users.table.filter.term", ADMIN_BUNDLE));
|
|
||||||
filterForm.add(usersTableFilter);
|
|
||||||
filterForm.add(new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.users.table.filter.submit", ADMIN_BUNDLE)));
|
|
||||||
final ActionLink clearLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.users.table.filter.clear", ADMIN_BUNDLE));
|
|
||||||
clearLink.addActionListener((e) -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
usersTableFilter.setValue(state, null);
|
|
||||||
});
|
|
||||||
filterForm.add(clearLink);
|
|
||||||
add(filterForm);
|
|
||||||
|
|
||||||
add(new UsersTable(userAdmin, usersTableFilter, selectedUserId));
|
|
||||||
|
|
||||||
final ActionLink addNewUserLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.new_user.link", ADMIN_BUNDLE));
|
|
||||||
addNewUserLink.addActionListener(e -> {
|
|
||||||
userAdmin.showNewUserForm(e.getPageState());
|
|
||||||
});
|
|
||||||
add(addNewUserLink);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -18,11 +18,9 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.core;
|
package org.libreccm.core;
|
||||||
|
|
||||||
import com.arsdigita.ui.admin.applications.AdminApplicationSetup;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.libreccm.admin.ui.AdminJsfApplicationSetup;
|
|
||||||
import org.libreccm.modules.CcmModule;
|
import org.libreccm.modules.CcmModule;
|
||||||
import org.libreccm.modules.InitEvent;
|
import org.libreccm.modules.InitEvent;
|
||||||
import org.libreccm.modules.InstallEvent;
|
import org.libreccm.modules.InstallEvent;
|
||||||
|
|
@ -76,18 +74,6 @@ public class CcmCore implements CcmModule {
|
||||||
event);
|
event);
|
||||||
systemUsersSetup.setupSystemUsers();
|
systemUsersSetup.setupSystemUsers();
|
||||||
|
|
||||||
LOGGER.info("Setting up admin application (/ccm/admin/)...");
|
|
||||||
final AdminApplicationSetup adminSetup
|
|
||||||
= new AdminApplicationSetup(event);
|
|
||||||
adminSetup.setup();
|
|
||||||
|
|
||||||
LOGGER.info("Setting up admin-jsf application (/ccm/admin-jsf/)...");
|
|
||||||
final AdminJsfApplicationSetup adminJsfSetup
|
|
||||||
= new AdminJsfApplicationSetup(event);
|
|
||||||
adminJsfSetup.setup();
|
|
||||||
|
|
||||||
LOGGER.info("Setting up login application...");
|
|
||||||
|
|
||||||
LOGGER.info("Importing category domains from bundle (if any)...");
|
LOGGER.info("Importing category domains from bundle (if any)...");
|
||||||
final Properties integrationProps = new Properties();
|
final Properties integrationProps = new Properties();
|
||||||
try (final InputStream inputStream = getClass().getResourceAsStream(
|
try (final InputStream inputStream = getClass().getResourceAsStream(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue