Skip to content

Commit

Permalink
#4594 Fix various perms UI issues
Browse files Browse the repository at this point in the history
  • Loading branch information
stroomdev66 committed Nov 12, 2024
1 parent 8b48ec1 commit 3dc146d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import stroom.data.grid.client.PagerView;
import stroom.dispatch.client.RestErrorHandler;
import stroom.dispatch.client.RestFactory;
import stroom.explorer.client.presenter.DocumentTypeCache;
import stroom.explorer.shared.DocumentTypes;
import stroom.query.api.v2.ExpressionOperator;
import stroom.security.shared.AppPermission;
import stroom.security.shared.AppPermissionResource;
Expand Down Expand Up @@ -62,7 +60,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;

public class AppUserPermissionsListPresenter
Expand All @@ -76,26 +73,25 @@ public class AppUserPermissionsListPresenter
private final MyDataGrid<AppUserPermissions> dataGrid;
private final PagerView pagerView;
private RestDataProvider<AppUserPermissions, ResultPage<AppUserPermissions>> dataProvider;
private DocumentTypes documentTypes;
private final MultiSelectionModelImpl<AppUserPermissions> selectionModel;
private final DataGridSelectionEventManager<AppUserPermissions> selectionEventManager;


@Inject
public AppUserPermissionsListPresenter(final EventBus eventBus,
final QuickFilterPageView view,
final PagerView pagerView,
final RestFactory restFactory,
final UiConfigCache uiConfigCache,
final DocumentTypeCache documentTypeCache) {
final UiConfigCache uiConfigCache) {
super(eventBus, view);
this.restFactory = restFactory;
this.pagerView = pagerView;
documentTypeCache.fetch(dt -> this.documentTypes = dt, this);

dataGrid = new MyDataGrid<>();
selectionModel = new MultiSelectionModelImpl<>(dataGrid);
selectionEventManager = new DataGridSelectionEventManager<>(dataGrid, selectionModel, false);
DataGridSelectionEventManager<AppUserPermissions> selectionEventManager = new DataGridSelectionEventManager<>(
dataGrid,
selectionModel,
false);
dataGrid.setSelectionModel(selectionModel, selectionEventManager);
pagerView.setDataWidget(dataGrid);

Expand Down Expand Up @@ -192,11 +188,11 @@ public Preset getValue(final AppUserPermissions documentUserPermissions) {
new Column<AppUserPermissions, String>(new TextCell()) {
@Override
public String getValue(final AppUserPermissions appUserPermissions) {
return getUserOrGroupName(appUserPermissions);
return appUserPermissions.getUserRef().getDisplayName();
}
};
nameCol.setSortable(true);
dataGrid.addResizableColumn(nameCol, "User or Group", 400);
dataGrid.addResizableColumn(nameCol, "Display Name", 400);

// Permissions
final Column<AppUserPermissions, SafeHtml> permissionCol =
Expand All @@ -205,25 +201,25 @@ public String getValue(final AppUserPermissions appUserPermissions) {
public SafeHtml getValue(final AppUserPermissions appUserPermissions) {
final DescriptionBuilder sb = new DescriptionBuilder();
if (appUserPermissions.getPermissions() != null &&
appUserPermissions.getPermissions().contains(AppPermission.ADMINISTRATOR)) {
appUserPermissions.getPermissions().contains(AppPermission.ADMINISTRATOR)) {
sb.addLine(true, false, AppPermission.ADMINISTRATOR.getDisplayValue());
} else if (appUserPermissions.getInherited() != null &&
appUserPermissions.getInherited().contains(AppPermission.ADMINISTRATOR)) {
appUserPermissions.getInherited().contains(AppPermission.ADMINISTRATOR)) {
sb.addLine(true, true, AppPermission.ADMINISTRATOR.getDisplayValue());
} else {
boolean notEmpty = false;
boolean lastInherited = false;
for (final AppPermission permission : AppPermission.LIST) {
if (appUserPermissions.getPermissions() != null &&
appUserPermissions.getPermissions().contains(permission)) {
appUserPermissions.getPermissions().contains(permission)) {
if (notEmpty) {
sb.addLine(false, lastInherited, ", ");
}
sb.addLine(permission.getDisplayValue());
notEmpty = true;
lastInherited = false;
} else if (appUserPermissions.getInherited() != null &&
appUserPermissions.getInherited().contains(permission)) {
appUserPermissions.getInherited().contains(permission)) {
if (notEmpty) {
sb.addLine(false, lastInherited, ", ");
}
Expand Down Expand Up @@ -276,18 +272,6 @@ public SafeHtml getValue(final AppUserPermissions appUserPermissions) {
dataGrid.getColumnSortList().push(nameCol);
}

private String getUserOrGroupName(AppUserPermissions appUserPermissions) {
final UserRef userRef = appUserPermissions.getUserRef();
if (userRef.getDisplayName() != null) {
if (!Objects.equals(userRef.getDisplayName(), userRef.getSubjectId())) {
return userRef.getDisplayName() + " (" + userRef.getSubjectId() + ")";
} else {
return userRef.getDisplayName();
}
}
return userRef.getSubjectId();
}

public ButtonView addButton(final Preset preset) {
return pagerView.addButton(preset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;

Expand Down Expand Up @@ -202,19 +201,11 @@ public Preset getValue(final DocumentUserPermissions documentUserPermissions) {
new Column<DocumentUserPermissions, String>(new TextCell()) {
@Override
public String getValue(final DocumentUserPermissions documentUserPermissions) {
final UserRef userRef = documentUserPermissions.getUserRef();
if (userRef.getDisplayName() != null) {
if (!Objects.equals(userRef.getDisplayName(), userRef.getSubjectId())) {
return userRef.getDisplayName() + " (" + userRef.getSubjectId() + ")";
} else {
return userRef.getDisplayName();
}
}
return userRef.getSubjectId();
return documentUserPermissions.getUserRef().getDisplayName();
}
};
nameCol.setSortable(true);
dataGrid.addResizableColumn(nameCol, "User or Group", 400);
dataGrid.addResizableColumn(nameCol, "Display Name", 400);

// Permission
final Column<DocumentUserPermissions, SafeHtml> permissionCol =
Expand Down Expand Up @@ -250,7 +241,7 @@ public SafeHtml getValue(final DocumentUserPermissions documentUserPermissions)
final Set<String> inherited = documentUserPermissions
.getInheritedDocumentCreatePermissions();
if ((explicit != null && explicit.size() > 0) ||
(inherited != null && inherited.size() > 0)) {
(inherited != null && inherited.size() > 0)) {

if (explicit != null && explicit.size() == documentTypes.getTypes().size()) {
sb.addLine(true, false, "All");
Expand All @@ -271,7 +262,7 @@ public SafeHtml getValue(final DocumentUserPermissions documentUserPermissions)
lastInherited = false;
notEmpty = true;
} else if (inherited != null &&
inherited.contains(documentType.getType())) {
inherited.contains(documentType.getType())) {
if (notEmpty) {
sb.addLine(false, lastInherited, ", ");
}
Expand Down

0 comments on commit 3dc146d

Please sign in to comment.