Skip to content

Commit

Permalink
gh-4594 Add user groups to UserTabPresenter
Browse files Browse the repository at this point in the history
  • Loading branch information
at055612 committed Dec 10, 2024
1 parent 5cf63c6 commit ce40e0d
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public final class ColumnSizeConstants {
public static final int BIG_COL = 400;
public static final int DATE_COL = 200;
public static final int DATE_AND_DURATION_COL = 320;
public static final int UUID_COL = 300;
public static final int USER_DISPLAY_NAME_COL = 300;
public static final int UUID_COL = 320;
public static final int USER_DISPLAY_NAME_COL = 350;
public static final int USER_FULL_NAME_COL = 350;

public static final int BYTE_SIZE_COL = 60;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,34 @@ public static void onDelete(final UserListPresenter userListPresenter,
final User user = userListPresenter.getSelectionModel().getSelected();
if (user != null) {
final String userDescription = getDescription(user);
ConfirmEvent.fire(
hasHandlers,
"Are you sure you want to delete " + userDescription + "?"
+ "\n\nThis will also remove them from any groups that they are currently a member of."
+ "\nYou will not be permitted to delete them if any content has a dependency on them.",
ok -> {
if (ok) {
restFactory
.create(USER_RESOURCE)
.method(resource -> resource.delete(user.getUuid()))
.onSuccess(didDelete -> {
if (didDelete) {
userListPresenter.getSelectionModel().clear(true);
userListPresenter.refresh();
}
})
.onFailure(error ->
AlertEvent.fireError(
hasHandlers,
"Error deleting " + userDescription,
error.getMessage(),
null))
.taskMonitorFactory(userListPresenter.getPagerView())
.exec();
}
});
final String msg = "Are you sure you want to permanently delete " + userDescription + "?"
+ "\n\nThis will also remove them from any groups that they are currently " +
"a member of and delete any API keys they held. " +
"Any documents that are solely owned by them will then only be " +
"accessible by an administrator."
+ "\nYou will not be permitted to delete them if any content has a " +
"dependency on them.";
ConfirmEvent.fire(hasHandlers, msg, ok -> {
if (ok) {
restFactory
.create(USER_RESOURCE)
.method(resource -> resource.delete(user.getUuid()))
.onSuccess(didDelete -> {
if (didDelete) {
userListPresenter.getSelectionModel().clear(true);
userListPresenter.refresh();
}
})
.onFailure(error ->
AlertEvent.fireError(
hasHandlers,
"Error deleting " + userDescription,
error.getMessage(),
null))
.taskMonitorFactory(userListPresenter.getPagerView())
.exec();
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.gwtplatform.mvp.client.View;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class UserAndGroupsPresenter extends ContentTabPresenter<UserAndGroupsView> {
Expand All @@ -67,6 +68,7 @@ public class UserAndGroupsPresenter extends ContentTabPresenter<UserAndGroupsVie

private ButtonView addMembersInButton = null;
private ButtonView removeMembersInButton = null;
private UserRef userRef = null;

@Inject
public UserAndGroupsPresenter(final EventBus eventBus,
Expand All @@ -84,6 +86,8 @@ public UserAndGroupsPresenter(final EventBus eventBus,
this.userList.setName("userList");
// Top pane doesn't need to link back to itself
this.userList.setValidUserScreensForActionMenu(UserScreen.allExcept(UserScreen.USER_GROUPS));
this.userList.setResultPageConsumer(userResultPage ->
onSelection());

this.parentsList = userListPresenterProvider.get();
// A parent can only be a group
Expand Down Expand Up @@ -219,44 +223,55 @@ protected void onBind() {
}));
}

private void setParentsListExtraTerm(final UserRef userRef) {
parentsList.setAdditionalTerm(ExpressionTerm
.builder()
.field(UserFields.PARENTS_OF.getFldName())
.condition(Condition.EQUALS)
.value(userRef.getUuid())
.build());
parentsList.refresh();

final StringBuilder parentLabel = new StringBuilder()
.append(userRef.getType(CaseType.SENTENCE))
.append(" \"")
.append(userRef.getDisplayName())
.append("\" is a member of:");
parentsList.getView().setLabel(parentLabel.toString());
}

private void setChildrenListAdditionalTerm(final UserRef userRef) {
childrenList.setAdditionalTerm(ExpressionTerm
.builder()
.field(UserFields.CHILDREN_OF.getFldName())
.condition(Condition.EQUALS)
.value(userRef.getUuid())
.build());
childrenList.refresh();

final StringBuilder childLabel = new StringBuilder();
if (userRef.isGroup()) {
childLabel.append("Members of group \"");
childLabel.append(userRef.getDisplayName());
childLabel.append("\":");
} else {
childLabel.append("No group selected");
}

childrenList.getView().setLabel(childLabel.toString());
}

private void onSelection() {
final User selected = userList.getSelectionModel().getSelected();
// GWT.log("onSelection - selected: " + selected);
if (selected != null) {
parentsList.setAdditionalTerm(ExpressionTerm
.builder()
.field(UserFields.PARENTS_OF.getFldName())
.condition(Condition.EQUALS)
.value(selected.getUuid())
.build());
parentsList.refresh();

final StringBuilder parentLabel = new StringBuilder()
.append(selected.getType(CaseType.SENTENCE))
.append(" \"")
.append(selected.getDisplayName())
.append("\" is a member of:");
parentsList.getView().setLabel(parentLabel.toString());
getView().setParentsVisible(true);

childrenList.setAdditionalTerm(ExpressionTerm
.builder()
.field(UserFields.CHILDREN_OF.getFldName())
.condition(Condition.EQUALS)
.value(selected.getUuid())
.build());
childrenList.refresh();
onSelection(GwtNullSafe.get(selected, User::asRef));
}

final StringBuilder childLabel = new StringBuilder();
if (selected.isGroup()) {
childLabel.append("Members of group \"");
childLabel.append(selected.getDisplayName());
childLabel.append("\":");
} else {
childLabel.append("No group selected");
}
private void onSelection(final UserRef selected) {
if (selected != null) {
setParentsListExtraTerm(selected);
setChildrenListAdditionalTerm(selected);

childrenList.getView().setLabel(childLabel.toString());
getView().setParentsVisible(true);
getView().setChildrenVisible(selected.isGroup());

Expand Down Expand Up @@ -388,9 +403,9 @@ private void onDelete() {
UserAndGroupHelper.onDelete(userList, restFactory, this);
}

private static String getDescription(final User user) {
return user.getType(CaseType.LOWER)
+ " '" + user.asRef().toDisplayString() + "'";
private static String getDescription(final UserRef userRef) {
return userRef.getType(CaseType.LOWER)
+ " '" + userRef.toDisplayString() + "'";
}

public void refresh() {
Expand Down Expand Up @@ -439,19 +454,39 @@ public String getType() {
return "UsersAndGroups";
}

/**
* Set the quick filter to filter on the desired user.
*
* @param userRef
*/
public void showUser(final UserRef userRef) {
userList.setResultPageConsumer(userResultPage -> {
onSelection();
});
userList.showUser(userRef);
}

/**
* Set the specific user
*
* @param userRef
*/
public void setUserRef(final UserRef userRef) {
Objects.requireNonNull(userRef);
this.userRef = userRef;

// Specific user so don't show the top pane
getView().setUserListVisible(false);

onSelection(userRef);

}


// --------------------------------------------------------------------------------


public interface UserAndGroupsView extends View {

void setUserListVisible(boolean visible);

void setUserList(View view);

void setParentsView(View view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ private void setupColumns() {
.enabledWhen(User::isEnabled)
.withSorting(UserFields.FIELD_DISPLAY_NAME, true)
.build();
dataGrid.addAutoResizableColumn(
dataGrid.addResizableColumn(
displayNameCol,
DataGridUtil.headingBuilder(UserAndGroupHelper.COL_NAME_DISPLAY_NAME)
.withToolTip(displayNameTooltip)
.build(),
300);
ColumnSizeConstants.USER_DISPLAY_NAME_COL);

// final Column<User, User> displayNameCol = DataGridUtil.columnBuilder(
// Function.identity(),
Expand Down Expand Up @@ -271,7 +271,7 @@ private void setupColumns() {
? "The full name of the user. Groups do not have a full name."
: "The full name of the user.")
.build(),
300);
ColumnSizeConstants.USER_FULL_NAME_COL);
}

// Unique User ID
Expand All @@ -289,7 +289,7 @@ private void setupColumns() {
DataGridUtil.headingBuilder(UserAndGroupHelper.COL_NAME_UNIQUE_USER_ID)
.withToolTip("The unique user ID on the identity provider.")
.build(),
350);
ColumnSizeConstants.UUID_COL);
}

// Actions Menu btn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class UserTabPresenter
private final LazyValue<UserDependenciesListPresenter> userDependenciesListPresenterLazyValue;
private final LazyValue<ApiKeysPresenter> apiKeysListPresenterLazyValue;
private final LazyValue<AppPermissionsEditPresenter> appPermissionsEditPresenterLazyValue;
private final LazyValue<UserAndGroupsPresenter> userAndGroupsPresenterLazyValue;
private final List<TabData> tabs = new ArrayList<>();

private UserRef userRef;
Expand All @@ -80,7 +81,8 @@ public UserTabPresenter(final EventBus eventBus,
final Provider<UserPermissionReportPresenter> userPermsReportPresenterProvider,
final Provider<UserDependenciesListPresenter> userDependenciesListPresenterProvider,
final Provider<ApiKeysPresenter> apiKeysListPresenterProvider,
final Provider<AppPermissionsEditPresenter> appPermissionsEditPresenterProvider) {
final Provider<AppPermissionsEditPresenter> appPermissionsEditPresenterProvider,
final Provider<UserAndGroupsPresenter> userAndGroupsPresenterProvider) {
super(eventBus, view);
this.userInfoPresenter = userInfoPresenter;
this.clientSecurityContext = clientSecurityContext;
Expand All @@ -104,11 +106,17 @@ public UserTabPresenter(final EventBus eventBus,
appPermissionsEditPresenter -> {
appPermissionsEditPresenter.setUserRef(getUserRef());
});
this.userAndGroupsPresenterLazyValue = new LazyValue<>(
userAndGroupsPresenterProvider,
userAndGroupsPresenter -> {
userAndGroupsPresenter.setUserRef(userRef);
});

final boolean hasManagerUsersPerm = clientSecurityContext.hasAppPermission(
AppPermission.MANAGE_USERS_PERMISSION);

addTab(INFO_TAB);
addTab(USER_GROUPS_TAB);
// It was decided that a user should not see their own app perms.
if (hasManagerUsersPerm) {
addTab(APP_PERMS_TAB);
Expand Down Expand Up @@ -157,6 +165,11 @@ protected void getContent(final TabData tab, final ContentCallback callback) {
if (INFO_TAB.equals(tab)) {
userInfoPresenter.setUserRef(userRef);
callback.onReady(userInfoPresenter);
} else if (USER_GROUPS_TAB.equals(tab)) {
final UserAndGroupsPresenter userAndGroupsPresenter
= userAndGroupsPresenterLazyValue.getValue();
userAndGroupsPresenter.setUserRef(userRef);
callback.onReady(userAndGroupsPresenter);
} else if (APP_PERMS_TAB.equals(tab)) {
final AppPermissionsEditPresenter appPermissionsEditPresenter
= appPermissionsEditPresenterLazyValue.getValue();
Expand Down Expand Up @@ -207,7 +220,7 @@ public void setUserRef(final UserRef userRef) {
this.userRef = userRef;
this.label = GwtNullSafe.getOrElse(
userRef,
ref -> ref.getType(CaseType.SENTENCE) + " " + ref.toDisplayString(),
ref -> ref.getType(CaseType.SENTENCE) + ": " + ref.toDisplayString(),
"Unknown User/Group");
userInfoPresenter.setUserRef(userRef);
appPermissionsEditPresenterLazyValue.consumeIfInitialised(appPermissionsEditPresenter ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.ThinSplitLayoutPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.View;
Expand All @@ -30,8 +31,13 @@ public final class UserAndGroupsViewImpl extends ViewImpl implements UserAndGrou

private final Widget widget;

@UiField
ThinSplitLayoutPanel outerSplitLayoutPanel;
@UiField
SimplePanel userList;

@UiField
ThinSplitLayoutPanel innerSplitLayoutPanel;
@UiField
SimplePanel parents;
@UiField
Expand All @@ -47,6 +53,18 @@ public Widget asWidget() {
return widget;
}

@Override
public void setUserListVisible(final boolean visible) {
userList.setVisible(visible);
outerSplitLayoutPanel.setWidgetHidden(userList.asWidget(), !visible);
if (visible) {
outerSplitLayoutPanel.setVSplits(0.5);
} else {
outerSplitLayoutPanel.setVSplits();
}
outerSplitLayoutPanel.onResize();
}

@Override
public void setUserList(final View view) {
this.userList.setWidget(view.asWidget());
Expand All @@ -71,11 +89,20 @@ public void setChildrenView(final View view) {

@Override
public void setChildrenVisible(final boolean visible) {
children.getElement().getStyle().setOpacity(visible
? 1
: 0.4);
children.setVisible(visible);
innerSplitLayoutPanel.setWidgetHidden(children.asWidget(), !visible);
if (visible) {
innerSplitLayoutPanel.setHSplits(0.5);
} else {
innerSplitLayoutPanel.setHSplits();
}
innerSplitLayoutPanel.onResize();
}


// --------------------------------------------------------------------------------


public interface Binder extends UiBinder<Widget, UserAndGroupsViewImpl> {

}
Expand Down
Loading

0 comments on commit ce40e0d

Please sign in to comment.