Search in sources :

Example 6 with UserPermissionDTO

use of org.activityinfo.shared.dto.UserPermissionDTO 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 7 with UserPermissionDTO

use of org.activityinfo.shared.dto.UserPermissionDTO 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)

Example 8 with UserPermissionDTO

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

Example 9 with UserPermissionDTO

use of org.activityinfo.shared.dto.UserPermissionDTO in project activityinfo by bedatadriven.

the class DbUserEditor method createGrid.

private void createGrid() {
    loader = new BasePagingLoader<UserResult>(new UserProxy());
    store = new ListStore<UserPermissionDTO>(loader);
    store.setKeyProvider(new ModelKeyProvider<UserPermissionDTO>() {

        @Override
        public String getKey(UserPermissionDTO model) {
            return model.getEmail();
        }
    });
    store.addListener(Store.Update, new Listener<StoreEvent<UserPermissionDTO>>() {

        @Override
        public void handleEvent(StoreEvent<UserPermissionDTO> event) {
            toolBar.setDirty(!store.getModifiedRecords().isEmpty());
        }
    });
    final List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
    columns.add(new ColumnConfig("name", I18N.CONSTANTS.name(), 100));
    columns.add(new ColumnConfig("email", I18N.CONSTANTS.email(), 150));
    columns.add(new ColumnConfig("partner", I18N.CONSTANTS.partner(), 150));
    PermissionCheckConfig allowView = new PermissionCheckConfig("allowViewSimple", I18N.CONSTANTS.allowView(), 75);
    allowView.setDataIndex("allowView");
    allowView.setToolTip(I18N.CONSTANTS.allowViewLong());
    columns.add(allowView);
    PermissionCheckConfig allowEdit = new PermissionCheckConfig("allowEditSimple", I18N.CONSTANTS.allowEdit(), 75);
    allowEdit.setDataIndex("allowEdit");
    allowEdit.setToolTip(I18N.CONSTANTS.allowEditLong());
    columns.add(allowEdit);
    PermissionCheckConfig allowViewAll = new PermissionCheckConfig("allowViewAll", I18N.CONSTANTS.allowViewAll(), 75);
    allowViewAll.setToolTip(I18N.CONSTANTS.allowViewAllLong());
    columns.add(allowViewAll);
    PermissionCheckConfig allowEditAll = new PermissionCheckConfig("allowEditAll", I18N.CONSTANTS.allowEditAll(), 75);
    allowEditAll.setToolTip(I18N.CONSTANTS.allowEditAllLong());
    columns.add(allowEditAll);
    PermissionCheckConfig allowManageUsers = null;
    allowManageUsers = new PermissionCheckConfig("allowManageUsers", I18N.CONSTANTS.allowManageUsers(), 150);
    columns.add(allowManageUsers);
    PermissionCheckConfig allowManageAllUsers = new PermissionCheckConfig("allowManageAllUsers", I18N.CONSTANTS.manageAllUsers(), 150);
    columns.add(allowManageAllUsers);
    // only users with the right to design them selves can change the design
    // attribute
    PermissionCheckConfig allowDesign = new PermissionCheckConfig("allowDesign", I18N.CONSTANTS.allowDesign(), 75);
    allowDesign.setToolTip(I18N.CONSTANTS.allowDesignLong());
    columns.add(allowDesign);
    grid = new Grid<UserPermissionDTO>(store, new ColumnModel(columns));
    grid.setLoadMask(true);
    grid.setSelectionModel(new GridSelectionModel<UserPermissionDTO>());
    grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<UserPermissionDTO>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<UserPermissionDTO> se) {
            onSelectionChanged(se.getSelectedItem());
        }
    });
    grid.addPlugin(allowEdit);
    grid.addPlugin(allowViewAll);
    grid.addPlugin(allowEditAll);
    grid.addPlugin(allowManageUsers);
    grid.addPlugin(allowManageAllUsers);
    grid.addPlugin(allowDesign);
    add(grid);
}
Also used : ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) CheckColumnConfig(com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig) ArrayList(java.util.ArrayList) UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO) StoreEvent(com.extjs.gxt.ui.client.store.StoreEvent) UserResult(org.activityinfo.shared.command.result.UserResult) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel)

Example 10 with UserPermissionDTO

use of org.activityinfo.shared.dto.UserPermissionDTO in project activityinfo by bedatadriven.

the class DbUserEditor method delete.

private void delete() {
    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(this, I18N.CONSTANTS.deleting()), new AsyncCallback<VoidResult>() {

        @Override
        public void onFailure(Throwable caught) {
        }

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

Aggregations

UserPermissionDTO (org.activityinfo.shared.dto.UserPermissionDTO)15 UpdateUserPermissions (org.activityinfo.shared.command.UpdateUserPermissions)9 Test (org.junit.Test)7 UserPermission (org.activityinfo.server.database.hibernate.entity.UserPermission)6 UserResult (org.activityinfo.shared.command.result.UserResult)4 ArrayList (java.util.ArrayList)2 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)2 OnDataSet (org.activityinfo.server.database.OnDataSet)2 GetUsers (org.activityinfo.shared.command.GetUsers)2 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)2 Record (com.extjs.gxt.ui.client.store.Record)1 StoreEvent (com.extjs.gxt.ui.client.store.StoreEvent)1 CheckColumnConfig (com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig)1 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)1 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)1 Query (javax.persistence.Query)1 User (org.activityinfo.server.database.hibernate.entity.User)1 UserDatabase (org.activityinfo.server.database.hibernate.entity.UserDatabase)1 BatchCommand (org.activityinfo.shared.command.BatchCommand)1 BatchResult (org.activityinfo.shared.command.result.BatchResult)1