use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.
the class ViewIdTests method test_ofViewIdString_NullWindowId.
@Test
public void test_ofViewIdString_NullWindowId() {
final ViewId viewId = randomViewId();
final WindowId expectedWindowId = null;
final ViewId viewId2 = ViewId.ofViewIdString(viewId.getViewId(), expectedWindowId);
Assert.assertEquals(viewId, viewId2);
}
use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.
the class DocumentPermissionsHelper method assertCanView.
public static void assertCanView(@NonNull final Document document, @NonNull final IUserRolePermissions permissions) {
// In case document type is not Window, return OK because we cannot validate
if (document.getDocumentPath().getDocumentType() != DocumentType.Window) {
// OK
return;
}
// Check if we have window read permission
final WindowId windowId = document.getDocumentPath().getWindowId();
final int windowIdInt = windowId.toIntOr(-1);
if (windowIdInt > 0 && !permissions.checkWindowPermission(windowIdInt).hasReadAccess()) {
throw DocumentPermissionException.of(DocumentPermission.View, "no window read permission");
}
final String tableName = document.getEntityDescriptor().getTableNameOrNull();
if (tableName == null) {
// cannot apply security because this is not table based
return;
}
final int adTableId = Services.get(IADTableDAO.class).retrieveTableId(tableName);
final int recordId = document.getDocumentId().toIntOr(-1);
final String errmsg = permissions.checkCanView(document.getAD_Client_ID(), document.getAD_Org_ID(), adTableId, recordId);
if (errmsg != null) {
throw DocumentPermissionException.of(DocumentPermission.View, errmsg);
}
}
use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.
the class DocumentPermissionsHelper method checkCanEdit.
private static String checkCanEdit(@NonNull final Document document, @NonNull final IUserRolePermissions permissions) {
// In case document type is not Window, return OK because we cannot validate
final DocumentPath documentPath = document.getDocumentPath();
if (documentPath.getDocumentType() != DocumentType.Window) {
// OK
return null;
}
// Check if we have window write permission
final WindowId windowId = documentPath.getWindowId();
final int windowIdInt = windowId.toIntOr(-1);
if (windowIdInt > 0 && !permissions.checkWindowPermission(windowIdInt).hasWriteAccess()) {
return "no window edit permission";
}
final String tableName = document.getEntityDescriptor().getTableNameOrNull();
if (tableName == null) {
// OK
return null;
}
final int adTableId = Services.get(IADTableDAO.class).retrieveTableId(tableName);
int adClientId = document.getAD_Client_ID();
int adOrgId = document.getAD_Org_ID();
final int recordId = document.getDocumentId().toIntOr(-1);
return permissions.checkCanUpdate(adClientId, adOrgId, adTableId, recordId);
}
use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.
the class WindowRestController method deleteRootDocumentsList.
@DeleteMapping("/{windowId}")
public List<JSONDocument> deleteRootDocumentsList(//
@PathVariable("windowId") final String windowIdStr, //
@RequestParam(name = "ids") @ApiParam("comma separated documentIds") final String idsListStr) {
final WindowId windowId = WindowId.fromJson(windowIdStr);
final List<DocumentPath> documentPaths = DocumentPath.rootDocumentPathsList(windowId, idsListStr);
if (documentPaths.isEmpty()) {
throw new IllegalArgumentException("No ids provided");
}
return deleteDocuments(documentPaths);
}
use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.
the class WindowRestController method getLayout.
@GetMapping("/{windowId}/{tabId}/layout")
public ResponseEntity<JSONDocumentLayout> getLayout(@PathVariable("windowId") final String windowIdStr, @PathVariable("tabId") final String tabIdStr, @RequestParam(name = PARAM_Advanced, required = false, defaultValue = PARAM_Advanced_DefaultValue) final boolean advanced, final WebRequest request) {
userSession.assertLoggedIn();
final WindowId windowId = WindowId.fromJson(windowIdStr);
final DetailId detailId = DetailId.fromJson(tabIdStr);
final DocumentDescriptor descriptor = documentCollection.getDocumentDescriptorFactory().getDocumentDescriptor(windowId);
DocumentPermissionsHelper.checkWindowAccess(descriptor.getEntityDescriptor(), userSession.getUserRolePermissions());
return ETagResponseEntityBuilder.ofETagAware(request, descriptor).includeLanguageInETag().cacheMaxAge(userSession.getHttpCacheMaxAge()).map(desc -> desc.getLayout().getDetail(detailId)).jsonOptions(() -> newJSONOptions().setShowAdvancedFields(advanced).build()).toJson(JSONDocumentLayout::ofDetailTab);
}
Aggregations