use of org.adempiere.ad.element.api.AdWindowId 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 AdWindowId adWindowId = document.getDocumentPath().getWindowId().toAdWindowIdOrNull();
if (adWindowId != null && !permissions.checkWindowPermission(adWindowId).hasReadAccess()) {
throw DocumentPermissionException.of(DocumentPermission.View, "no window read permission");
}
final int adTableId = getAdTableId(document);
if (adTableId <= 0) {
// cannot apply security because this is not table based
return;
}
final int recordId = getRecordId(document);
final OrgId orgId = document.getOrgId();
if (orgId == null) {
// the user cleared the field; field is flagged as mandatory; until the user set the field, don't make a fuss.
return;
}
final String errmsg = permissions.checkCanView(document.getClientId(), orgId, adTableId, recordId);
if (errmsg != null) {
throw DocumentPermissionException.of(DocumentPermission.View, errmsg);
}
}
use of org.adempiere.ad.element.api.AdWindowId 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 AdWindowId adWindowId = documentPath.getWindowId().toAdWindowIdOrNull();
if (adWindowId != null && !permissions.checkWindowPermission(adWindowId).hasWriteAccess()) {
return "no window edit permission";
}
final int adTableId = getAdTableId(document);
if (adTableId <= 0) {
// not table based => OK
return null;
}
final int recordId = getRecordId(document);
final ClientId adClientId = document.getClientId();
final OrgId adOrgId = document.getOrgId();
if (adOrgId == null) {
// the user cleared the field; field is flagged as mandatory; until user set the field, don't make a fuss.
return null;
}
return permissions.checkCanUpdate(adClientId, adOrgId, adTableId, recordId);
}
Aggregations