SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
CmsSwtUtils.fill(sashForm);
- // MODEL
-// List<UserDirectory> directories = new ArrayList<>();
-// // List<User> orgs = cmsUserManager.listGroups(null, true, false);
-// for (UserDirectory directory : cmsUserManager.getUserDirectories()) {
-// if (CurrentUser.implies(CmsRole.userAdmin, directory.getContext())) {
-// directories.add(directory);
-// }
-//
-// }
-
// VIEW
HierarchicalPart<HierarchyUnit> hierarchyPart = new AbstractHierarchicalPart<>() {
if (ud.getRealm().isPresent()) {
for (Role r : ud.getHierarchyUnitRoles(ud, null, true)) {
Content content = ContentUtils.roleToContent(cmsUserManager, contentSession, r);
- // if (r instanceof Person || r instanceof Organization)
if (content.hasContentClass(LdapObjs.inetOrgPerson.qName(), LdapObjs.organization.qName()))
roles.add(content);
}
} else {
for (HierarchyUnit directChild : hu.getDirectHierarchyUnits(false)) {
- if (!directChild.isFunctional()) {
+ 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 (r instanceof Person || r instanceof Organization)
if (content.hasContentClass(LdapObjs.inetOrgPerson.qName(),
LdapObjs.organization.qName(), LdapObjs.groupOfNames.qName()))
roles.add(content);
});
usersPart.addColumn((Column<Content>) (role) -> role.attr(LdapAttrs.mail.qName()));
- SwtTableView<HierarchyUnit, Content> usersView = new SwtTableView<>(sashForm, SWT.BORDER, usersPart);
+ new SwtTableView<>(sashForm, SWT.BORDER, usersPart);
// toolbar
Composite bottom = new Composite(parent, SWT.NONE);
if (o instanceof HierarchyUnit) {
HierarchyUnit hierarchyUnit = (HierarchyUnit) o;
usersPart.setInput(hierarchyUnit);
- cmsView.sendEvent(SuiteUxEvent.refreshPart.topic(), SuiteUxEvent
- .eventProperties(ContentUtils.hierarchyUnitToContent(contentSession, hierarchyUnit)));
+// cmsView.sendEvent(SuiteUxEvent.refreshPart.topic(), SuiteUxEvent
+// .eventProperties(ContentUtils.hierarchyUnitToContent(contentSession, hierarchyUnit)));
}
});
return sashForm;
}
-// static String getProperty(Role role, LdapAttrs attr) {
-// Object value = role.getProperties().get(attr.name());
-// return value != null ? value.toString() : null;
-// }
-
-// private boolean isOrganisation(Role role) {
-// String[] objectClasses = role.getProperties().get(LdapAttrs.objectClasses.name()).toString().split("\\n");
-// for (String objectClass : objectClasses) {
-// if (LdapObjs.organization.name().equalsIgnoreCase(objectClass))
-// return true;
-// }
-// return false;
-// }
-
public void setCmsUserManager(CmsUserManager cmsUserManager) {
this.cmsUserManager = cmsUserManager;
}
import org.argeo.api.acr.Content;
import org.argeo.api.acr.ldap.LdapAttrs;
import org.argeo.api.acr.ldap.LdapObjs;
+import org.argeo.app.api.SuiteRole;
import org.argeo.app.ui.SuiteMsg;
import org.argeo.app.ui.SuiteStyle;
import org.argeo.app.ui.SuiteUiUtils;
+import org.argeo.cms.CmsMsg;
import org.argeo.cms.CmsUserManager;
import org.argeo.cms.Localized;
+import org.argeo.cms.auth.CmsRole;
+import org.argeo.cms.auth.CurrentUser;
+import org.argeo.cms.auth.RoleNameUtils;
+import org.argeo.cms.auth.SystemRole;
import org.argeo.cms.swt.CmsSwtUtils;
+import org.argeo.cms.swt.Selected;
import org.argeo.cms.swt.acr.SwtSection;
import org.argeo.cms.swt.acr.SwtUiProvider;
+import org.argeo.cms.swt.dialogs.CmsFeedback;
import org.argeo.cms.swt.widgets.EditableText;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
/** Edit a suite user. */
public class PersonUiProvider implements SwtUiProvider {
- private String[] availableRoles;
private CmsUserManager cmsUserManager;
@Override
User user = context.adapt(User.class);
+ String roleContext = RoleNameUtils.getContext(user.getName());
+
if (context.hasContentClass(LdapObjs.person.qName())) {
+
addFormLine(main, SuiteMsg.firstName, context, LdapAttrs.givenName);
addFormLine(main, SuiteMsg.lastName, context, LdapAttrs.sn);
addFormLine(main, SuiteMsg.email, context, LdapAttrs.mail);
+ }
+
+ if (context.hasContentClass(LdapObjs.posixAccount.qName())) {
- Composite rolesSection = new Composite(main, SWT.NONE);
- rolesSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+ SwtSection rolesSection = new SwtSection(main, SWT.NONE);
+ rolesSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
rolesSection.setLayout(new GridLayout());
List<String> roles = Arrays.asList(cmsUserManager.getUserRoles(user.getName()));
- for (String role : roles) {
- // new Label(rolesSection, SWT.NONE).setText(role);
- Button radio = new Button(rolesSection, SWT.CHECK);
- radio.setText(role);
- if (roles.contains(role))
- radio.setSelection(true);
- }
+ addRoleCheckBox(rolesSection, SuiteMsg.coworkerRole, SuiteRole.coworker, roleContext, roles);
+ addRoleCheckBox(rolesSection, SuiteMsg.publisherRole, SuiteRole.publisher, roleContext, roles);
+ addRoleCheckBox(rolesSection, SuiteMsg.userAdminRole, CmsRole.userAdmin, roleContext, roles);
// Composite facetsSection = new Composite(main, SWT.NONE);
// facetsSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
// new Label(facetsSection, SWT.NONE).setText(member);
// }
// }
+ if (CurrentUser.implies(CmsRole.userAdmin, roleContext)) {
+ SwtSection changePasswordSection = new SwtSection(main, SWT.BORDER);
+ changePasswordSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
+ changePasswordSection.setLayout(new GridLayout(2, false));
+// SuiteUiUtils.addFormLabel(changePasswordSection, CmsMsg.changePassword)
+// .setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false, false, 2, 1));
+ SuiteUiUtils.addFormLabel(changePasswordSection, CmsMsg.newPassword);
+ Text newPasswordT = SuiteUiUtils.addFormTextField(changePasswordSection, null, null,
+ SWT.PASSWORD | SWT.BORDER);
+ newPasswordT.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ SuiteUiUtils.addFormLabel(changePasswordSection, CmsMsg.repeatNewPassword);
+ Text repeatNewPasswordT = SuiteUiUtils.addFormTextField(changePasswordSection, null, null,
+ SWT.PASSWORD | SWT.BORDER);
+ repeatNewPasswordT.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ Button apply = new Button(changePasswordSection, SWT.FLAT);
+ apply.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false, 2, 1));
+ apply.setText(CmsMsg.changePassword.lead());
+ apply.addSelectionListener((Selected) (e) -> {
+ try {
+ char[] newPassword = newPasswordT.getTextChars();
+ char[] repeatNewPassword = repeatNewPasswordT.getTextChars();
+ if (newPassword.length > 0 && Arrays.equals(newPassword, repeatNewPassword)) {
+ cmsUserManager.resetPassword(user.getName(), newPassword);
+ CmsFeedback.show(CmsMsg.passwordChanged.lead());
+ } else {
+ CmsFeedback.error(CmsMsg.invalidPassword.lead(), null);
+ }
+ } catch (Exception e1) {
+ CmsFeedback.error(CmsMsg.invalidPassword.lead(), e1);
+ }
+ });
+ }
}
-// if (user instanceof Group) {
-// String cn = context.getName().getLocalPart();
-// Text cnT = SuiteUiUtils.addFormLine(main, "uid", getUserProperty(user, LdapAttrs.uid.name()));
-// cnT.setText(cn);
-//
-// } else {
-// String uid = context.getName().getLocalPart();
-//
-//// Text givenName = new Text(main, SWT.SINGLE);
-//// givenName.setText(getUserProperty(user, LdapAttrs.givenName.name()));
-// Text givenName = SuiteUiUtils.addFormInput(main, SuiteMsg.firstName.lead(),
-// getUserProperty(user, LdapAttrs.givenName.name()));
-//
-// Text sn = SuiteUiUtils.addFormInput(main, SuiteMsg.lastName.lead(),
-// getUserProperty(user, LdapAttrs.sn.name()));
-// // sn.setText(getUserProperty(user, LdapAttrs.sn.name()));
-//
-// Text email = SuiteUiUtils.addFormInput(main, SuiteMsg.email.lead(),
-// getUserProperty(user, LdapAttrs.mail.name()));
-// // email.setText(getUserProperty(user, LdapAttrs.mail.name()));
-//
-// Text uidT = SuiteUiUtils.addFormLine(main, "uid", getUserProperty(user, LdapAttrs.uid.name()));
-// uidT.setText(uid);
-//
-//// Label dnL = new Label(main, SWT.NONE);
-//// dnL.setText(user.getName());
-//
-// // roles
-// // Section rolesSection = new Section(main, SWT.NONE, context);
-// Composite rolesSection = new Composite(main, SWT.NONE);
-// // rolesSection.setText("Roles");
-// rolesSection.setLayoutData(CmsSwtUtils.fillWidth());
-// rolesSection.setLayout(new GridLayout());
-// // new Label(rolesSection, SWT.NONE).setText("Roles:");
-// List<String> roles = Arrays.asList(cmsUserManager.getUserRoles(user.getName()));
-// for (String role : availableRoles) {
-// // new Label(rolesSection, SWT.NONE).setText(role);
-// Button radio = new Button(rolesSection, SWT.CHECK);
-// radio.setText(role);
-// if (roles.contains(role))
-// radio.setSelection(true);
-// }
-// }
-
return main;
}
});
}
+ private void addRoleCheckBox(SwtSection parent, Localized msg, SystemRole systemRole, String roleContext,
+ List<String> roles) {
+ Button radio = new Button(parent, SWT.CHECK);
+ radio.setText(msg.lead());
+ radio.setSelection(false);
+ roles: for (String dn : roles) {
+ if (systemRole.implied(dn, roleContext)) {
+ radio.setSelection(true);
+ break roles;
+ }
+ }
+ if (CurrentUser.implies(CmsRole.userAdmin, roleContext))
+ radio.setEnabled(true);
+ else
+ radio.setEnabled(false);
+
+ }
+
public void setCmsUserManager(CmsUserManager cmsUserManager) {
this.cmsUserManager = cmsUserManager;
}
- private String getUserProperty(Object element, String key) {
- Object value = ((User) element).getProperties().get(key);
- return value != null ? value.toString() : null;
- }
+// private String getUserProperty(Object element, String key) {
+// Object value = ((User) element).getProperties().get(key);
+// return value != null ? value.toString() : null;
+// }
public void init(Map<String, Object> properties) {
- availableRoles = (String[]) properties.get("availableRoles");
- // cmsUserManager.getRoles(null);
}
}