Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine: Add button to remove all direct user permissions #967

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,8 @@ public interface CommonApplicationConstants extends Constants {

String removePermission();

String removeDirectSystemPermissionsButtonLabel();

String objectPermission();

String addSystemPermission();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ refreshRate=Refresh Rate
registerDisksLabel=Register Disks
remoteDesktop=Remote Desktop
removeConfirmationPopupMessage=Are you sure you want to remove the following items?
removeDirectSystemPermissionsButtonLabel=Remove Direct System Permissions
removeDisk=Remove
removeInterface=Remove
removePermission=Remove
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ addInstanceImages=\u0421\u043E\u0437\u0434\u0430\u0442\u044C
addItemButtonLabel=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C
addPermission=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C
addSanStorage=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C
addSystemPermission=\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f
addVmHostDevice=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0443\u0441\u0442\u0440\u043E\u0439\u0441\u0442\u0432\u043E
addressSanStorage=\u0410\u0434\u0440\u0435\u0441
admin=\u0410\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0430\u0442\u043E\u0440
Expand Down Expand Up @@ -548,6 +549,7 @@ refreshRate=\u041E\u0441\u0432\u0435\u0436\u0438\u0442\u044C \u043E\u0446\u0435\
registerDisksLabel=\u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0435 \u0434\u0438\u0441\u043A\u0438
remoteDesktop=\u0423\u0434\u0430\u043B\u0451\u043D\u043D\u044B\u0439 \u0440\u0430\u0431\u043E\u0447\u0438\u0439 \u0441\u0442\u043E\u043B
removeConfirmationPopupMessage=\u0412\u044B \u0442\u043E\u0447\u043D\u043E \u0445\u043E\u0442\u0438\u0442\u0435 \u0443\u0434\u0430\u043B\u0438\u0442\u044C \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0438\u0435 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u044B?
removeDirectSystemPermissionsButtonLabel=\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0432\u044b\u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0439
removeDisk=\u0423\u0434\u0430\u043B\u0438\u0442\u044C
removeInterface=\u0423\u0434\u0430\u043B\u0438\u0442\u044C
removePermission=\u0423\u0434\u0430\u043B\u0438\u0442\u044C
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.ovirt.engine.core.common.queries.IdQueryParameters;
import org.ovirt.engine.core.common.queries.QueryReturnValue;
import org.ovirt.engine.core.common.queries.QueryType;
import org.ovirt.engine.core.common.utils.ObjectUtils;
import org.ovirt.engine.ui.frontend.AsyncCallback;
import org.ovirt.engine.ui.frontend.Frontend;
import org.ovirt.engine.ui.uicommonweb.UICommand;
Expand All @@ -29,6 +30,7 @@
public class UserPermissionListModel extends PermissionListModel<DbUser> {

private UICommand addRoleToUserCommand;
private UICommand removeDirectRolesFromUserCommand;

@Inject
public UserPermissionListModel(Provider<AdElementListModel> adElementListModelProvider) {
Expand All @@ -39,6 +41,11 @@ public UserPermissionListModel(Provider<AdElementListModel> adElementListModelPr

setAddRoleToUserCommand(new UICommand("AddRoleToUser", this)); // $NON-NLS-1$
getCommands().add(getAddRoleToUserCommand());

setRemoveDirectRolesFromUserCommand(new UICommand("RemoveDirectRolesFromUser", this)); // $NON-NLS-1$
getCommands().add(getRemoveDirectRolesFromUserCommand());
getItemsChangedEvent().addListener((ev, sender, args) -> updateRemoveDirectPermissionActionAvailability());

updateActionAvailability();
}

Expand Down Expand Up @@ -86,6 +93,45 @@ private void setAddRoleToUserCommand(UICommand value) {
addRoleToUserCommand = value;
}

public UICommand getRemoveDirectRolesFromUserCommand() {
return removeDirectRolesFromUserCommand;
}

private void setRemoveDirectRolesFromUserCommand(UICommand removeDirectRolesFromUserCommand) {
this.removeDirectRolesFromUserCommand = removeDirectRolesFromUserCommand;
}

private void removeAllDirect() {
List<Permission> elementsToRemove = getDirectPermissions();

if (elementsToRemove.isEmpty()) {
return;
}

// Correctly set permissions to delete into the selected items.
setSelectedItem(elementsToRemove.get(0));
setSelectedItems(elementsToRemove);

remove();
0ffer marked this conversation as resolved.
Show resolved Hide resolved
}

private List<Permission> getDirectPermissions() {
List<Permission> directPermissions = new ArrayList<>();

if (ObjectUtils.isEmpty(getItems())) {
return directPermissions;
}

for (Permission item : getItems()) {
if (item.getAdElementId() != null &&
getEntity() != null &&
item.getAdElementId().equals(getEntity().getId())) {
directPermissions.add(item);
}
}
return directPermissions;
}

public void remove() {
if (getWindow() != null) {
return;
Expand Down Expand Up @@ -167,10 +213,18 @@ private void updateActionAvailability() {
getAddCommand().setIsAvailable(false);
}

private void updateRemoveDirectPermissionActionAvailability() {
getRemoveDirectRolesFromUserCommand()
.setIsExecutionAllowed(!getDirectPermissions().isEmpty());
}

@Override
public void executeCommand(UICommand command) {
super.executeCommand(command);

if (command == getRemoveDirectRolesFromUserCommand()) {
removeAllDirect();
}
if (command == getRemoveCommand()) {
remove();
} else if (command == getAddRoleToUserCommand()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public SearchableDetailModelProvider<Permission, UserListModel, UserPermissionLi
@Override
public AbstractModelBoundPopupPresenterWidget<? extends ConfirmationModel, ?> getConfirmModelPopup(UserPermissionListModel source,
UICommand lastExecutedCommand) {
if (lastExecutedCommand == getModel().getRemoveCommand()) {
if (lastExecutedCommand == getModel().getRemoveCommand() || lastExecutedCommand == getModel().getRemoveDirectRolesFromUserCommand()) {
return removeConfirmPopupProvider.get();
} else {
return super.getConfirmModelPopup(source, lastExecutedCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ protected UICommand resolveCommand() {
return getDetailModel().getAddRoleToUserCommand();
}
});
addActionButton(new UiCommandButtonDefinition<DbUser, Permission>(getSharedEventBus(), constants.removeDirectSystemPermissionsButtonLabel()) {
@Override
protected UICommand resolveCommand() {
return getDetailModel().getRemoveDirectRolesFromUserCommand();
}
});
super.initializeButtons();
}
}