Search in sources :

Example 6 with UpdateUserPermissions

use of org.activityinfo.legacy.shared.command.UpdateUserPermissions in project activityinfo by bedatadriven.

the class UpdateUserPermissionsHandlerTest method testFailingVerifyAuthorityForView.

@Test(expected = IllegalAccessCommandException.class)
public void testFailingVerifyAuthorityForView() throws IllegalAccessCommandException {
    UserPermission executingUserPermissions = new UserPermission();
    executingUserPermissions.setPartner(IRC);
    executingUserPermissions.setAllowManageUsers(true);
    UserPermissionDTO dto = new UserPermissionDTO();
    dto.setPartner(NRC_DTO);
    dto.setAllowView(true);
    dto.setAllowEdit(true);
    UpdateUserPermissions cmd = new UpdateUserPermissions(1, dto);
    UpdateUserPermissionsHandler.verifyAuthority(cmd, executingUserPermissions);
}
Also used : UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) Test(org.junit.Test)

Example 7 with UpdateUserPermissions

use of org.activityinfo.legacy.shared.command.UpdateUserPermissions in project activityinfo by bedatadriven.

the class UpdateUserPermissionsHandlerTest method testVerifyAuthorityForViewPermissions.

/**
 * Asserts that someone with ManageUsersPermission will be permitted to
 * grant some one edit rights.
 */
@Test
public void testVerifyAuthorityForViewPermissions() throws IllegalAccessCommandException {
    UserPermission executingUserPermissions = new UserPermission();
    executingUserPermissions.setPartner(NRC);
    executingUserPermissions.setAllowManageUsers(true);
    UserPermissionDTO dto = new UserPermissionDTO();
    dto.setPartner(NRC_DTO);
    dto.setAllowView(true);
    UpdateUserPermissions cmd = new UpdateUserPermissions(1, dto);
    UpdateUserPermissionsHandler.verifyAuthority(cmd, executingUserPermissions);
}
Also used : UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) Test(org.junit.Test)

Example 8 with UpdateUserPermissions

use of org.activityinfo.legacy.shared.command.UpdateUserPermissions in project activityinfo by bedatadriven.

the class DbUserEditorActions method showDialog.

private void showDialog(final UserForm form, final boolean newUser) {
    final FormDialogImpl dlg = new FormDialogImpl(form);
    dlg.setHeadingText(newUser ? I18N.CONSTANTS.newUser() : I18N.CONSTANTS.editUser());
    dlg.setWidth(400);
    dlg.setHeight(300);
    dlg.getCancelButton().addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent buttonEvent) {
            panel.setModified(false);
        }
    });
    final String host = Window.Location.getHostName();
    dlg.show(new FormDialogCallback() {

        @Override
        public void onValidated() {
            try {
                UpdateUserPermissions command = new UpdateUserPermissions(db, form.getUser(), host);
                command.setNewUser(newUser);
                dispatcher.execute(command, new AsyncCallback<VoidResult>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        if (caught instanceof UserExistsException) {
                            MessageBox.alert(I18N.CONSTANTS.userExistsTitle(), I18N.CONSTANTS.userExistsMessage(), null);
                        } else {
                            MessageBox.alert(I18N.CONSTANTS.serverError(), I18N.CONSTANTS.errorUnexpectedOccured(), null);
                        }
                    }

                    @Override
                    public void onSuccess(VoidResult result) {
                        loader.load();
                        panel.setModified(false);
                        dlg.hide();
                    }
                });
            } catch (FolderAssignmentException excp) {
                MessageBox.alert(I18N.CONSTANTS.noFolderAssignmentTitle(), excp.getMessage(), null);
            } catch (PermissionAssignmentException excp) {
                MessageBox.alert(I18N.CONSTANTS.permissionAssignmentErrorTitle(), excp.getMessage(), null);
            }
        }
    });
}
Also used : FormDialogImpl(org.activityinfo.ui.client.page.common.dialog.FormDialogImpl) FormDialogCallback(org.activityinfo.ui.client.page.common.dialog.FormDialogCallback) VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult) UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) PermissionAssignmentException(org.activityinfo.ui.client.page.config.form.PermissionAssignmentException) UserExistsException(org.activityinfo.legacy.shared.command.result.UserExistsException) FolderAssignmentException(org.activityinfo.ui.client.page.config.form.FolderAssignmentException) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent)

Example 9 with UpdateUserPermissions

use of org.activityinfo.legacy.shared.command.UpdateUserPermissions in project activityinfo by bedatadriven.

the class UpdateUserPermissionsHandlerTest method testVerifyAuthorityForEditPermissions.

/**
 * Asserts that someone with ManageUsersPermission will be permitted to
 * grant some one edit rights.
 */
@Test
public void testVerifyAuthorityForEditPermissions() throws IllegalAccessCommandException {
    UserPermission executingUserPermissions = new UserPermission();
    executingUserPermissions.setPartner(NRC);
    executingUserPermissions.setAllowManageUsers(true);
    UserPermissionDTO dto = new UserPermissionDTO();
    dto.setPartner(NRC_DTO);
    dto.setAllowView(true);
    dto.setAllowEdit(true);
    UpdateUserPermissions cmd = new UpdateUserPermissions(1, dto);
    UpdateUserPermissionsHandler.verifyAuthority(cmd, executingUserPermissions);
}
Also used : UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) Test(org.junit.Test)

Example 10 with UpdateUserPermissions

use of org.activityinfo.legacy.shared.command.UpdateUserPermissions in project activityinfo by bedatadriven.

the class UpdateUserPermissionsHandlerTest method testAuthorizedCreate.

/**
 * Verifies that a user with the manageUsers permission can add another user to the UserDatabase
 */
@Test
@OnDataSet("/dbunit/schema1.db.xml")
public void testAuthorizedCreate() throws CommandException {
    setUser(2);
    UserPermissionDTO user = new UserPermissionDTO();
    user.setEmail("ralph@lauren.com");
    user.setName("Ralph");
    user.setPartner(new PartnerDTO(1, "NRC"));
    user.setAllowView(true);
    user.setAllowEdit(true);
    UpdateUserPermissions cmd = new UpdateUserPermissions(1, user);
    execute(cmd);
    UserResult result = execute(new GetUsers(1));
    assertThat(result.getTotalLength(), equalTo(1));
    UserPermissionDTO ralph = result.getData().get(0);
    assertThat(ralph.getEmail(), equalTo("ralph@lauren.com"));
    assertThat(ralph.getAllowEdit(), equalTo(true));
    assertThat(ralph.hasFolderLimitation(), equalTo(false));
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) GetUsers(org.activityinfo.legacy.shared.command.GetUsers) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)11 UserPermissionDTO (org.activityinfo.legacy.shared.model.UserPermissionDTO)10 Test (org.junit.Test)8 GetUsers (org.activityinfo.legacy.shared.command.GetUsers)3 UserResult (org.activityinfo.legacy.shared.command.result.UserResult)3 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)3 OnDataSet (org.activityinfo.server.database.OnDataSet)3 VoidResult (org.activityinfo.legacy.shared.command.result.VoidResult)2 MaskingAsyncMonitor (org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor)2 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)1 Record (com.extjs.gxt.ui.client.store.Record)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 BatchCommand (org.activityinfo.legacy.shared.command.BatchCommand)1 BatchResult (org.activityinfo.legacy.shared.command.result.BatchResult)1 UserExistsException (org.activityinfo.legacy.shared.command.result.UserExistsException)1 FolderDTO (org.activityinfo.legacy.shared.model.FolderDTO)1 FormDialogCallback (org.activityinfo.ui.client.page.common.dialog.FormDialogCallback)1 FormDialogImpl (org.activityinfo.ui.client.page.common.dialog.FormDialogImpl)1 FolderAssignmentException (org.activityinfo.ui.client.page.config.form.FolderAssignmentException)1 PermissionAssignmentException (org.activityinfo.ui.client.page.config.form.PermissionAssignmentException)1