From ac28ae5a9bc54d90d65a3d07ea0d7790dd99f554 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 21 Nov 2022 18:13:04 +0200 Subject: [PATCH] acl checkField --- application/Espo/Core/Acl.php | 13 +++++++++++++ application/Espo/Core/AclManager.php | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/application/Espo/Core/Acl.php b/application/Espo/Core/Acl.php index bb9031e1f2..940b1ac514 100644 --- a/application/Espo/Core/Acl.php +++ b/application/Espo/Core/Acl.php @@ -248,6 +248,19 @@ class Acl ->getScopeForbiddenFieldList($this->user, $scope, $action, $thresholdLevel); } + /** + * Check access to a field. + * + * @param string $scope A scope (entity type). + * @param string $field A field to check. + * @param Table::ACTION_READ|Table::ACTION_EDIT $action An action. + * @return bool + */ + public function checkField(string $scope, string $field, string $action = Table::ACTION_READ): bool + { + return $this->aclManager->checkField($this->user, $scope, $field, $action); + } + /** * Get links forbidden for a user. * diff --git a/application/Espo/Core/AclManager.php b/application/Espo/Core/AclManager.php index 40f999d7d2..2176ea13a2 100644 --- a/application/Espo/Core/AclManager.php +++ b/application/Espo/Core/AclManager.php @@ -556,6 +556,20 @@ class AclManager ); } + /** + * Check access to a field. + * + * @param User $user A user. + * @param string $scope A scope (entity type). + * @param string $field A field to check. + * @param Table::ACTION_READ|Table::ACTION_EDIT $action An action. + * @return bool + */ + public function checkField(User $user, string $scope, string $field, string $action = Table::ACTION_READ): bool + { + return !in_array($field, $this->getScopeForbiddenFieldList($user, $scope, $action)); + } + /** * Whether a user has access to another user over a specific permission. *