package org.argeo.app.ui.people;
-import java.util.ArrayList;
-import java.util.List;
-
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.argeo.api.acr.Content;
import org.argeo.api.acr.ContentRepository;
import org.argeo.api.acr.ContentSession;
-import org.argeo.api.acr.ldap.LdapAttrs;
-import org.argeo.api.acr.ldap.LdapObjs;
-import org.argeo.api.cms.directory.CmsDirectory;
+import org.argeo.api.acr.ldap.LdapAttr;
import org.argeo.api.cms.directory.CmsUserManager;
import org.argeo.api.cms.directory.HierarchyUnit;
-import org.argeo.api.cms.directory.UserDirectory;
-import org.argeo.api.cms.ux.CmsIcon;
import org.argeo.api.cms.ux.CmsView;
-import org.argeo.app.ui.SuiteIcon;
-import org.argeo.app.ui.SuiteMsg;
-import org.argeo.app.ui.SuiteUxEvent;
+import org.argeo.app.ux.SuiteIcon;
+import org.argeo.app.ux.SuiteMsg;
+import org.argeo.app.ux.SuiteUxEvent;
+import org.argeo.cms.CurrentUser;
import org.argeo.cms.acr.ContentUtils;
import org.argeo.cms.auth.CmsRole;
-import org.argeo.cms.auth.CurrentUser;
-import org.argeo.cms.auth.UserAdminUtils;
import org.argeo.cms.jcr.acr.JcrContent;
import org.argeo.cms.swt.CmsSwtTheme;
import org.argeo.cms.swt.CmsSwtUtils;
import org.argeo.cms.swt.Selected;
import org.argeo.cms.swt.acr.SwtUiProvider;
+import org.argeo.cms.swt.dialogs.CmsFeedback;
import org.argeo.cms.swt.widgets.SwtGuidedFormDialog;
import org.argeo.cms.swt.widgets.SwtTableView;
import org.argeo.cms.swt.widgets.SwtTreeView;
import org.argeo.cms.ui.CmsUiProvider;
-import org.argeo.cms.ux.widgets.AbstractHierarchicalPart;
+import org.argeo.cms.ux.widgets.CmsDialog;
import org.argeo.cms.ux.widgets.Column;
-import org.argeo.cms.ux.widgets.DefaultTabularPart;
import org.argeo.cms.ux.widgets.GuidedForm;
-import org.argeo.cms.ux.widgets.HierarchicalPart;
-import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
-import org.osgi.service.useradmin.Role;
-import org.osgi.service.useradmin.User;
/** Entry to the admin area. */
public class PeopleEntryArea implements SwtUiProvider, CmsUiProvider {
CmsSwtUtils.fill(sashForm);
// VIEW
- HierarchicalPart<HierarchyUnit> hierarchyPart = new AbstractHierarchicalPart<>() {
-
- @Override
- public List<HierarchyUnit> getChildren(HierarchyUnit parent) {
- List<HierarchyUnit> visible = new ArrayList<>();
- if (parent != null) {
- if (parent instanceof CmsDirectory) // do no show children of the directories
- return visible;
- for (HierarchyUnit hu : parent.getDirectHierarchyUnits(true)) {
- visible.add(hu);
- }
- } else {
- for (UserDirectory directory : cmsUserManager.getUserDirectories()) {
- if (CurrentUser.implies(CmsRole.userAdmin, directory.getBase())) {
- visible.add(directory);
- }
- for (HierarchyUnit hu : directory.getDirectHierarchyUnits(true)) {
- if (CurrentUser.implies(CmsRole.userAdmin, hu.getBase())) {
- visible.add(hu);
- }
- }
-
- }
- }
- return visible;
- }
-
- @Override
- public String getText(HierarchyUnit model) {
- return model.getHierarchyUnitLabel(CurrentUser.locale());
- }
-
- @Override
- public CmsIcon getIcon(HierarchyUnit model) {
- Content content = ContentUtils.hierarchyUnitToContent(contentSession, model);
- if (content.hasContentClass(LdapObjs.organization))
- return SuiteIcon.organisation;
- else if (content.hasContentClass(LdapObjs.posixGroup))
- return SuiteIcon.users;
- else
- return SuiteIcon.addressBook;
- }
-
- };
+ HierarchyUnitPart hierarchyPart = new HierarchyUnitPart(contentSession, cmsUserManager);
SwtTreeView<HierarchyUnit> directoriesView = new SwtTreeView<>(sashForm, SWT.BORDER, hierarchyPart);
- DefaultTabularPart<HierarchyUnit, Content> usersPart = new DefaultTabularPart<>() {
-
- @Override
- protected List<Content> asList(HierarchyUnit hu) {
- List<Content> roles = new ArrayList<>();
- UserDirectory ud = (UserDirectory) hu.getDirectory();
- if (ud.getRealm().isPresent()) {
- for (Role r : ud.getHierarchyUnitRoles(ud, null, true)) {
- Content content = ContentUtils.roleToContent(cmsUserManager, contentSession, r);
- if (content.hasContentClass(LdapObjs.inetOrgPerson, LdapObjs.organization))
- roles.add(content);
- }
-
- } else {
- for (HierarchyUnit directChild : hu.getDirectHierarchyUnits(false)) {
- if (!(directChild.isType(HierarchyUnit.Type.FUNCTIONAL)
- || directChild.isType(HierarchyUnit.Type.ROLES))) {
- for (Role r : ud.getHierarchyUnitRoles(directChild, null, false)) {
- Content content = ContentUtils.roleToContent(cmsUserManager, contentSession, r);
- if (content.hasContentClass(LdapObjs.inetOrgPerson, LdapObjs.organization,
- LdapObjs.groupOfNames))
- roles.add(content);
- }
- }
- }
- }
- return roles;
- }
- };
- usersPart.addColumn(new Column<Content>() {
-
- @Override
- public String getText(Content role) {
- if (role.hasContentClass(LdapObjs.inetOrgPerson))
- return UserAdminUtils.getUserDisplayName(role.adapt(User.class));
- else if (role.hasContentClass(LdapObjs.organization))
- return role.attr(LdapAttrs.o);
- else if (role.hasContentClass(LdapObjs.groupOfNames))
- return role.attr(LdapAttrs.cn);
- else
- return null;
- }
-
- @Override
- public CmsIcon getIcon(Content role) {
- if (role.hasContentClass(LdapObjs.posixAccount))
- return SuiteIcon.user;
- else if (role.hasContentClass(LdapObjs.inetOrgPerson))
- return SuiteIcon.person;
- else if (role.hasContentClass(LdapObjs.organization))
- return SuiteIcon.organisationContact;
- else if (role.hasContentClass(LdapObjs.groupOfNames))
- return SuiteIcon.group;
- else
- return null;
- }
-
- @Override
- public int getWidth() {
- return 300;
- }
-
- });
-// usersPart.addColumn((Column<Content>) (role) -> role.attr(LdapAttrs.mail));
+ UsersPart usersPart = new UsersPart(contentSession, cmsUserManager);
usersPart.addColumn(new Column<Content>() {
@Override
public String getText(Content role) {
- return role.attr(LdapAttrs.mail);
+ return role.attr(LdapAttr.mail);
}
@Override
ToolBar bottomToolBar = new ToolBar(bottom, SWT.NONE);
bottomToolBar.setLayoutData(new GridData(SWT.END, SWT.FILL, true, false));
- ToolItem deleteItem = new ToolItem(bottomToolBar, SWT.FLAT);
- deleteItem.setEnabled(false);
-// CmsUiUtils.style(deleteItem, SuiteStyle.recentItems);
- deleteItem.setImage(theme.getSmallIcon(SuiteIcon.delete));
+// ToolItem deleteItem = new ToolItem(bottomToolBar, SWT.FLAT);
+// deleteItem.setEnabled(false);
+// deleteItem.setImage(theme.getSmallIcon(SuiteIcon.delete));
Menu menu = new Menu(Display.getCurrent().getActiveShell(), SWT.POP_UP);
// TODO display add user only if hierarchy unit is a POSIX group
Content huContent = ContentUtils.hierarchyUnitToContent(contentSession, hierarchyUnit);
GuidedForm wizard = new NewUserForm(cmsUserManager, huContent);
SwtGuidedFormDialog dialog = new SwtGuidedFormDialog(parent.getShell(), wizard);
- if (dialog.open() == Window.OK) {
- // TODO create
+ if (dialog.open() == CmsDialog.OK) {
+ CmsFeedback.show(SuiteMsg.personWizardFeedback.lead());
+ usersPart.refresh();
}
});
Content huContent = ContentUtils.hierarchyUnitToContent(contentSession, hierarchyUnit);
GuidedForm wizard = new NewOrgForm(cmsUserManager, huContent);
SwtGuidedFormDialog dialog = new SwtGuidedFormDialog(parent.getShell(), wizard);
- if (dialog.open() == Window.OK) {
- // TODO create
+ if (dialog.open() == CmsDialog.OK) {
+ CmsFeedback.show(SuiteMsg.orgWizardFeedback.lead());
+ usersPart.refresh();
}
});
sashForm.setWeights(new int[] { 30, 70 });
- SwtTableView<?, ?> usersTable = new SwtTableView<>(bottom, SWT.BORDER, usersPart);
- usersTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ SwtTableView<?, ?> usersView = new SwtTableView<>(bottom, SWT.BORDER, usersPart);
+ usersView.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// CONTROLLER
hierarchyPart.onSelected((o) -> {
HierarchyUnit hierarchyUnit = (HierarchyUnit) o;
usersPart.setInput(hierarchyUnit);
addItem.setEnabled(true);
+
+ addOrgItem.setEnabled(usersPart.getInput() != null
+ && CurrentUser.implies(CmsRole.groupAdmin, usersPart.getInput().getBase()));
// cmsView.sendEvent(SuiteUxEvent.refreshPart.topic(), SuiteUxEvent
// .eventProperties(ContentUtils.hierarchyUnitToContent(contentSession, hierarchyUnit)));
}
Content user = (Content) o;
if (user != null) {
cmsView.sendEvent(SuiteUxEvent.refreshPart.topic(), SuiteUxEvent.eventProperties(user));
- deleteItem.setEnabled(true);
+// deleteItem.setEnabled(true);
} else {
- deleteItem.setEnabled(false);
+// deleteItem.setEnabled(false);
}
});