use of org.molgenis.data.plugin.model.Plugin in project molgenis by molgenis.
the class PluginPopulatorTest method testPopulate.
@Test
public void testPopulate() throws Exception {
PluginController pluginController0 = when(mock(PluginController.class).getId()).thenReturn("newPlugin").getMock();
PluginController pluginController1 = when(mock(PluginController.class).getId()).thenReturn("changedPlugin").getMock();
ApplicationContext ctx = mock(ApplicationContext.class);
when(ctx.getBeansOfType(PluginController.class)).thenReturn(ImmutableMap.of("newPlugin", pluginController0, "changedPlugin", pluginController1));
Plugin newPlugin = when(mock(Plugin.class).getId()).thenReturn("newPlugin").getMock();
when(newPlugin.setLabel("newPlugin")).thenReturn(newPlugin);
Plugin changedPlugin = when(mock(Plugin.class).getId()).thenReturn("changedPlugin").getMock();
when(changedPlugin.setLabel("changedPlugin")).thenReturn(changedPlugin);
Plugin existingChangedPlugin = when(mock(Plugin.class).getId()).thenReturn("changedPlugin").getMock();
when(existingChangedPlugin.setLabel("oldChangedPlugin")).thenReturn(existingChangedPlugin);
Plugin deletedPlugin = when(mock(Plugin.class).getId()).thenReturn("deletedPlugin").getMock();
when(deletedPlugin.setLabel("deletedPlugin")).thenReturn(deletedPlugin);
when(pluginFactory.create("newPlugin")).thenReturn(newPlugin);
when(pluginFactory.create("changedPlugin")).thenReturn(changedPlugin);
when(dataService.getRepository(PluginMetadata.PLUGIN, Plugin.class)).thenReturn(pluginRepository);
when(dataService.findAll(PluginMetadata.PLUGIN, Plugin.class)).thenReturn(Stream.of(existingChangedPlugin, deletedPlugin));
pluginPopulator.populate(ctx);
verify(pluginRepository).upsertBatch(updateStreamArgumentCaptor.capture());
assertEquals(newHashSet(updateStreamArgumentCaptor.getValue()), newHashSet(newPlugin, changedPlugin));
verify(dataService).delete(eq(PluginMetadata.PLUGIN), deleteStreamArgumentCaptor.capture());
assertEquals(deleteStreamArgumentCaptor.getValue().collect(toList()), singletonList(deletedPlugin));
}
use of org.molgenis.data.plugin.model.Plugin in project molgenis by molgenis.
the class PermissionManagerControllerTest method setUp.
@BeforeMethod
public void setUp() {
config.resetMocks();
mockMvc = MockMvcBuilders.standaloneSetup(permissionManagerController).setMessageConverters(gsonHttpMessageConverter).build();
user1 = when(mock(User.class).getId()).thenReturn("1").getMock();
when(user1.isSuperuser()).thenReturn(true);
when(user1.getUsername()).thenReturn("Ipsum");
userSid = new PrincipalSid("Ipsum");
user2 = when(mock(User.class).getId()).thenReturn("2").getMock();
group1 = when(mock(Group.class).getId()).thenReturn("1").getMock();
groupSid = new GrantedAuthoritySid("ROLE_1");
group2 = when(mock(Group.class).getId()).thenReturn("2").getMock();
plugin1 = when(mock(Plugin.class).getId()).thenReturn("1").getMock();
plugin2 = when(mock(Plugin.class).getId()).thenReturn("2").getMock();
pluginIdentity1 = new PluginIdentity(plugin1);
pluginIdentity2 = new PluginIdentity(plugin2);
entityType1 = when(mock(EntityType.class).getId()).thenReturn("1").getMock();
entityType2 = when(mock(EntityType.class).getId()).thenReturn("2").getMock();
entityType3 = when(mock(EntityType.class).getId()).thenReturn("3").getMock();
when(entityType1.getLabel()).thenReturn("label1");
when(entityType2.getLabel()).thenReturn("label2");
when(entityType3.getLabel()).thenReturn("label3");
entityIdentity1 = new EntityTypeIdentity(entityType1);
entityIdentity2 = new EntityTypeIdentity(entityType2);
entityIdentity3 = new EntityTypeIdentity(entityType3);
package1 = when(mock(Package.class).getId()).thenReturn("1").getMock();
package2 = when(mock(Package.class).getId()).thenReturn("2").getMock();
package3 = when(mock(Package.class).getId()).thenReturn("3").getMock();
packageIdentity1 = new PackageIdentity(package1);
packageIdentity2 = new PackageIdentity(package2);
packageIdentity3 = new PackageIdentity(package3);
when(dataService.findAll(USER, User.class)).thenReturn(Stream.of(user1, user2));
when(dataService.findAll(GROUP, Group.class)).thenReturn(Stream.of(group1, group2));
when(dataService.findOneById(GROUP, "1", Group.class)).thenReturn(group1);
when(dataService.findOneById(USER, "1", User.class)).thenReturn(user1);
when(dataService.findAll(PLUGIN, Plugin.class)).thenReturn(Stream.of(plugin1, plugin2));
when(dataService.findAll(ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(Stream.of(entityType1, entityType2, entityType3));
when(dataService.findAll(PACKAGE, Package.class)).thenReturn(Stream.of(package1, package2, package3));
pluginPermissionRead = PluginPermission.READ;
cumulativeEntityPermissionWritemeta = new CumulativePermission();
cumulativeEntityPermissionWritemeta.set(EntityTypePermission.WRITEMETA).set(EntityTypePermission.WRITE).set(EntityTypePermission.READ).set(EntityTypePermission.COUNT);
cumulativeEntityPermissionWrite = new CumulativePermission();
cumulativeEntityPermissionWrite.set(EntityTypePermission.WRITE).set(EntityTypePermission.READ).set(EntityTypePermission.COUNT);
cumulativeEntityPermissionRead = new CumulativePermission();
cumulativeEntityPermissionRead.set(EntityTypePermission.READ).set(EntityTypePermission.COUNT);
cumulativeEntityPermissionCount = new CumulativePermission();
cumulativeEntityPermissionCount.set(EntityTypePermission.COUNT);
}
use of org.molgenis.data.plugin.model.Plugin in project molgenis by molgenis.
the class PermissionManagerController method updatePluginPermissions.
private void updatePluginPermissions(WebRequest webRequest, Sid sid) {
for (Plugin plugin : getPlugins()) {
String param = "radio-" + plugin.getId();
String value = webRequest.getParameter(param);
if (value != null) {
if (!value.equals("none")) {
createSidPluginPermission(plugin, sid, toPluginPermission(value));
} else {
removeSidPluginPermission(plugin, sid);
}
}
}
}
use of org.molgenis.data.plugin.model.Plugin in project molgenis by molgenis.
the class PermissionManagerController method toPluginPermissions.
private Permissions toPluginPermissions(List<Plugin> plugins, Map<ObjectIdentity, Acl> aclMap, Sid sid) {
Permissions permissions = new Permissions();
// set permissions: entity ids
Map<String, String> pluginMap = plugins.stream().collect(toMap(Plugin::getId, Plugin::getId, (u, v) -> {
throw new IllegalStateException(format("Duplicate key %s", u));
}, LinkedHashMap::new));
permissions.setEntityIds(pluginMap);
// set permissions: user of group id
boolean isUser = setUserOrGroup(sid, permissions);
// set permissions: permissions
aclMap.forEach((objectIdentity, acl) -> {
String pluginId = objectIdentity.getIdentifier().toString();
acl.getEntries().forEach(ace -> {
if (ace.getSid().equals(sid)) {
org.molgenis.security.permission.Permission pluginPermission = toPluginPermission(ace);
if (isUser) {
permissions.addUserPermission(pluginId, pluginPermission);
} else {
permissions.addGroupPermission(pluginId, pluginPermission);
}
}
});
});
return permissions;
}
Aggregations