system user id in config
This commit is contained in:
@@ -42,11 +42,23 @@ class SystemUser
|
||||
private const ID = 'system';
|
||||
private const UUID = 'ffffffff-ffff-ffff-ffff-ffffffffffff';
|
||||
|
||||
private bool $isUuid;
|
||||
private string $id;
|
||||
|
||||
public function __construct(Metadata $metadata)
|
||||
public function __construct(Metadata $metadata, Config $config)
|
||||
{
|
||||
$this->isUuid = $metadata->get(['app', 'recordId', 'dbType']) === 'uuid';
|
||||
$id = $config->get('systemUserId');
|
||||
|
||||
if ($id) {
|
||||
$this->id = $id;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$isUuid = $metadata->get(['app', 'recordId', 'dbType']) === 'uuid';
|
||||
|
||||
$this->id = $isUuid ?
|
||||
self::UUID :
|
||||
self::ID;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,8 +66,6 @@ class SystemUser
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->isUuid ?
|
||||
self::UUID :
|
||||
self::ID;
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
"emailKeepParentTeamsEntityList"
|
||||
],
|
||||
"params": {
|
||||
"systemUserId": {
|
||||
"level": "admin",
|
||||
"readOnly": true
|
||||
},
|
||||
"smtpPassword": {
|
||||
"level": "internal"
|
||||
},
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
namespace Espo\Tools\App;
|
||||
|
||||
use Espo\Core\Authentication\Util\MethodProvider as AuthenticationMethodProvider;
|
||||
use Espo\Core\Utils\SystemUser;
|
||||
use Espo\Entities\DashboardTemplate;
|
||||
use Espo\Entities\EmailAccount as EmailAccountEntity;
|
||||
use Espo\Entities\InboundEmail as InboundEmailEntity;
|
||||
@@ -67,7 +68,8 @@ class AppService
|
||||
private Preferences $preferences,
|
||||
private FieldUtil $fieldUtil,
|
||||
private Log $log,
|
||||
private AuthenticationMethodProvider $authenticationMethodProvider
|
||||
private AuthenticationMethodProvider $authenticationMethodProvider,
|
||||
private SystemUser $systemUser
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -145,6 +147,7 @@ class AppService
|
||||
'timeZoneList' => $timeZoneList,
|
||||
'auth2FARequired' => $auth2FARequired,
|
||||
'logoutWait' => $logoutWait,
|
||||
'systemUserId' => $this->systemUser->getId(),
|
||||
];
|
||||
|
||||
/** @var array<string, array<string, mixed>> $map */
|
||||
|
||||
@@ -57,7 +57,7 @@ define('views/email/record/detail', ['views/record/detail'], function (Dep) {
|
||||
|
||||
if (status === 'Archived') {
|
||||
if (
|
||||
this.model.get('createdById') === 'system' ||
|
||||
this.model.get('createdById') === this.getHelper().getAppParam('systemUserId') ||
|
||||
!this.model.get('createdById') || this.model.get('isImported')
|
||||
) {
|
||||
isRestricted = true;
|
||||
|
||||
@@ -92,7 +92,7 @@ define('views/notification/items/base', ['view'], function (Dep) {
|
||||
let id = this.userId;
|
||||
|
||||
if (this.isSystemAvatar || !id) {
|
||||
id = 'system';
|
||||
id = this.getHelper().getAppParam('systemUserId');
|
||||
}
|
||||
|
||||
return this.getHelper().getAvatarHtml(id, 'small', 20);
|
||||
|
||||
@@ -221,7 +221,7 @@ define('views/stream/note', ['view'], function (Dep) {
|
||||
let id = this.model.get('createdById');
|
||||
|
||||
if (this.isSystemAvatar) {
|
||||
id = 'system';
|
||||
id = this.getHelper().getAppParam('systemUserId');
|
||||
}
|
||||
|
||||
return this.getHelper().getAvatarHtml(id, 'small', 20);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
namespace tests\integration\Espo\Settings;
|
||||
|
||||
use Espo\Entities\User;
|
||||
use Espo\Tools\App\SettingsService;
|
||||
|
||||
class AccessTest extends \tests\integration\Core\BaseTestCase
|
||||
@@ -98,7 +99,7 @@ class AccessTest extends \tests\integration\Core\BaseTestCase
|
||||
{
|
||||
$this->createUser([
|
||||
'userName' => 'admin-tester',
|
||||
'type' => 'admin'
|
||||
'type' => 'admin',
|
||||
]);
|
||||
|
||||
$this->auth('admin-tester');
|
||||
@@ -115,4 +116,23 @@ class AccessTest extends \tests\integration\Core\BaseTestCase
|
||||
$this->assertTrue(property_exists($data, 'jobPeriod'));
|
||||
$this->assertFalse(property_exists($data, 'cryptKey'));
|
||||
}
|
||||
|
||||
public function testReadOnly(): void
|
||||
{
|
||||
$this->createUser([
|
||||
'userName' => 'admin-tester',
|
||||
'type' => User::TYPE_ADMIN,
|
||||
]);
|
||||
|
||||
$this->auth('admin-tester');
|
||||
$this->setApplication($this->createApplication());
|
||||
|
||||
$this->getInjectableFactory()
|
||||
->create(SettingsService::class)
|
||||
->setConfigData((object) [
|
||||
'systemUserId' => 'test'
|
||||
]);
|
||||
|
||||
$this->assertNull($this->getConfig()->get('systemUserId'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user