user fixes

This commit is contained in:
yuri
2018-10-26 14:38:18 +03:00
parent adf5283375
commit 66b2065d7c
4 changed files with 42 additions and 10 deletions

View File

@@ -46,7 +46,8 @@ class Espo extends Base
$user = $this->getEntityManager()->getRepository('User')->findOne([
'whereClause' => [
'userName' => $username,
'password' => $hash
'password' => $hash,
'type!=' => ['api', 'system']
]
]);

View File

@@ -172,14 +172,14 @@ class LDAP extends Espo
}
}
$user = $this->getEntityManager()->getRepository('User')->findOne(array(
'whereClause' => array(
$user = $this->getEntityManager()->getRepository('User')->findOne([
'whereClause' => [
'userName' => $username,
),
));
'type!=' => ['api', 'system']
]
]);
$isCreateUser = $this->getUtils()->getOption('createEspoUser');
if (!isset($user) && $isCreateUser) {
if (!isset($user) && $this->getUtils()->getOption('createEspoUser')) {
$userData = $ldapClient->getEntry($userDn);
$user = $this->createUser($userData, $isPortal);
}

View File

@@ -44,6 +44,10 @@ class User extends \Espo\Core\ORM\Repositories\RDB
}
}
if ($entity->has('type') && !$entity->get('type')) {
$entity->set('type', 'regular');
}
$entity->clear('isAdmin');
$entity->clear('isPortalUser');
$entity->clear('isSuperAdmin');

View File

@@ -98,6 +98,8 @@ class User extends Record
]
];
protected $allowedUserTypeList = ['regular', 'admin', 'portal', 'api'];
protected function getMailSender()
{
return $this->getContainer()->get('mailSender');
@@ -390,7 +392,10 @@ class User extends Record
protected function beforeCreateEntity(Entity $entity, $data)
{
if ($this->getConfig()->get('userLimit') && !$this->getUser()->isSuperAdmin() && !$entity->isPortal()) {
if (
$this->getConfig()->get('userLimit') && !$this->getUser()->isSuperAdmin() &&
!$entity->isPortal() && !$entity->isApi()
) {
$userCount = $this->getInternalUserCount();
if ($userCount >= $this->getConfig()->get('userLimit')) {
throw new Forbidden('User limit '.$this->getConfig()->get('userLimit').' is reached.');
@@ -412,15 +417,27 @@ class User extends Record
$entity->set('secretKey', $secretKey);
}
}
if (!$entity->isSuperAdmin()) {
if (
$entity->get('type') &&
!in_array($entity->get('type'), $this->allowedUserTypeList)
) {
throw new Forbidden();
}
}
}
protected function beforeUpdateEntity(Entity $entity, $data)
{
if ($this->getConfig()->get('userLimit') && !$this->getUser()->isSuperAdmin()) {
if (
($entity->get('isActive') && $entity->isAttributeChanged('isActive') && !$entity->isPortal())
(
$entity->get('isActive') && $entity->isAttributeChanged('isActive') &&
!$entity->isPortal() && !$entity->isApi()
)
||
(!$entity->isPortal() && $entity->isAttributeChanged('type'))
(!$entity->isPortal() && !$entity->isApi() && $entity->isAttributeChanged('type'))
) {
$userCount = $this->getInternalUserCount();
if ($userCount >= $this->getConfig()->get('userLimit')) {
@@ -447,6 +464,16 @@ class User extends Record
$entity->set('secretKey', $secretKey);
}
}
if (!$entity->isSuperAdmin()) {
if (
$entity->isAttributeChanged('type') &&
$entity->get('type') &&
!in_array($entity->get('type'), $this->allowedUserTypeList)
) {
throw new Forbidden();
}
}
}
protected function sendPassword(Entity $user, $password)