Search in sources :

Example 11 with UserPermissionDTO

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

the class DbUserEditor method save.

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

        @Override
        public void onFailure(Throwable caught) {
        // handled by monitor
        }

        @Override
        public void onSuccess(BatchResult result) {
            store.commitChanges();
        }
    });
}
Also used : UpdateUserPermissions(org.activityinfo.shared.command.UpdateUserPermissions) MaskingAsyncMonitor(org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor) BatchCommand(org.activityinfo.shared.command.BatchCommand) Record(com.extjs.gxt.ui.client.store.Record) BatchResult(org.activityinfo.shared.command.result.BatchResult) UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO)

Example 12 with UserPermissionDTO

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

the class UpdateUserPermissionsHandler method execute.

@Override
public CommandResult execute(UpdateUserPermissions cmd, User executingUser) throws CommandException {
    UserDatabase database = databaseDAO.findById(cmd.getDatabaseId());
    UserPermissionDTO dto = cmd.getModel();
    /*
         * First check that the current user has permission to add users to to
         * the queries
         */
    boolean isOwner = executingUser.getId() == database.getOwner().getId();
    if (!isOwner) {
        verifyAuthority(cmd, database.getPermissionByUser(executingUser));
    }
    User user = null;
    if (userDAO.doesUserExist(dto.getEmail())) {
        user = userDAO.findUserByEmail(dto.getEmail());
    }
    if (user == null) {
        user = createNewUser(executingUser, dto, cmd.getHost());
    }
    /*
         * Does the permission record exist ?
         */
    UserPermission perm = database.getPermissionByUser(user);
    if (perm == null) {
        perm = new UserPermission(database, user);
        doUpdate(perm, dto, isOwner, database.getPermissionByUser(executingUser));
        permDAO.persist(perm);
    } else {
        doUpdate(perm, dto, isOwner, database.getPermissionByUser(executingUser));
    }
    return null;
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase) UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission)

Example 13 with UserPermissionDTO

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

the class DbUserExport method createDataRows.

private void createDataRows(Sheet sheet) {
    ((HSSFSheet) sheet).createDrawingPatriarch();
    int rowIndex = 2;
    for (UserPermissionDTO user : users) {
        Row row = sheet.createRow(rowIndex++);
        int column = 0;
        createCell(row, column++, user.getName());
        createCell(row, column++, user.getEmail());
        createCell(row, column++, String.valueOf(user.getPartner()));
        createCell(row, column++, String.valueOf(user.getAllowView()));
        createCell(row, column++, String.valueOf(user.getAllowViewAll()));
        createCell(row, column++, String.valueOf(user.getAllowDesign()));
        createCell(row, column++, String.valueOf(user.getAllowEdit()));
        createCell(row, column++, String.valueOf(user.getAllowEditAll()));
        createCell(row, column++, String.valueOf(user.getAllowManageUsers()));
        createCell(row, column++, String.valueOf(user.getAllowManageAllUsers()));
    }
}
Also used : HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) Row(org.apache.poi.ss.usermodel.Row) UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO)

Example 14 with UserPermissionDTO

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

Example 15 with UserPermissionDTO

use of org.activityinfo.shared.dto.UserPermissionDTO 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
 *
 * @throws CommandException
 */
@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));
    Assert.assertEquals(1, result.getTotalLength());
    Assert.assertEquals("ralph@lauren.com", result.getData().get(0).getEmail());
    Assert.assertTrue("edit permissions", result.getData().get(0).getAllowEdit());
}
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)

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