Search in sources :

Example 1 with UpdateUserPermissions

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

the class DbUserEditor method add.

private void add() {
    final UserForm form = new UserForm(db);
    final FormDialogImpl dlg = new FormDialogImpl(form);
    dlg.setHeading(I18N.CONSTANTS.newUser());
    dlg.setWidth(400);
    dlg.setHeight(300);
    final String host = Window.Location.getHostName();
    dlg.show(new FormDialogCallback() {

        @Override
        public void onValidated() {
            dispatcher.execute(new UpdateUserPermissions(db, form.getUser(), host), dlg, new AsyncCallback<VoidResult>() {

                @Override
                public void onFailure(Throwable caught) {
                }

                @Override
                public void onSuccess(VoidResult result) {
                    loader.load();
                    dlg.hide();
                }
            });
        }
    });
}
Also used : FormDialogImpl(org.activityinfo.client.page.common.dialog.FormDialogImpl) FormDialogCallback(org.activityinfo.client.page.common.dialog.FormDialogCallback) VoidResult(org.activityinfo.shared.command.result.VoidResult) UpdateUserPermissions(org.activityinfo.shared.command.UpdateUserPermissions) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) UserForm(org.activityinfo.client.page.config.form.UserForm)

Example 2 with UpdateUserPermissions

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

the class UpdateUserPermissionsHandlerTest method ownerCanAddUser.

@Test
public void ownerCanAddUser() throws Exception {
    UserPermissionDTO user = new UserPermissionDTO();
    user.setEmail("other@foobar");
    user.setName("Foo Bar");
    user.setPartner(NRC_DTO);
    user.setAllowView(true);
    UpdateUserPermissions cmd = new UpdateUserPermissions(1, user);
    handler.execute(cmd, owner);
    assertThat(mailer.sentMails.size(), equalTo(1));
}
Also used : UpdateUserPermissions(org.activityinfo.shared.command.UpdateUserPermissions) UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO) Test(org.junit.Test)

Example 3 with UpdateUserPermissions

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

the class UpdateUserPermissionsHandlerTest method testOwnerUpdate.

/**
 * Verifies that the owner of a database can update an existing users permission
 *
 * @throws CommandException
 */
@Test
@OnDataSet("/dbunit/schema1.db.xml")
public void testOwnerUpdate() throws CommandException {
    setUser(1);
    UserPermissionDTO user = new UserPermissionDTO();
    user.setEmail("bavon@nrcdrc.org");
    user.setPartner(new PartnerDTO(1, "NRC"));
    user.setAllowView(true);
    user.setAllowViewAll(false);
    user.setAllowEdit(true);
    user.setAllowEdit(false);
    user.setAllowDesign(true);
    execute(new UpdateUserPermissions(1, user));
    UserResult result = execute(new GetUsers(1));
    UserPermissionDTO reUser = result.getData().get(0);
    Assert.assertEquals("bavon@nrcdrc.org", reUser.getEmail());
    Assert.assertTrue("design rights", user.getAllowDesign());
}
Also used : PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) UpdateUserPermissions(org.activityinfo.shared.command.UpdateUserPermissions) UserResult(org.activityinfo.shared.command.result.UserResult) GetUsers(org.activityinfo.shared.command.GetUsers) UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 4 with UpdateUserPermissions

use of org.activityinfo.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.shared.command.UpdateUserPermissions) UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission) Test(org.junit.Test)

Example 5 with UpdateUserPermissions

use of org.activityinfo.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.shared.command.UpdateUserPermissions) UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission) Test(org.junit.Test)

Aggregations

UpdateUserPermissions (org.activityinfo.shared.command.UpdateUserPermissions)10 UserPermissionDTO (org.activityinfo.shared.dto.UserPermissionDTO)9 Test (org.junit.Test)7 UserPermission (org.activityinfo.server.database.hibernate.entity.UserPermission)4 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)2 OnDataSet (org.activityinfo.server.database.OnDataSet)2 GetUsers (org.activityinfo.shared.command.GetUsers)2 UserResult (org.activityinfo.shared.command.result.UserResult)2 VoidResult (org.activityinfo.shared.command.result.VoidResult)2 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)2 Record (com.extjs.gxt.ui.client.store.Record)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 FormDialogCallback (org.activityinfo.client.page.common.dialog.FormDialogCallback)1 FormDialogImpl (org.activityinfo.client.page.common.dialog.FormDialogImpl)1 UserForm (org.activityinfo.client.page.config.form.UserForm)1 BatchCommand (org.activityinfo.shared.command.BatchCommand)1 BatchResult (org.activityinfo.shared.command.result.BatchResult)1