Search in sources :

Example 1 with UpdateUserPermissions

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

the class DbUserEditorActions method delete.

public void delete() {
    panel.setModified(true);
    final UserPermissionDTO model = grid.getSelectionModel().getSelectedItem();
    model.setAllowView(false);
    model.setAllowViewAll(false);
    model.setAllowEdit(false);
    model.setAllowEditAll(false);
    model.setAllowDesign(false);
    model.setAllowManageAllUsers(false);
    model.setAllowManageUsers(false);
    dispatcher.execute(new UpdateUserPermissions(db.getId(), model), new MaskingAsyncMonitor(panel, I18N.CONSTANTS.deleting()), new AsyncCallback<VoidResult>() {

        @Override
        public void onFailure(Throwable caught) {
            panel.setModified(false);
        }

        @Override
        public void onSuccess(VoidResult result) {
            store.remove(model);
            panel.setModified(false);
        }
    });
}
Also used : VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult) UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) MaskingAsyncMonitor(org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO)

Example 2 with UpdateUserPermissions

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

the class DbUserEditorActions method save.

public void save(final NavigationCallback callback) {
    BatchCommand batch = new BatchCommand();
    for (Record record : store.getModifiedRecords()) {
        batch.add(new UpdateUserPermissions(db.getId(), (UserPermissionDTO) record.getModel()));
    }
    dispatcher.execute(batch, new MaskingAsyncMonitor(panel, I18N.CONSTANTS.saving()), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
            // handled by monitor
            if (callback != null) {
                callback.onDecided(false);
            }
        }

        @Override
        public void onSuccess(BatchResult result) {
            store.commitChanges();
            panel.setModified(false);
            if (callback != null) {
                callback.onDecided(true);
            }
        }
    });
}
Also used : UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) MaskingAsyncMonitor(org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor) BatchCommand(org.activityinfo.legacy.shared.command.BatchCommand) Record(com.extjs.gxt.ui.client.store.Record) BatchResult(org.activityinfo.legacy.shared.command.result.BatchResult) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO)

Example 3 with UpdateUserPermissions

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

the class UpdateUserPermissionsHandlerTest method testVerifyAuthorityForViewByOtherPartner.

@Test
public void testVerifyAuthorityForViewByOtherPartner() throws IllegalAccessCommandException {
    UserPermission executingUserPermissions = new UserPermission();
    executingUserPermissions.setPartner(IRC);
    executingUserPermissions.setAllowManageUsers(true);
    executingUserPermissions.setAllowManageAllUsers(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 4 with UpdateUserPermissions

use of org.activityinfo.legacy.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
 */
@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);
    assertThat(reUser.getEmail(), equalTo("bavon@nrcdrc.org"));
    assertThat(reUser.getAllowDesign(), equalTo(true));
}
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)

Example 5 with UpdateUserPermissions

use of org.activityinfo.legacy.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.legacy.shared.command.UpdateUserPermissions) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) 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