Skip to content

Commit

Permalink
#4379 Improve Stroom permission model
Browse files Browse the repository at this point in the history
  • Loading branch information
stroomdev66 committed Aug 12, 2024
1 parent c403ed3 commit 433e8ab
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,8 @@ public void setKeyboardSelectedRow(final int row, boolean stealFocus) {
public void setFocusText(final boolean focusText) {
this.focusText = focusText;
}

public MultiSelectionModelImpl<FindResult> getSelectionModel() {
return selectionModel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@

package stroom.security.client;

import stroom.core.client.MenuKeys;
import stroom.document.client.event.ShowPermissionsDialogEvent;
import stroom.explorer.shared.ExplorerConstants;
import stroom.menubar.client.event.BeforeRevealMenubarEvent;
import stroom.node.client.NodeToolsPlugin;
import stroom.query.api.v2.ExpressionOperator;
import stroom.query.api.v2.ExpressionTerm;
import stroom.query.api.v2.ExpressionTerm.Condition;
import stroom.security.client.api.ClientSecurityContext;
import stroom.security.client.presenter.DocumentPermissionsEditPresenter;
import stroom.security.client.presenter.DocumentPermissionsPresenter;
import stroom.security.shared.AppPermission;
import stroom.security.shared.DocumentPermissionFields;
import stroom.svg.shared.SvgImage;
import stroom.widget.menu.client.presenter.IconMenuItem.Builder;
import stroom.widget.util.client.KeyBinding.Action;

import com.google.gwt.inject.client.AsyncProvider;
Expand All @@ -36,11 +45,15 @@
public class ManageUserPlugin extends NodeToolsPlugin {


private final AsyncProvider<DocumentPermissionsEditPresenter> documentPermissionsEditPresenterProvider;

@Inject
public ManageUserPlugin(final EventBus eventBus,
final ClientSecurityContext securityContext,
final AsyncProvider<DocumentPermissionsPresenter> documentPermissionsPresenterProvider) {
final AsyncProvider<DocumentPermissionsPresenter> documentPermissionsPresenterProvider,
final AsyncProvider<DocumentPermissionsEditPresenter> documentPermissionsEditPresenterProvider) {
super(eventBus, securityContext);
this.documentPermissionsEditPresenterProvider = documentPermissionsEditPresenterProvider;
// this.usersAndGroupsPresenterProvider = usersAndGroupsPresenterProvider;
//
// Add handler for showing the document permissions dialog in the explorer tree context menu
Expand Down Expand Up @@ -73,6 +86,7 @@ public void onFailure(final Throwable caught) {
// }
}


private AppPermission getRequiredAppPermission() {
return AppPermission.MANAGE_USERS_PERMISSION;
}
Expand All @@ -83,18 +97,39 @@ private Action getOpenAction() {

@Override
protected void addChildItems(final BeforeRevealMenubarEvent event) {
// if (getSecurityContext().hasAppPermission(getRequiredAppPermission())) {
// // Menu item for the user/group permissions dialog
// MenuKeys.addSecurityMenu(event.getMenuItems());
// event.getMenuItems().addMenuItem(MenuKeys.SECURITY_MENU,
// new IconMenuItem.Builder()
// .priority(1)
// .icon(SvgImage.USER)
// .text("Application Permissions")
// .action(getOpenAction())
// .command(this::open)
// .build());
// }
if (getSecurityContext().hasAppPermission(getRequiredAppPermission())) {
// Menu item for the user/group permissions dialog
MenuKeys.addSecurityMenu(event.getMenuItems());
event.getMenuItems().addMenuItem(MenuKeys.SECURITY_MENU,
new Builder()
.priority(1)
.icon(SvgImage.LOCKED)
.text("Document Permissions")
.action(getOpenAction())
.command(() -> documentPermissionsEditPresenterProvider.get(
new AsyncCallback<DocumentPermissionsEditPresenter>() {
@Override
public void onSuccess(final DocumentPermissionsEditPresenter presenter) {
final ExpressionTerm term = new ExpressionTerm(
true,
DocumentPermissionFields.DESCENDANTS.getFldName(),
Condition.OF_DOC_REF,
null,
ExplorerConstants.SYSTEM_DOC_REF);
final ExpressionOperator operator = ExpressionOperator
.builder()
.addTerm(term)
.build();
presenter.show(operator, () -> {
});
}

@Override
public void onFailure(final Throwable caught) {
}
}))
.build());
}
}

// private void open() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import stroom.explorer.client.presenter.DocSelectionBoxPresenter;
import stroom.explorer.client.presenter.DocumentListPresenter;
import stroom.explorer.client.presenter.DocumentTypeCache;
import stroom.explorer.client.presenter.FindDocResultListHandler;
import stroom.explorer.shared.DocumentType;
import stroom.explorer.shared.ExplorerResource;
import stroom.explorer.shared.FindResult;
import stroom.query.api.v2.ExpressionOperator;
import stroom.query.api.v2.ExpressionOperator.Op;
import stroom.query.api.v2.ExpressionTerm;
Expand Down Expand Up @@ -51,7 +53,6 @@

import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import javax.inject.Inject;
import javax.inject.Provider;

Expand All @@ -65,10 +66,11 @@ public class DocumentPermissionsEditPresenter
private final DocSelectionBoxPresenter docSelectionBoxPresenter;
private final UserRefSelectionBoxPresenter userRefSelectionBoxPresenter;
private final DocumentListPresenter documentListPresenter;
private final Provider<DocumentCreatePermissionsListPresenter>
documentCreatePermissionsListPresenterProvider;
private final Provider<DocumentCreatePermissionsListPresenter> documentCreatePermissionsListPresenterProvider;
private final Provider<DocumentPermissionsPresenter> documentPermissionsPresenterProvider;
private final RestFactory restFactory;
private final ButtonView docFilter;
private final ButtonView docView;
private ExpressionOperator expression;

@Inject
Expand All @@ -78,6 +80,8 @@ public DocumentPermissionsEditPresenter(final EventBus eventBus,
final DocumentListPresenter documentListPresenter,
final Provider<DocumentCreatePermissionsListPresenter>
documentCreatePermissionsListPresenterProvider,
final Provider<DocumentPermissionsPresenter>
documentPermissionsPresenterProvider,
final DocSelectionBoxPresenter docSelectionBoxPresenter,
final UserRefSelectionBoxPresenter userRefSelectionBoxPresenter,
final RestFactory restFactory,
Expand All @@ -88,20 +92,39 @@ public DocumentPermissionsEditPresenter(final EventBus eventBus,
this.docSelectionBoxPresenter = docSelectionBoxPresenter;
this.userRefSelectionBoxPresenter = userRefSelectionBoxPresenter;
this.documentCreatePermissionsListPresenterProvider = documentCreatePermissionsListPresenterProvider;
this.documentPermissionsPresenterProvider = documentPermissionsPresenterProvider;
this.docFilterPresenterProvider = docFilterPresenterProvider;

view.setDocList(documentListPresenter.getView());
view.setUiHandlers(this);

// Filter
docFilter = documentListPresenter.getView().addButton(SvgPresets.FILTER);
docView = documentListPresenter.getView().addButton(SvgPresets.LOCKED_AMBER);
docView.setEnabled(false);
expression = ExpressionOperator.builder().op(Op.AND).build();

documentTypeCache.fetch(types -> {
getView().setDocTypes(types.getTypes());
}, this);
getView().setDocRefSelection(docSelectionBoxPresenter.getView());
getView().setUserRefSelection(userRefSelectionBoxPresenter.getView());

documentListPresenter.setFindResultListHandler(new FindDocResultListHandler() {
@Override
public void openDocument(final FindResult match) {
final FindResult selected = documentListPresenter.getSelected();
if (match != null) {
documentPermissionsPresenterProvider.get().show(match.getDocRef());
}
docView.setEnabled(match != null);
}

@Override
public void focus() {

}
});
}

@Override
Expand Down Expand Up @@ -148,19 +171,39 @@ protected void onBind() {
.onHideRequest(handler)
.fire();
}));

registerHandler(documentListPresenter.getSelectionModel().addSelectionHandler(e -> {
final FindResult selected = documentListPresenter.getSelected();
// if (selected != null) {
// if (e.getSelectionType().isDoubleSelect()) {
// documentPermissionsPresenterProvider.get().show(selected.getDocRef());
// }
// }
docView.setEnabled(selected != null);
}));
registerHandler(docView.addClickHandler(e -> {
final FindResult selected = documentListPresenter.getSelected();
if (selected != null) {
documentPermissionsPresenterProvider.get().show(selected.getDocRef());
}
}));
}

public void show(final DocRef docRef, final Runnable onClose) {
if (docRef != null) {
docSelectionBoxPresenter.setSelectedEntityReference(docRef);
final ExpressionTerm term = new ExpressionTerm(
true,
DocumentPermissionFields.DOCUMENT.getFldName(),
Condition.IS_DOC_REF,
null,
docRef);
show(ExpressionOperator.builder().op(Op.AND).addTerm(term).build(), onClose);
}
}

final ExpressionTerm term = new ExpressionTerm(
true,
DocumentPermissionFields.DOCUMENT.getFldName(),
Condition.IS_DOC_REF,
null,
docRef);
expression = ExpressionOperator.builder().op(Op.AND).addTerm(term).build();

docSelectionBoxPresenter.setSelectedEntityReference(docRef);
public void show(final ExpressionOperator expression, final Runnable onClose) {
this.expression = expression;

// We only want to see documents tha the current user is effectively the owner of as they can't change
// permissions on anything else.
Expand Down

0 comments on commit 433e8ab

Please sign in to comment.