Search in sources :

Example 1 with UserPermissionDTO

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

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

use of org.activityinfo.legacy.shared.model.UserPermissionDTO in project activityinfo by bedatadriven.

the class MailingListDialog method createMailingList.

private String createMailingList(List<UserPermissionDTO> users) {
    StringBuilder emails = new StringBuilder();
    for (UserPermissionDTO dto : users) {
        emails.append("\"" + dto.getName() + "\"");
        emails.append(" ");
        emails.append("<" + dto.getEmail() + ">,");
        emails.append(" ");
    }
    return emails.toString();
}
Also used : UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO)

Example 4 with UserPermissionDTO

use of org.activityinfo.legacy.shared.model.UserPermissionDTO in project activityinfo by bedatadriven.

the class GetUsersHandler method execute.

@Override
public CommandResult execute(GetUsers cmd, User currentUser) {
    Database db = em.getReference(Database.class, cmd.getDatabaseId());
    UserPermission currentUserPermission = PermissionOracle.using(em).getPermissionByUser(db, currentUser);
    assertAuthorized(currentUserPermission);
    String whereClause = "up.database.id = :dbId and " + "up.user.id <> :currentUserId and " + "up.allowView = true";
    if (!currentUserPermission.isAllowManageAllUsers()) {
        whereClause += " and up.partner.id = " + currentUserPermission.getPartner().getId();
    }
    TypedQuery<UserPermission> query = em.createQuery("select up from UserPermission up where " + whereClause + " " + composeOrderByClause(cmd), UserPermission.class).setParameter("dbId", cmd.getDatabaseId()).setParameter("currentUserId", currentUser.getId());
    List<Folder> folders = em.createQuery("select f from Folder f where f.database.id = :dbId", Folder.class).setParameter("dbId", cmd.getDatabaseId()).getResultList();
    Map<ResourceId, Folder> folderMap = new HashMap<>();
    for (Folder folder : folders) {
        folderMap.put(CuidAdapter.folderId(folder.getId()), folder);
    }
    if (cmd.getOffset() > 0) {
        query.setFirstResult(cmd.getOffset());
    }
    if (cmd.getLimit() > 0) {
        query.setMaxResults(cmd.getLimit());
    }
    List<UserPermissionDTO> models = new ArrayList<>();
    for (UserPermission perm : query.getResultList()) {
        UserPermissionDTO dto = new UserPermissionDTO();
        dto.setEmail(perm.getUser().getEmail());
        dto.setName(perm.getUser().getName());
        dto.setOrganization(perm.getUser().getOrganization());
        dto.setJobtitle(perm.getUser().getJobtitle());
        dto.setAllowDesign(perm.isAllowDesign());
        dto.setAllowView(perm.isAllowView());
        dto.setAllowViewAll(perm.isAllowViewAll());
        dto.setAllowEdit(perm.isAllowEdit());
        dto.setAllowEditAll(perm.isAllowEditAll());
        dto.setAllowManageUsers(perm.isAllowManageUsers());
        dto.setAllowManageAllUsers(perm.isAllowManageAllUsers());
        dto.setPartner(new PartnerDTO(perm.getPartner().getId(), perm.getPartner().getName()));
        dto.setFolderLimitation(!Strings.isNullOrEmpty(perm.getModel()));
        dto.setFolders(folderList(folderMap, perm));
        models.add(dto);
    }
    return new UserResult(models, cmd.getOffset(), queryTotalCount(cmd, currentUser, whereClause));
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Folder(org.activityinfo.server.database.hibernate.entity.Folder) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) ResourceId(org.activityinfo.model.resource.ResourceId) Database(org.activityinfo.server.database.hibernate.entity.Database) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission)

Example 5 with UserPermissionDTO

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

Aggregations

UserPermissionDTO (org.activityinfo.legacy.shared.model.UserPermissionDTO)15 UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)10 Test (org.junit.Test)9 UserResult (org.activityinfo.legacy.shared.command.result.UserResult)5 GetUsers (org.activityinfo.legacy.shared.command.GetUsers)4 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)4 OnDataSet (org.activityinfo.server.database.OnDataSet)3 Database (org.activityinfo.server.database.hibernate.entity.Database)2 UserPermission (org.activityinfo.server.database.hibernate.entity.UserPermission)2 MaskingAsyncMonitor (org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor)2 Record (com.extjs.gxt.ui.client.store.Record)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)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 VoidResult (org.activityinfo.legacy.shared.command.result.VoidResult)1 FolderDTO (org.activityinfo.legacy.shared.model.FolderDTO)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 Folder (org.activityinfo.server.database.hibernate.entity.Folder)1