Skip to content

Commit

Permalink
gh-4594 Improve Accounts tbl, add link to Usrs/Grps scrn
Browse files Browse the repository at this point in the history
  • Loading branch information
at055612 committed Nov 13, 2024
1 parent 5c3e3b9 commit f80273a
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface QuickFilterPageView extends View, Focus, HasUiHandlers<QuickFil
void registerPopupTextProvider(Supplier<SafeHtml> popupTextSupplier);

void setDataView(View view);

void setQuickFilterText(String quickFilterText);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.ViewWithUiHandlers;

import java.util.Objects;
import java.util.function.Supplier;

public class QuickFilterPageViewImpl extends ViewWithUiHandlers<QuickFilterUiHandlers>
Expand Down Expand Up @@ -70,16 +71,30 @@ public void setDataView(View view) {
data.setWidget(view.asWidget());
}

@Override
public void setQuickFilterText(final String quickFilterText) {
final String currVal = quickFilter.getText();
quickFilter.setText(quickFilterText);
if (!Objects.equals(currVal, quickFilterText)) {
getUiHandlers().onFilterChange(quickFilterText);
}
}

@UiHandler("quickFilter")
void onFilterChange(final ValueChangeEvent<String> event) {
getUiHandlers().onFilterChange(quickFilter.getText());
}


@Override
public Widget asWidget() {
return widget;
}


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


public interface Binder extends UiBinder<Widget, QuickFilterPageViewImpl> {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import stroom.core.client.presenter.MonitoringPlugin;
import stroom.menubar.client.event.BeforeRevealMenubarEvent;
import stroom.security.client.api.ClientSecurityContext;
import stroom.security.client.event.OpenUserOrGroupEvent;
import stroom.security.client.presenter.UserAndGroupsPresenter;
import stroom.security.shared.AppPermission;
import stroom.security.shared.UserFields;
import stroom.svg.shared.SvgImage;
import stroom.widget.menu.client.presenter.IconMenuItem.Builder;
import stroom.widget.util.client.KeyBinding.Action;
Expand All @@ -27,6 +29,15 @@ public UsersAndGroupsPlugin(final EventBus eventBus,
final Provider<UserAndGroupsPresenter> presenterProvider,
final ClientSecurityContext securityContext) {
super(eventBus, contentManager, presenterProvider, securityContext);

registerHandler(getEventBus().addHandler(OpenUserOrGroupEvent.getType(), event -> {
open(taskManagerPresenter ->
taskManagerPresenter.setFilterInput(buildFilterInput(event.getSubjectId())));
}));
}

private String buildFilterInput(final String subjectId) {
return UserFields.FIELD_DISPLAY_NAME + ":" + subjectId;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package stroom.security.client.event;

import stroom.security.client.event.OpenUserOrGroupEvent.OpenUserOrGroupHandler;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HasHandlers;

import java.util.Objects;

public class OpenUserOrGroupEvent extends GwtEvent<OpenUserOrGroupHandler> {

private static Type<OpenUserOrGroupHandler> TYPE;
private final String subjectId;

private OpenUserOrGroupEvent(final String subjectId) {
this.subjectId = Objects.requireNonNull(subjectId);
}

/**
* Open the named node on the nodes screen
*/
public static void fire(final HasHandlers handlers, final String subjectId) {
handlers.fireEvent(new OpenUserOrGroupEvent(subjectId));
}

public static Type<OpenUserOrGroupHandler> getType() {
if (TYPE == null) {
TYPE = new Type<>();
}
return TYPE;
}

@Override
public Type<OpenUserOrGroupHandler> getAssociatedType() {
return getType();
}

@Override
protected void dispatch(final OpenUserOrGroupHandler handler) {
handler.onOpen(this);
}

public String getSubjectId() {
return subjectId;
}

@Override
public String toString() {
return "OpenUserOrGroupEvent{" +
"subjectId='" + subjectId + '\'' +
'}';
}

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


public interface OpenUserOrGroupHandler extends EventHandler {

void onOpen(OpenUserOrGroupEvent event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ protected void onBind() {
}));
}

public void setFilterInput(final String filterInput) {
userList.setQuickFilterText(filterInput);
}

private void onSelection() {
final User selected = userList.getSelectionModel().getSelected();
if (selected != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,17 @@ public void onFilterChange(final String text) {
filter = text;
if (filter != null) {
filter = filter.trim();
if (filter.length() == 0) {
if (filter.isEmpty()) {
filter = null;
}
}
refresh();
}

public void setQuickFilterText(final String quickFilterText) {
getView().setQuickFilterText(quickFilterText);
}

public void refresh() {
if (dataProvider == null) {
this.dataProvider = new RestDataProvider<User, ResultPage<User>>(getEventBus()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import stroom.alert.client.event.AlertEvent;
import stroom.alert.client.event.ConfirmEvent;
import stroom.cell.info.client.CommandLink;
import stroom.data.client.event.DataSelectionEvent;
import stroom.data.client.event.DataSelectionEvent.DataSelectionHandler;
import stroom.data.client.event.HasDataSelectionHandlers;
Expand All @@ -15,6 +16,7 @@
import stroom.dispatch.client.RestFactory;
import stroom.preferences.client.DateTimeFormatter;
import stroom.security.client.api.ClientSecurityContext;
import stroom.security.client.event.OpenUserOrGroupEvent;
import stroom.security.identity.shared.Account;
import stroom.security.identity.shared.AccountResource;
import stroom.security.identity.shared.AccountResultPage;
Expand Down Expand Up @@ -44,6 +46,7 @@
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;

public class AccountsListPresenter
extends MyPresenterWidget<PagerView>
Expand Down Expand Up @@ -158,8 +161,8 @@ private void deleteSelectedAccount() {
final Account account = selectionModel.getSelected();
if (account != null) {
final String msg = "Are you sure you want to delete account '"
+ account.getUserId()
+ "'?";
+ account.getUserId()
+ "'?";
ConfirmEvent.fire(this, msg, ok -> {
if (ok) {
restFactory
Expand All @@ -180,14 +183,32 @@ private void deleteSelectedAccount() {
private void initTableColumns() {
// User Id
if (securityContext.hasAppPermission(AppPermission.MANAGE_USERS_PERMISSION)) {
final Column<Account, String> userIdColumn = DataGridUtil.textColumnBuilder(
Account::getUserId)
.enabledWhen(Account::isEnabled)
.withSorting(FindAccountRequest.FIELD_NAME_USER_ID)
.build();
dataGrid.addResizableColumn(userIdColumn, "User Id", 250);

dataGrid.addResizableColumn(
DataGridUtil.commandLinkColumnBuilder(buildOpenUserCommandLink())
.enabledWhen(Account::isEnabled)
.withSorting(FindAccountRequest.FIELD_NAME_USER_ID)
.build(),
DataGridUtil.headingBuilder("User Id")
.withToolTip("The unique identifier for both the account and the corresponding user.")
.build(),
200);
}

// First Name
final Column<Account, String> firstNameColumn = DataGridUtil.textColumnBuilder(Account::getFirstName)
.enabledWhen(Account::isEnabled)
.withSorting(FindAccountRequest.FIELD_NAME_FIRST_NAME)
.build();
dataGrid.addResizableColumn(firstNameColumn, "First Name", 180);

// First Name
final Column<Account, String> lastNameColumn = DataGridUtil.textColumnBuilder(Account::getLastName)
.enabledWhen(Account::isEnabled)
.withSorting(FindAccountRequest.FIELD_NAME_LAST_NAME)
.build();
dataGrid.addResizableColumn(lastNameColumn, "Last Name", 180);

// Email
final Column<Account, String> emailColumn = DataGridUtil.textColumnBuilder(Account::getEmail)
.enabledWhen(Account::isEnabled)
Expand All @@ -196,27 +217,39 @@ private void initTableColumns() {
dataGrid.addResizableColumn(emailColumn, "Email", 250);

// Status
final Column<Account, String> statusColumn = DataGridUtil.textColumnBuilder(Account::getStatus)
.enabledWhen(Account::isEnabled)
.withSorting(FindAccountRequest.FIELD_NAME_STATUS)
.build();
dataGrid.addColumn(statusColumn, "Status", ColumnSizeConstants.MEDIUM_COL);
dataGrid.addColumn(
DataGridUtil.textColumnBuilder(Account::getStatus)
.enabledWhen(Account::isEnabled)
.withSorting(FindAccountRequest.FIELD_NAME_STATUS)
.build(),
DataGridUtil.headingBuilder("Status")
.withToolTip("The status of the account. One of (Enabled|Disabled|Locked|Inactive).")
.build(),
ColumnSizeConstants.SMALL_COL);

// Last Sign In
final Column<Account, String> lastSignInColumn = DataGridUtil.textColumnBuilder((Account account) ->
dateTimeFormatter.format(account.getLastLoginMs()))
.enabledWhen(Account::isEnabled)
.withSorting(FindAccountRequest.FIELD_NAME_LAST_LOGIN_MS)
.build();
dataGrid.addColumn(lastSignInColumn, "Last Sign In", ColumnSizeConstants.DATE_COL);
dataGrid.addColumn(
DataGridUtil.textColumnBuilder((Account account) ->
dateTimeFormatter.format(account.getLastLoginMs()))
.enabledWhen(Account::isEnabled)
.withSorting(FindAccountRequest.FIELD_NAME_LAST_LOGIN_MS)
.build(),
DataGridUtil.headingBuilder("Last Sign In")
.withToolTip("The date/time the user last successfully signed in.")
.build(),
ColumnSizeConstants.DATE_COL);

// Sign In Failures
final Column<Account, String> signInFailuresColumn = DataGridUtil.textColumnBuilder((Account account) ->
"" + account.getLoginFailures())
.enabledWhen(Account::isEnabled)
.withSorting(FindAccountRequest.FIELD_NAME_LOGIN_FAILURES)
.build();
dataGrid.addColumn(signInFailuresColumn, "Sign In Failures", 130);
dataGrid.addColumn(
DataGridUtil.textColumnBuilder((Account account) ->
"" + account.getLoginFailures())
.enabledWhen(Account::isEnabled)
.withSorting(FindAccountRequest.FIELD_NAME_LOGIN_FAILURES)
.build(),
DataGridUtil.headingBuilder("Sign In Failures")
.withToolTip("The number of login failures since the last successful login.")
.build(),
130);

// Comments
final Column<Account, String> commentsColumn = DataGridUtil.textColumnBuilder(Account::getComments)
Expand All @@ -228,6 +261,22 @@ private void initTableColumns() {
DataGridUtil.addEndColumn(dataGrid);
}

private Function<Account, CommandLink> buildOpenUserCommandLink() {
return (Account account) -> {
if (account != null) {
final String userId = account.getUserId();

return new CommandLink(
userId,
"Open user '" + userId + "' on the Users and Groups screen.",
() -> OpenUserOrGroupEvent.fire(
AccountsListPresenter.this, userId));
} else {
return null;
}
};
}

private void fetchData(final Range range,
final Consumer<AccountResultPage> dataConsumer,
final TaskMonitorFactory taskMonitorFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class FindAccountRequest extends BaseCriteria {

public static final String FIELD_NAME_USER_ID = "userId";
public static final String FIELD_NAME_EMAIL = "email";
public static final String FIELD_NAME_FIRST_NAME = "firstName";
public static final String FIELD_NAME_LAST_NAME = "lastName";
public static final String FIELD_NAME_STATUS = "status";
public static final String FIELD_NAME_LAST_LOGIN_MS = "lastLoginMs";
public static final String FIELD_NAME_LOGIN_FAILURES = "loginFailures";
Expand Down
Loading

0 comments on commit f80273a

Please sign in to comment.