meetings and assignmentPermissions

This commit is contained in:
yuri
2016-07-29 11:41:37 +03:00
parent cda612810d
commit d10ef7038b
6 changed files with 111 additions and 15 deletions
+10
View File
@@ -118,5 +118,15 @@ class Acl
{
return $this->getAclManager()->getScopeForbiddenFieldList($this->getUser(), $scope, $action, $thresholdLevel);
}
public function checkUserPermission($target, $permissionType = 'userPermission')
{
return $this->getAclManager()->checkUserPermission($this->getUser(), $target, $permissionType);
}
public function checkAssignmentPermission($target)
{
return $this->getAclManager()->checkAssignmentPermission($this->getUser(), $target);
}
}
+35
View File
@@ -235,5 +235,40 @@ class AclManager
if ($user->isAdmin()) return [];
return $this->getTable($user)->getScopeForbiddenFieldList($scope, $action, $thresholdLevel);
}
public function checkUserPermission(User $user, $target, $permissionType = 'userPermission')
{
$permission = $this->get($user, $permissionType);
if (is_object($target)) {
$userId = $target->id;
} else {
$userId = $target;
}
if ($user->id === $userId) return true;
if ($permission === 'no') {
return false;
}
if ($permission === 'yes') {
return true;
}
if ($permission === 'team') {
$teamIdList = $user->getLinkMultipleIdList('teams');
if (!$this->getContainer()->get('entityManager')->getRepository('User')->checkBelongsToAnyOfTeams($userId, $teamIdList)) {
return false;
}
}
return true;
}
public function checkAssignmentPermission(User $user, $target)
{
return $this->checkUserPermission($user, $target, 'assignmentPermission');
}
}
@@ -61,19 +61,23 @@ class Meeting extends \Espo\Core\ORM\Repositories\RDB
}
$assignedUserId = $entity->get('assignedUserId');
if ($assignedUserId && $entity->has('usersIds')) {
$usersIds = $entity->get('usersIds');
if (!is_array($usersIds)) {
$usersIds = array();
}
if (!in_array($assignedUserId, $usersIds)) {
$usersIds[] = $assignedUserId;
$entity->set('usersIds', $usersIds);
$hash = $entity->get('usersNames');
if ($hash instanceof \StdClass) {
$hash->$assignedUserId = $entity->get('assignedUserName');
$entity->set('usersNames', $hash);
if ($assignedUserId) {
if ($entity->has('usersIds')) {
$usersIds = $entity->get('usersIds');
if (!is_array($usersIds)) {
$usersIds = [];
}
if (!in_array($assignedUserId, $usersIds)) {
$usersIds[] = $assignedUserId;
$entity->set('usersIds', $usersIds);
$hash = $entity->get('usersNames');
if ($hash instanceof \StdClass) {
$hash->$assignedUserId = $entity->get('assignedUserName');
$entity->set('usersNames', $hash);
}
}
} else {
$entity->addLinkMultipleId('users', $assignedUserId);
}
if ($entity->isNew()) {
$currentUserId = $this->getEntityManager()->getUser()->id;
@@ -76,6 +76,39 @@ class Meeting extends \Espo\Services\Record
return $this->getInjection('dateTime');
}
public function checkAssignment(Entity $entity)
{
$result = parent::checkAssignment($entity);
if (!$result) return false;
$userIdList = $entity->get('usersIds');
if (!is_array($userIdList)) {
$userIdList = [];
}
$newIdList = [];
if (!$entity->isNew()) {
$existingIdList = [];
foreach ($entity->get('users') as $user) {
$existingIdList[] = $user->id;
}
foreach ($userIdList as $id) {
if (!in_array($id, $existingIdList)) {
$newIdList[] = $id;
}
}
} else {
$newIdList = $userIdList;
}
foreach ($newIdList as $userId) {
if (!$this->getAcl()->checkAssignmentPermission($userId)) {
return false;
}
}
return true;
}
protected function getInvitationManager()
{
+2 -2
View File
@@ -391,8 +391,8 @@ class Record extends \Espo\Core\Services\Base
return false;
}
} else if ($assignmentPermission == 'team') {
$teamIds = $this->getUser()->get('teamsIds');
if (!$this->getEntityManager()->getRepository('User')->checkBelongsToAnyOfTeams($assignedUserId, $teamIds)) {
$teamIdList = $this->getUser()->get('teamsIds');
if (!$this->getEntityManager()->getRepository('User')->checkBelongsToAnyOfTeams($assignedUserId, $teamIdList)) {
return false;
}
}
@@ -30,7 +30,21 @@ Espo.define('crm:views/meeting/fields/users', 'crm:views/meeting/fields/attendee
return Dep.extend({
selectPrimaryFilterName: 'active'
selectPrimaryFilterName: 'active',
init: function () {
this.assignmentPermission = this.getAcl().get('assignmentPermission');
if (this.assignmentPermission == 'no') {
this.readOnly = true;
}
Dep.prototype.init.call(this);
},
getSelectBoolFilterList: function () {
if (this.assignmentPermission == 'team') {
return ['onlyMyTeam'];
}
}
});