Search in sources :

Example 1 with FolderDTO

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

the class GetUsersHandler method createFolderDTO.

private FolderDTO createFolderDTO(Folder folder) {
    FolderDTO dto = new FolderDTO();
    dto.setId(folder.getId());
    dto.setDatabaseId(folder.getDatabase().getId());
    dto.setName(folder.getName());
    return dto;
}
Also used : FolderDTO(org.activityinfo.legacy.shared.model.FolderDTO)

Example 2 with FolderDTO

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

the class UpdateUserPermissionsHandler method constructModel.

private UserPermissionModel constructModel(UserPermission perm, UserPermissionDTO dto) {
    List<GrantModel> grants = new ArrayList<>();
    for (FolderDTO folderDTO : dto.getFolders()) {
        GrantModel grant = new GrantModel.Builder().setResourceId(CuidAdapter.folderId(folderDTO.getId())).build();
        grants.add(grant);
    }
    return new UserPermissionModel(perm.getUser().getId(), perm.getDatabase().getId(), grants);
}
Also used : FolderDTO(org.activityinfo.legacy.shared.model.FolderDTO) GrantModel(org.activityinfo.model.database.GrantModel) ArrayList(java.util.ArrayList) UserPermissionModel(org.activityinfo.model.database.UserPermissionModel)

Example 3 with FolderDTO

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

the class DesignTreeDropTarget method showFeedback.

@Override
protected void showFeedback(DNDEvent event) {
    final TreePanel.TreeNode overItem = tree.findNode(event.getTarget());
    if (overItem == null) {
        clearStyles(event);
    }
    ModelData sourceModel = tree.getSelectionModel().getSelectedItem();
    ModelData overModel = null;
    if (overItem != null) {
        overModel = overItem.getModel();
        // Dropping a node onto itself? Abort.
        if (overModel == sourceModel) {
            clearStyles(event);
            return;
        }
        // Dropping a node into one of its children? Nope.
        List<ModelData> children = tree.getStore().getChildren(sourceModel, true);
        if (children.contains(overItem.getModel())) {
            clearStyles(event);
            return;
        }
    }
    // Now decide whether this move is legal
    // insert = insert after the overItem as a sibling
    // append = append to the overItem's children
    boolean insert = false;
    boolean append = false;
    // For most items, we will only allow inserting within the same parent
    if (overModel != null && tree.getStore().getParent(sourceModel) == tree.getStore().getParent(overModel)) {
        insert = true;
    }
    // Activities/Forms can be moved into other folders
    if (sourceModel instanceof ActivityDTO) {
        if (overModel == null || overModel instanceof FolderDTO) {
            insert = true;
            append = true;
        }
        if (overModel instanceof ActivityDTO) {
            insert = true;
        }
    }
    // which operation is allowed.
    if (append) {
        setFeedback(DND.Feedback.BOTH);
    } else {
        setFeedback(DND.Feedback.INSERT);
    }
    if (append && overItem == null) {
        handleAppend(event, overItem);
    } else if (insert) {
        handleInsert(event, overItem);
    } else if (append) {
        handleAppend(event, overItem);
    } else {
        if (activeItem != null) {
            tree.getView().onDropChange(activeItem, false);
        }
        status = -1;
        activeItem = null;
        appendItem = null;
        Insert.get().hide();
        event.getStatus().setStatus(false);
    }
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) FolderDTO(org.activityinfo.legacy.shared.model.FolderDTO) TreePanel(com.extjs.gxt.ui.client.widget.treepanel.TreePanel) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Example 4 with FolderDTO

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

the class GetUsersHandler method folderList.

private List<FolderDTO> folderList(Map<ResourceId, Folder> folderMap, UserPermission perm) {
    if (Strings.isNullOrEmpty(perm.getModel())) {
        // Include all folders, as user has access to all
        List<FolderDTO> folderList = new ArrayList<>(folderMap.size());
        folderMap.values().forEach(folder -> folderList.add(createFolderDTO(folder)));
        return folderList;
    }
    try {
        UserPermissionModel model = UserPermissionModel.fromJson(Json.parse(perm.getModel()));
        List<FolderDTO> folderList = new ArrayList<>();
        for (GrantModel grantModel : model.getGrants()) {
            Folder folder = folderMap.get(grantModel.getResourceId());
            if (folder != null) {
                folderList.add(createFolderDTO(folder));
            }
        }
        return folderList;
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Permissions model: " + perm.getModel());
        LOGGER.log(Level.SEVERE, "Failed to parse permissions model", e);
        return null;
    }
}
Also used : FolderDTO(org.activityinfo.legacy.shared.model.FolderDTO) GrantModel(org.activityinfo.model.database.GrantModel) ArrayList(java.util.ArrayList) Folder(org.activityinfo.server.database.hibernate.entity.Folder) IllegalAccessCommandException(org.activityinfo.legacy.shared.exception.IllegalAccessCommandException) UserPermissionModel(org.activityinfo.model.database.UserPermissionModel)

Example 5 with FolderDTO

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

the class UpdateUserPermissionsHandlerTest method testFolderLevelUpdate.

@Test
@OnDataSet("/dbunit/schema3.db.xml")
public void testFolderLevelUpdate() {
    setUser(1);
    UserPermissionDTO newUser = new UserPermissionDTO();
    newUser.setName("Bavon");
    newUser.setEmail("bavon@nrcdrc.org");
    newUser.setPartner(new PartnerDTO(1, "NRC"));
    newUser.setAllowView(true);
    newUser.setAllowViewAll(false);
    newUser.setAllowEdit(true);
    newUser.setAllowEdit(false);
    newUser.setAllowDesign(true);
    FolderDTO health = new FolderDTO();
    health.setId(3);
    newUser.setFolders(Arrays.asList(health));
    newUser.setFolderLimitation(true);
    execute(new UpdateUserPermissions(1, newUser));
    UserResult users = execute(new GetUsers(1));
    UserPermissionDTO bavon = users.getData().get(0);
    assertThat(bavon.hasFolderLimitation(), equalTo(true));
}
Also used : FolderDTO(org.activityinfo.legacy.shared.model.FolderDTO) 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)

Aggregations

FolderDTO (org.activityinfo.legacy.shared.model.FolderDTO)5 ArrayList (java.util.ArrayList)2 GrantModel (org.activityinfo.model.database.GrantModel)2 UserPermissionModel (org.activityinfo.model.database.UserPermissionModel)2 ModelData (com.extjs.gxt.ui.client.data.ModelData)1 TreePanel (com.extjs.gxt.ui.client.widget.treepanel.TreePanel)1 GetUsers (org.activityinfo.legacy.shared.command.GetUsers)1 UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)1 UserResult (org.activityinfo.legacy.shared.command.result.UserResult)1 IllegalAccessCommandException (org.activityinfo.legacy.shared.exception.IllegalAccessCommandException)1 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)1 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)1 UserPermissionDTO (org.activityinfo.legacy.shared.model.UserPermissionDTO)1 OnDataSet (org.activityinfo.server.database.OnDataSet)1 Folder (org.activityinfo.server.database.hibernate.entity.Folder)1 Test (org.junit.Test)1