use of com.bakdata.conquery.models.forms.configs.FormConfig in project conquery by bakdata.
the class FormConfigProcessor method addConfig.
/**
* Adds the provided config to the desired dataset and the datasets that the
* subject has access to (has the READ ability on the Dataset), if the config is
* translatable to those.
*/
public FormConfig addConfig(Subject subject, Dataset targetDataset, FormConfigAPI config) {
// TODO clear this up
final Namespace namespace = datasetRegistry.get(targetDataset.getId());
subject.authorize(namespace.getDataset(), Ability.READ);
FormConfig internalConfig = FormConfigAPI.intern(config, storage.getUser(subject.getId()), targetDataset);
// Add the config immediately to the submitted dataset
addConfigToDataset(internalConfig);
return internalConfig;
}
use of com.bakdata.conquery.models.forms.configs.FormConfig in project conquery by bakdata.
the class FormConfigAPI method intern.
public static FormConfig intern(FormConfigAPI extern, User owner, Dataset dataset) {
FormConfig intern = new FormConfig();
intern.setFormId(extern.formId);
intern.setFormType(extern.formType);
intern.setLabel(extern.label);
intern.setTags(extern.tags);
intern.setValues(extern.values);
intern.setCreationTime(extern.creationTime);
intern.setOwner(owner);
intern.setDataset(dataset);
return intern;
}
use of com.bakdata.conquery.models.forms.configs.FormConfig in project conquery by bakdata.
the class SerializationTests method formConfig.
@Test
public void formConfig() throws JSONException, IOException {
final CentralRegistry registry = new CentralRegistry();
final Dataset dataset = new Dataset("test-dataset");
registry.register(dataset);
ExportForm form = new ExportForm();
AbsoluteMode mode = new AbsoluteMode();
form.setTimeMode(mode);
mode.setForm(form);
mode.setFeatures(List.of(new CQConcept()));
ObjectMapper mapper = FormConfigProcessor.getMAPPER();
JsonNode values = mapper.valueToTree(form);
FormConfig formConfig = new FormConfig(form.getClass().getAnnotation(CPSType.class).id(), values);
formConfig.setDataset(dataset);
SerializationTestUtil.forType(FormConfig.class).registry(registry).test(formConfig);
}
use of com.bakdata.conquery.models.forms.configs.FormConfig in project conquery by bakdata.
the class FormConfigTest method deleteConfig.
@Test
public void deleteConfig() {
// PREPARE
user.addPermission(DatasetPermission.onInstance(Ability.READ, datasetId));
ObjectMapper mapper = FormConfigProcessor.getMAPPER();
FormConfig formConfig = new FormConfig(form.getClass().getAnnotation(CPSType.class).id(), mapper.valueToTree(form));
formConfig.setDataset(dataset);
user.addPermission(formConfig.createPermission(AbilitySets.FORM_CONFIG_CREATOR));
storage.addFormConfig(formConfig);
// EXECUTE
processor.deleteConfig(user, formConfig);
// CHECK
assertThat(storage.getAllFormConfigs()).doesNotContain(formConfig);
assertThat(user.getPermissions()).doesNotContain(FormConfigPermission.onInstance(AbilitySets.FORM_CONFIG_CREATOR, formConfig.getId()));
}
use of com.bakdata.conquery.models.forms.configs.FormConfig in project conquery by bakdata.
the class FormConfigTest method patchConfig.
@Test
public void patchConfig() {
// PREPARE
user.addPermission(DatasetPermission.onInstance(Ability.READ, datasetId));
Group group1 = new Group("test1", "test1", storage);
storage.addGroup(group1);
Group group2 = new Group("test2", "test2", storage);
storage.addGroup(group2);
group1.addMember(user);
group2.addMember(user);
ObjectMapper mapper = FormConfigProcessor.getMAPPER();
JsonNode values = mapper.valueToTree(form);
FormConfigAPI formConfig = FormConfigAPI.builder().formType(form.getFormType()).values(values).build();
FormConfig config = processor.addConfig(user, dataset, formConfig);
// EXECUTE PART 1
processor.patchConfig(user, config, FormConfigPatch.builder().label("newTestLabel").tags(new String[] { "tag1", "tag2" }).groups(List.of(group1.getId())).values(new ObjectNode(mapper.getNodeFactory(), Map.of("test-Node", new TextNode("test-text")))).build());
// CHECK PART 1
FormConfig patchedFormExpected = new FormConfig(form.getClass().getAnnotation(CPSType.class).id(), values);
patchedFormExpected.setDataset(dataset);
patchedFormExpected.setFormId(config.getFormId());
patchedFormExpected.setLabel("newTestLabel");
patchedFormExpected.setShared(true);
patchedFormExpected.setTags(new String[] { "tag1", "tag2" });
patchedFormExpected.setOwner(user);
patchedFormExpected.setValues(new ObjectNode(mapper.getNodeFactory(), Map.of("test-Node", new TextNode("test-text"))));
final FormConfigId formId = config.getId();
assertThat(storage.getFormConfig(formId)).usingRecursiveComparison().ignoringFields("cachedId", FormConfig.Fields.creationTime).isEqualTo(patchedFormExpected);
assertThat(storage.getGroup(group1.getId()).getPermissions()).contains(FormConfigPermission.onInstance(AbilitySets.SHAREHOLDER, formId));
assertThat(storage.getGroup(group2.getId()).getPermissions()).doesNotContain(FormConfigPermission.onInstance(AbilitySets.SHAREHOLDER, formId));
// EXECUTE PART 2 (Unshare)
processor.patchConfig(user, config, FormConfigPatch.builder().groups(List.of()).build());
// CHECK PART 2
patchedFormExpected.setShared(false);
assertThat(storage.getFormConfig(formId)).usingRecursiveComparison().ignoringFields("cachedId", FormConfig.Fields.creationTime).isEqualTo(patchedFormExpected);
assertThat(storage.getGroup(group1.getId()).getPermissions()).doesNotContain(FormConfigPermission.onInstance(AbilitySets.SHAREHOLDER, formId));
assertThat(storage.getGroup(group2.getId()).getPermissions()).doesNotContain(FormConfigPermission.onInstance(AbilitySets.SHAREHOLDER, formId));
}
Aggregations