Search in sources :

Example 31 with WindowId

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);
}
Also used : WindowId(de.metas.ui.web.window.datatypes.WindowId) Test(org.junit.Test)

Example 32 with WindowId

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);
    }
}
Also used : WindowId(de.metas.ui.web.window.datatypes.WindowId) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO)

Example 33 with WindowId

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);
}
Also used : WindowId(de.metas.ui.web.window.datatypes.WindowId) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath)

Example 34 with WindowId

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);
}
Also used : WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 35 with WindowId

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);
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId) WindowId(de.metas.ui.web.window.datatypes.WindowId) JSONDocumentLayout(de.metas.ui.web.window.datatypes.json.JSONDocumentLayout) DocumentDescriptor(de.metas.ui.web.window.descriptor.DocumentDescriptor) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

WindowId (de.metas.ui.web.window.datatypes.WindowId)48 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)22 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)13 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)9 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)9 List (java.util.List)9 Set (java.util.Set)9 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableSet (com.google.common.collect.ImmutableSet)8 AdempiereException (org.adempiere.exceptions.AdempiereException)8 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)8 NonNull (lombok.NonNull)7 Services (org.adempiere.util.Services)7 LogManager (de.metas.logging.LogManager)6 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)6 DetailId (de.metas.ui.web.window.descriptor.DetailId)6 Logger (org.slf4j.Logger)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 JSONViewDataType (de.metas.ui.web.view.json.JSONViewDataType)5