mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
user fixes
This commit is contained in:
@@ -46,7 +46,8 @@ class Espo extends Base
|
||||
$user = $this->getEntityManager()->getRepository('User')->findOne([
|
||||
'whereClause' => [
|
||||
'userName' => $username,
|
||||
'password' => $hash
|
||||
'password' => $hash,
|
||||
'type!=' => ['api', 'system']
|
||||
]
|
||||
]);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user