Skip to content

EspoCRM – Open Source CRM Application

2FA setup only for interactive user

Yuriiae5d8ea79135
diff --git a/application/Espo/Tools/UserSecurity/Service.php b/application/Espo/Tools/UserSecurity/Service.php
index 5ca2703503..3cbfaf8e6f 100644
--- a/application/Espo/Tools/UserSecurity/Service.php
+++ b/application/Espo/Tools/UserSecurity/Service.php
@@ -103,12 +103,7 @@ class Service
*/
public function getTwoFactorUserSetupData(string $id, stdClass $data): stdClass
{
- if (
- !$this->user->isEffectiveAdmin() &&
- $id !== $this->user->getId()
- ) {
- throw new Forbidden();
- }
+ $this->assertUserWriteAccess($id);
$isReset = $data->reset ?? false;
@@ -187,9 +182,7 @@ class Service
*/
public function update(string $id, stdClass $data): stdClass
{
- if (!$this->user->isEffectiveAdmin() && $id !== $this->user->getId()) {
- throw new Forbidden();
- }
+ $this->assertUserWriteAccess($id);
/** @var ?User $user */
$user = $this->entityManager->getEntityById(User::ENTITY_TYPE, $id);
@@ -308,4 +301,18 @@ class Service
/** @var UserDataRepository */
return $this->entityManager->getRepository(UserData::ENTITY_TYPE);
}
+
+ /**
+ * @throws Forbidden
+ */
+ private function assertUserWriteAccess(string $id): void
+ {
+ if (!$this->user->isEffectiveAdmin() && $id !== $this->user->getId()) {
+ throw new Forbidden();
+ }
+
+ if ($this->user->getScopes() !== null) {
+ throw new Forbidden("Allowed only for an interactive user.");
+ }
+ }
}