1 package org
.argeo
.app
.ui
.people
;
3 import java
.util
.ArrayList
;
7 import javax
.jcr
.RepositoryException
;
9 import org
.argeo
.api
.acr
.Content
;
10 import org
.argeo
.api
.acr
.ContentRepository
;
11 import org
.argeo
.api
.acr
.ContentSession
;
12 import org
.argeo
.api
.cms
.ux
.CmsIcon
;
13 import org
.argeo
.api
.cms
.ux
.CmsView
;
14 import org
.argeo
.app
.ui
.SuiteEvent
;
15 import org
.argeo
.app
.ui
.SuiteIcon
;
16 import org
.argeo
.cms
.CmsUserManager
;
17 import org
.argeo
.cms
.acr
.ContentUtils
;
18 import org
.argeo
.cms
.auth
.CmsRole
;
19 import org
.argeo
.cms
.auth
.CurrentUser
;
20 import org
.argeo
.cms
.auth
.UserAdminUtils
;
21 import org
.argeo
.cms
.jcr
.acr
.JcrContent
;
22 import org
.argeo
.cms
.swt
.CmsSwtTheme
;
23 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
24 import org
.argeo
.cms
.swt
.Selected
;
25 import org
.argeo
.cms
.swt
.acr
.SwtUiProvider
;
26 import org
.argeo
.cms
.swt
.widgets
.SwtGuidedFormDialog
;
27 import org
.argeo
.cms
.swt
.widgets
.SwtTableView
;
28 import org
.argeo
.cms
.swt
.widgets
.SwtTreeView
;
29 import org
.argeo
.cms
.ui
.CmsUiProvider
;
30 import org
.argeo
.cms
.ux
.widgets
.AbstractHierarchicalPart
;
31 import org
.argeo
.cms
.ux
.widgets
.Column
;
32 import org
.argeo
.cms
.ux
.widgets
.DefaultTabularPart
;
33 import org
.argeo
.cms
.ux
.widgets
.GuidedForm
;
34 import org
.argeo
.cms
.ux
.widgets
.HierarchicalPart
;
35 import org
.argeo
.osgi
.useradmin
.UserDirectory
;
36 import org
.argeo
.util
.directory
.HierarchyUnit
;
37 import org
.argeo
.util
.directory
.ldap
.IpaUtils
;
38 import org
.argeo
.util
.naming
.LdapAttrs
;
39 import org
.argeo
.util
.naming
.LdapObjs
;
40 import org
.eclipse
.jface
.window
.Window
;
41 import org
.eclipse
.swt
.SWT
;
42 import org
.eclipse
.swt
.custom
.SashForm
;
43 import org
.eclipse
.swt
.layout
.GridData
;
44 import org
.eclipse
.swt
.layout
.GridLayout
;
45 import org
.eclipse
.swt
.widgets
.Composite
;
46 import org
.eclipse
.swt
.widgets
.Control
;
47 import org
.eclipse
.swt
.widgets
.ToolBar
;
48 import org
.eclipse
.swt
.widgets
.ToolItem
;
49 import org
.osgi
.service
.useradmin
.Role
;
50 import org
.osgi
.service
.useradmin
.User
;
52 /** Entry to the admin area. */
53 public class PeopleEntryArea
implements SwtUiProvider
, CmsUiProvider
{
55 private CmsUserManager cmsUserManager
;
57 private ContentRepository contentRepository
;
60 public Control
createUiPart(Composite parent
, Content context
) {
61 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
62 CmsView cmsView
= CmsSwtUtils
.getCmsView(parent
);
63 parent
.setLayout(new GridLayout());
65 ContentSession contentSession
= contentRepository
.get();
66 SashForm sashForm
= new SashForm(parent
, SWT
.VERTICAL
);
67 CmsSwtUtils
.fill(sashForm
);
70 // List<UserDirectory> directories = new ArrayList<>();
71 // // List<User> orgs = cmsUserManager.listGroups(null, true, false);
72 // for (UserDirectory directory : cmsUserManager.getUserDirectories()) {
73 // if (CurrentUser.implies(CmsRole.userAdmin, directory.getContext())) {
74 // directories.add(directory);
80 HierarchicalPart
<HierarchyUnit
> hierarchyPart
= new AbstractHierarchicalPart
<>() {
83 public List
<HierarchyUnit
> getChildren(HierarchyUnit parent
) {
84 List
<HierarchyUnit
> visible
= new ArrayList
<>();
86 for (HierarchyUnit hu
: parent
.getDirectHierarchyUnits(true)) {
87 // if parent was visible, it is visible
88 // TODO restrict more?
90 // if (CurrentUser.implies(CmsRole.userAdmin, hu.getBase()) //
97 for (UserDirectory directory
: cmsUserManager
.getUserDirectories()) {
98 if (CurrentUser
.implies(CmsRole
.userAdmin
, directory
.getBase()) //
99 || CurrentUser
.implies(CmsRole
.userAdmin
,
100 IpaUtils
.IPA_ACCOUNTS_RDN
+ "," + directory
.getBase())) // IPA
102 // TODO show base level
104 for (HierarchyUnit hu
: directory
.getDirectHierarchyUnits(true)) {
105 if (CurrentUser
.implies(CmsRole
.userAdmin
, hu
.getBase())) {
116 public String
getText(HierarchyUnit model
) {
117 return model
.getHierarchyUnitLabel(CurrentUser
.locale());
121 public CmsIcon
getIcon(HierarchyUnit model
) {
122 Content content
= ContentUtils
.hierarchyUnitToContent(contentSession
, model
);
123 if (content
.hasContentClass(LdapObjs
.organization
.qName()))
124 return SuiteIcon
.organisation
;
125 else if (content
.hasContentClass(LdapObjs
.posixGroup
.qName()))
126 return SuiteIcon
.users
;
128 return SuiteIcon
.addressBook
;
132 SwtTreeView
<HierarchyUnit
> directoriesView
= new SwtTreeView
<>(sashForm
, SWT
.BORDER
, hierarchyPart
);
134 DefaultTabularPart
<HierarchyUnit
, Content
> usersPart
= new DefaultTabularPart
<>() {
137 protected List
<Content
> asList(HierarchyUnit hu
) {
138 List
<Content
> roles
= new ArrayList
<>();
139 UserDirectory ud
= (UserDirectory
) hu
.getDirectory();
140 if (ud
.getRealm().isPresent()) {
141 for (Role r
: ud
.getHierarchyUnitRoles(ud
, null, true)) {
142 Content content
= ContentUtils
.roleToContent(cmsUserManager
, contentSession
, r
);
143 // if (r instanceof Person || r instanceof Organization)
144 if (content
.hasContentClass(LdapObjs
.inetOrgPerson
.qName(), LdapObjs
.organization
.qName()))
149 for (HierarchyUnit directChild
: hu
.getDirectHierarchyUnits(false)) {
150 if (!directChild
.isFunctional()) {
151 for (Role r
: ud
.getHierarchyUnitRoles(directChild
, null, false)) {
152 Content content
= ContentUtils
.roleToContent(cmsUserManager
, contentSession
, r
);
153 // if (r instanceof Person || r instanceof Organization)
154 if (content
.hasContentClass(LdapObjs
.inetOrgPerson
.qName(),
155 LdapObjs
.organization
.qName(), LdapObjs
.groupOfNames
.qName()))
164 usersPart
.addColumn(new Column
<Content
>() {
167 public String
getText(Content role
) {
168 if (role
.isContentClass(LdapObjs
.inetOrgPerson
.qName()))
169 return UserAdminUtils
.getUserDisplayName(role
.adapt(User
.class));
170 else if (role
.isContentClass(LdapObjs
.organization
.qName()))
171 return role
.attr(LdapAttrs
.o
.qName());
172 else if (role
.isContentClass(LdapObjs
.groupOfNames
.qName()))
173 return role
.attr(LdapAttrs
.cn
.qName());
179 public CmsIcon
getIcon(Content role
) {
180 if (role
.hasContentClass(LdapObjs
.posixAccount
.qName()))
181 return SuiteIcon
.user
;
182 else if (role
.isContentClass(LdapObjs
.inetOrgPerson
.qName()))
183 return SuiteIcon
.person
;
184 else if (role
.isContentClass(LdapObjs
.organization
.qName()))
185 return SuiteIcon
.organisationContact
;
186 else if (role
.isContentClass(LdapObjs
.groupOfNames
.qName()))
187 return SuiteIcon
.group
;
193 public int getWidth() {
198 usersPart
.addColumn((Column
<Content
>) (role
) -> role
.attr(LdapAttrs
.mail
.qName()));
200 SwtTableView
<HierarchyUnit
, Content
> usersView
= new SwtTableView
<>(sashForm
, SWT
.BORDER
, usersPart
);
203 Composite bottom
= new Composite(parent
, SWT
.NONE
);
204 bottom
.setLayoutData(CmsSwtUtils
.fillWidth());
205 bottom
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
206 ToolBar bottomToolBar
= new ToolBar(bottom
, SWT
.NONE
);
207 bottomToolBar
.setLayoutData(new GridData(SWT
.END
, SWT
.FILL
, true, false));
208 ToolItem deleteItem
= new ToolItem(bottomToolBar
, SWT
.FLAT
);
209 deleteItem
.setEnabled(false);
210 // CmsUiUtils.style(deleteItem, SuiteStyle.recentItems);
211 deleteItem
.setImage(theme
.getSmallIcon(SuiteIcon
.delete
));
212 ToolItem addItem
= new ToolItem(bottomToolBar
, SWT
.FLAT
);
213 addItem
.setImage(theme
.getSmallIcon(SuiteIcon
.add
));
215 sashForm
.setWeights(new int[] { 30, 70 });
218 hierarchyPart
.onSelected((o
) -> {
219 if (o
instanceof HierarchyUnit
) {
220 HierarchyUnit hierarchyUnit
= (HierarchyUnit
) o
;
221 usersPart
.setInput(hierarchyUnit
);
222 cmsView
.sendEvent(SuiteEvent
.refreshPart
.topic(),
223 SuiteEvent
.eventProperties(ContentUtils
.hierarchyUnitToContent(contentSession
, hierarchyUnit
)));
227 usersPart
.onSelected((o
) -> {
228 Content user
= (Content
) o
;
230 cmsView
.sendEvent(SuiteEvent
.refreshPart
.topic(), SuiteEvent
.eventProperties(user
));
231 deleteItem
.setEnabled(true);
233 deleteItem
.setEnabled(false);
237 usersPart
.onAction((o
) -> {
238 Content user
= (Content
) o
;
240 cmsView
.sendEvent(SuiteEvent
.openNewPart
.topic(), SuiteEvent
.eventProperties(user
));
244 addItem
.addSelectionListener((Selected
) (e
) -> {
245 HierarchyUnit hierarchyUnit
= usersPart
.getInput();
246 Content huContent
= ContentUtils
.hierarchyUnitToContent(contentSession
, hierarchyUnit
);
247 GuidedForm wizard
= new NewUserForm(cmsUserManager
, huContent
);
248 SwtGuidedFormDialog dialog
= new SwtGuidedFormDialog(parent
.getShell(), wizard
);
249 // WizardDialog dialog = new WizardDialog(shell, wizard);
250 if (dialog
.open() == Window
.OK
) {
255 directoriesView
.refresh();
256 // usersView.refresh();
261 // static String getProperty(Role role, LdapAttrs attr) {
262 // Object value = role.getProperties().get(attr.name());
263 // return value != null ? value.toString() : null;
266 // private boolean isOrganisation(Role role) {
267 // String[] objectClasses = role.getProperties().get(LdapAttrs.objectClasses.name()).toString().split("\\n");
268 // for (String objectClass : objectClasses) {
269 // if (LdapObjs.organization.name().equalsIgnoreCase(objectClass))
275 public void setCmsUserManager(CmsUserManager cmsUserManager
) {
276 this.cmsUserManager
= cmsUserManager
;
280 public Control
createUi(Composite parent
, Node context
) throws RepositoryException
{
281 return createUiPart(parent
, JcrContent
.nodeToContent(context
));
284 public void setContentRepository(ContentRepository contentRepository
) {
285 this.contentRepository
= contentRepository
;