Search in sources :

Example 1 with Setting

use of org.pentaho.platform.web.http.api.resources.Setting in project pentaho-platform by pentaho.

the class FileServiceTest method testDoGetCanAccessList.

@Test
public void testDoGetCanAccessList() {
    String permissions = RepositoryFilePermission.READ.ordinal() + "|" + RepositoryFilePermission.WRITE.ordinal() + "|" + RepositoryFilePermission.DELETE.ordinal();
    doReturn(true).when(fileService.repository).hasAccess(anyString(), any(EnumSet.class));
    List<Setting> settings = fileService.doGetCanAccessList("pathId", permissions);
    assertTrue(settings.size() > 0);
}
Also used : EnumSet(java.util.EnumSet) Setting(org.pentaho.platform.web.http.api.resources.Setting) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with Setting

use of org.pentaho.platform.web.http.api.resources.Setting in project pentaho-platform by pentaho.

the class FileServiceTest method testDoGetPathsAccessList.

@Test
public void testDoGetPathsAccessList() {
    List<String> paths = new ArrayList<String>();
    paths.add("path1");
    paths.add("path2");
    paths.add("path3");
    doReturn(true).when(fileService.repository).hasAccess(anyString(), any(EnumSet.class));
    List<Setting> settings = fileService.doGetPathsAccessList(new StringListWrapper(paths));
    assertTrue(settings.size() > 0);
    doReturn(false).when(fileService.repository).hasAccess(anyString(), any(EnumSet.class));
    settings = fileService.doGetPathsAccessList(new StringListWrapper(paths));
    assertEquals(0, settings.size());
}
Also used : EnumSet(java.util.EnumSet) Setting(org.pentaho.platform.web.http.api.resources.Setting) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) StringListWrapper(org.pentaho.platform.web.http.api.resources.StringListWrapper) Test(org.junit.Test)

Example 3 with Setting

use of org.pentaho.platform.web.http.api.resources.Setting in project pentaho-platform by pentaho.

the class FileService method doGetCanAccessList.

public List<Setting> doGetCanAccessList(String pathId, String permissions) {
    StringTokenizer tokenizer = new StringTokenizer(permissions, "|");
    ArrayList<Setting> permMap = new ArrayList<Setting>();
    while (tokenizer.hasMoreTokens()) {
        Integer perm = Integer.valueOf(tokenizer.nextToken());
        EnumSet<RepositoryFilePermission> permission = EnumSet.of(RepositoryFilePermission.values()[perm]);
        permMap.add(new Setting(perm.toString(), new Boolean(getRepository().hasAccess(idToPath(pathId), permission)).toString()));
    }
    return permMap;
}
Also used : StringTokenizer(java.util.StringTokenizer) Setting(org.pentaho.platform.web.http.api.resources.Setting) ArrayList(java.util.ArrayList) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)

Example 4 with Setting

use of org.pentaho.platform.web.http.api.resources.Setting in project pentaho-platform by pentaho.

the class FileService method doGetPathsAccessList.

public List<Setting> doGetPathsAccessList(StringListWrapper pathsWrapper) {
    List<Setting> pathsPermissonsSettings = new ArrayList<Setting>();
    String permissions = RepositoryFilePermission.READ.ordinal() + "|" + RepositoryFilePermission.WRITE.ordinal() + "|" + RepositoryFilePermission.DELETE.ordinal() + "|" + RepositoryFilePermission.ACL_MANAGEMENT.ordinal() + "|" + RepositoryFilePermission.ALL.ordinal();
    List<String> paths = pathsWrapper.getStrings();
    for (String path : paths) {
        List<Setting> permList = doGetCanAccessList(path, permissions);
        for (Setting perm : permList) {
            if (Boolean.parseBoolean(perm.getValue())) {
                Setting setting = new Setting();
                setting.setName(path);
                setting.setValue(perm.getName());
                pathsPermissonsSettings.add(setting);
            }
        }
    }
    return pathsPermissonsSettings;
}
Also used : Setting(org.pentaho.platform.web.http.api.resources.Setting) ArrayList(java.util.ArrayList)

Aggregations

Setting (org.pentaho.platform.web.http.api.resources.Setting)4 ArrayList (java.util.ArrayList)3 EnumSet (java.util.EnumSet)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 StringTokenizer (java.util.StringTokenizer)1 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)1 StringListWrapper (org.pentaho.platform.web.http.api.resources.StringListWrapper)1