<?php
namespace Claromentis\Projects;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"] ?: array()) + array("_4d707fab93" . "bebb00bbe69" . "e8159697c90" => base64_decode(""), "us" . "er" . "_i" . "d" => base64_decode("dXNlcl" . "9pZA=="), "_23ab4dd8" . "1b6c619f4" . "7099ef7c2" . "485a12" => base64_decode("cm9sZ" . "XM="), "_0c5123aa744f6" . "9bbc0e8b3ea2f6" . "e847d" => base64_decode("bG1zZw" . "=="), "_bd71c3b5c201fc11db82ed14ce424" . "de5" => base64_decode("aW5fY" . "XJyYX" . "k="), "_0ea4e32b57963ac0cb3057e03e9a" . "ef64" => base64_decode("aWQ" . "="), "_01f117db67aa749d3ec8da7" . "eb478730c" => base64_decode("LCA" . "="), "_a18f3f2e515f9b634cee4e5fbdcd" . "b572" => base64_decode("cGVybXM" . "="), "_d1071a032215f0eb5c4a8" . "ef175f7049d" => base64_decode("cm9s" . "ZQ=="), "_cfc7ad35" . "7eb2a4278" . "7a63179d5" . "0bbb53" => base64_decode("cmVzcG9uc2liaWxpdH" . "k="), "_a48eb1db4f6ab2c82fb" . "9db687c5f4a32" => base64_decode("cmln" . "aHRz"), "_50efd92c99598ae28570d31983db5" . "d9b" => base64_decode("cHJvamVjdHMuYWRtaW4ucGVybXMuZWRpdF9jb" . "21wYW5pZXM="), "_8dabb06efc95d" . "f4cff7c4afe918" . "57b53" => base64_decode("bm" . "Ft" . "ZQ" . "=="), "_cc68d6d68b25a61fd770c5c3e84" . "50ccf" => base64_decode("cHJvamVjdHMuYWRtaW4ucGVybXMuY3JlYXRlX25ld1" . "9wcm9qZWN0"), "_83028dfc60732657dc3ac25ded3" . "6d932" => base64_decode("cHJvamVjdHMuYWRtaW4ucGVybXMuZnVsbF9wZXJta" . "XNzaW9u"), "_5159b3572969eca46a" . "cd1b2e1418459c" => base64_decode("aW1wbG9" . "kZQ=="), "_d59e8b45d9de0cf03727e5" . "e9fd8d37c7" => base64_decode("aGFzX3JpZ2h" . "0cw=="), "_49c6565" . "477ee9f8" . "22b499a5" . "3e6d2995" . "f" => base64_decode("YXJyYXl" . "fa2V5X2" . "V4aXN0c" . "w=="), "proj" . "ect_" . "id" => base64_decode("cHJva" . "mVjdF" . "9pZA=" . "="));
use Claromentis\Core\Acl\Acl;
use Claromentis\Core\Acl\RoleBased\RoleAclChecker;
use Claromentis\Core\Acl\RoleBased\RoleRepository;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Projects\Acl\Rights;
use Claromentis\Projects\Model\Member;
use Claromentis\Projects\Model\Task;
use Claromentis\Projects\Repository\TaskRepository;
use Claromentis\Projects\Repository\TeamRepository;






class PermissionsMap
{
    const PERM_PROJECT_CREATE = 1;
    const PERM_PROJECT_FULL = 2;
    const PERM_EDIT_COMPANIES = 4;
    
    
    const CREATE_PROJECT = 23;
    const EDIT_COMPANIES = 24;
    
    
    const EDIT_ADHOC_TASK = 24;
    const VIEW_ADHOC_TASK = 25;
    const UPDATE_ADHOC_TASK = 26;
    
    
    protected $team_repository;
    
    
    protected $task_repository;
    
    
    protected $admin_acl;
    
    
    protected $role_acl;
    
    
    protected $role_repository;
    public function __construct(TeamRepository $team_repository, TaskRepository $task_repository, Acl $_8b4fbf19a40cd35b5144ef4d8ee73220, RoleAclChecker $_ce30a1539f2fa7dff639ac636142d216, RoleRepository $_90f6cb30a269a622b4c838bfd5a0a5db)
    {
        $this->team_repository = $team_repository;
        $this->task_repository = $task_repository;
        $this->admin_acl = $_8b4fbf19a40cd35b5144ef4d8ee73220;
        $this->role_acl = $_ce30a1539f2fa7dff639ac636142d216;
        $this->role_repository = $_90f6cb30a269a622b4c838bfd5a0a5db;
    }
    public function GetAdminPermsDialogArray()
    {
        return array(self::PERM_PROJECT_CREATE => array($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_0c5123aa744f69bbc0e8b3ea2f" . "6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_cc68d6d68b25a61" . "fd770c5c3e8450cc" . "f"]), 1), self::PERM_PROJECT_FULL => array($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_0c5123a" . "a744f69b" . "bc0e8b3e" . "a2f6e847" . "d"]($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_83028dfc60732657dc3ac25ded3" . "6d932"]), 1), self::PERM_EDIT_COMPANIES => array($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_0c5123aa744f69bbc0e8b3ea2f6e" . "847d"]($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_50efd92c99598ae28570d31983d" . "b5d9b"]), 1));
    }
    
    
    
    
    
    
    
    public function PermitsProjectAction(SecurityContext $context, $project_id, $_18f48e103c59a05cbe75b66b44ec5728) : bool
    {
        
        
        if ($_18f48e103c59a05cbe75b66b44ec5728 === self::CREATE_PROJECT) {
            $_3d408935c467487f7ef90c6ba73977ee = false;
            if ($this->admin_acl->Permits($context, self::PERM_PROJECT_CREATE) || $this->admin_acl->Permits($context, self::PERM_PROJECT_FULL)) {
                $_3d408935c467487f7ef90c6ba73977ee = true;
            }
            return $_3d408935c467487f7ef90c6ba73977ee;
        }
        if ($_18f48e103c59a05cbe75b66b44ec5728 === self::EDIT_COMPANIES) {
            $_3d408935c467487f7ef90c6ba73977ee = false;
            if ($this->admin_acl->Permits($context, self::PERM_EDIT_COMPANIES) || $this->admin_acl->Permits($context, self::PERM_PROJECT_FULL)) {
                $_3d408935c467487f7ef90c6ba73977ee = true;
            }
            return $_3d408935c467487f7ef90c6ba73977ee;
        }
        
        
        if ($this->admin_acl->Permits($context, self::PERM_PROJECT_FULL)) {
            return true;
        }
        return $this->role_acl->DoesUserHaveRight(Permissions::PROJECT_AGGREGATION, $project_id, $context->GetUserId(), $_18f48e103c59a05cbe75b66b44ec5728);
    }
    
    
    
    
    
    
    
    public function PermitsTaskAction(SecurityContext $context, $task_id, $_1ac701da0834eb6c188cf3ef004a1aca) : bool
    {
        
        
        if ($this->admin_acl->Permits($context, self::PERM_PROJECT_FULL)) {
            return true;
        }
        $_696b535739055ed7d827709916d07dea = $this->task_repository->LoadTask($task_id);
        $user_id = $context->GetUserId();
        
        
        $_3d408935c467487f7ef90c6ba73977ee = false;
        switch ($_1ac701da0834eb6c188cf3ef004a1aca) {
            case self::VIEW_ADHOC_TASK:
            case self::UPDATE_ADHOC_TASK:
            case Permissions::VIEW_DISCUSSION:
            case Permissions::PARTICIPATE_IN_DISCUSSION:
                if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_bd71c3b5c201fc11db82ed14c" . "e424de5"]($user_id, $_696b535739055ed7d827709916d07dea->GetAssignees()) || $user_id == $_696b535739055ed7d827709916d07dea->GetCreatorId()) {
                    $_3d408935c467487f7ef90c6ba73977ee = true;
                }
                break;
            case self::EDIT_ADHOC_TASK:
                if ($user_id == $_696b535739055ed7d827709916d07dea->GetCreatorId()) {
                    $_3d408935c467487f7ef90c6ba73977ee = true;
                }
                break;
        }
        return $_3d408935c467487f7ef90c6ba73977ee;
    }
    public function GetObjectIDsWithRight(int $user_id, int $_18f48e103c59a05cbe75b66b44ec5728)
    {
        return $this->role_acl->GetObjectsForUserWithRight(Permissions::PROJECT_AGGREGATION, $user_id, $_18f48e103c59a05cbe75b66b44ec5728);
    }
    public function PermitsFullAccess(SecurityContext $context)
    {
        $_1f24efd4735b7a11b391147435e7d35d = false;
        if ($this->admin_acl->Permits($context, self::PERM_PROJECT_FULL)) {
            $_1f24efd4735b7a11b391147435e7d35d = true;
        }
        return $_1f24efd4735b7a11b391147435e7d35d;
    }
    public function PermitsCreateProjects(SecurityContext $context)
    {
        $_1f24efd4735b7a11b391147435e7d35d = false;
        if ($this->admin_acl->Permits($context, self::PERM_PROJECT_CREATE) || $this->PermitsFullAccess($context)) {
            $_1f24efd4735b7a11b391147435e7d35d = true;
        }
        return $_1f24efd4735b7a11b391147435e7d35d;
    }
    public function PermitsEditCompanies(SecurityContext $context)
    {
        $_1f24efd4735b7a11b391147435e7d35d = false;
        if ($this->admin_acl->Permits($context, self::PERM_EDIT_COMPANIES) || $this->PermitsFullAccess($context)) {
            $_1f24efd4735b7a11b391147435e7d35d = true;
        }
        return $_1f24efd4735b7a11b391147435e7d35d;
    }
    
    
    
    
    
    
    
    
    
    public function GetMemberRolesWithRight(int $project_id, int $_18f48e103c59a05cbe75b66b44ec5728) : array
    {
        $_23ab4dd81b6c619f47099ef7c2485a12 = $this->role_repository->GetRolesPopulated(Permissions::PROJECT_AGGREGATION, $project_id);
        $_5db2a45af9531d045f7bd144e7974f0d = [];
        $_aac32009fb9ef1cb19bac01bd59aa3f5 = [];
        
        
        foreach ($_23ab4dd81b6c619f47099ef7c2485a12 as $_d1071a032215f0eb5c4a8ef175f7049d) {
            $_02752cdc22229457e909d01fb90d3a62 = new Acl(RoleRepository::PERM_CLASS_ACL_ROLE, (int) $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_0ea4e32b57963ac0" . "cb3057e03e9aef64"]]);
            $_02752cdc22229457e909d01fb90d3a62->Hydrate(Rights::PermsToLegacyRights($_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_a18f3f2e515f9b634cee" . "4e5fbdcdb572"]]));
            $_5db2a45af9531d045f7bd144e7974f0d[(int) $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_0ea4e32b5796" . "3ac0cb3057e03" . "e9aef64"]]] = $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_8dabb06efc95df4cff7c4a" . "fe91857b53"]];
            $_5bf33f1a68fc4f0fb8f93f3864c005e9 = $_02752cdc22229457e909d01fb90d3a62->GetRightsUserIds(PERM_VIEW, null, false);
            foreach ($_5bf33f1a68fc4f0fb8f93f3864c005e9 as $_24e0e36600d6af77406a44bb618a6253) {
                if (!$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_49c656547" . "7ee9f822b4" . "99a53e6d29" . "95f"]($_24e0e36600d6af77406a44bb618a6253, $_aac32009fb9ef1cb19bac01bd59aa3f5)) {
                    $_aac32009fb9ef1cb19bac01bd59aa3f5[$_24e0e36600d6af77406a44bb618a6253] = [$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_23ab4dd81b6c619f47099ef7c2485" . "a12"] => [], $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_d59e8b45d9d" . "e0cf03727e5e" . "9fd8d37c7"] => false];
                }
                
                
                if (($_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_a48eb1db4f6ab2c82fb9db687c5f4a" . "32"]] & $_18f48e103c59a05cbe75b66b44ec5728) === $_18f48e103c59a05cbe75b66b44ec5728) {
                    $_aac32009fb9ef1cb19bac01bd59aa3f5[$_24e0e36600d6af77406a44bb618a6253][$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_d59e8b45d9de0cf03727e5e9fd8d3" . "7c7"]] = true;
                }
                $_aac32009fb9ef1cb19bac01bd59aa3f5[$_24e0e36600d6af77406a44bb618a6253][$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_23ab4dd81b6c619f47099ef7c2" . "485a12"]][(int) $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_0ea4e32b" . "57963ac0c" . "b3057e03e" . "9aef64"]]] = $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_8dabb06efc95d" . "f4cff7c4afe918" . "57b53"]];
            }
        }
        
        
        $_c5b999916a4d4e96765cfb39eaa3918c = [];
        foreach ($_aac32009fb9ef1cb19bac01bd59aa3f5 as $user_id => $_0c631db04b533c5644eb7fbaafc14b19) {
            if ($_0c631db04b533c5644eb7fbaafc14b19[$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_d59e8b45d9de0cf03727e5e9fd8d" . "37c7"]]) {
                unset($_0c631db04b533c5644eb7fbaafc14b19[$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_d59e8b45d9de0cf03727" . "e5e9fd8d37c7"]]);
                $_c5b999916a4d4e96765cfb39eaa3918c[$user_id] = $_0c631db04b533c5644eb7fbaafc14b19;
            }
        }
        return $_c5b999916a4d4e96765cfb39eaa3918c;
    }
    
    
    
    
    
    
    
    
    
    public function GetProjectTeamMembers($project_id, $_1be2ab9e3ab3bcb39f8b8b32778beaf9 = true)
    {
        return $this->GetProjectMembersWithRight($project_id, $_1be2ab9e3ab3bcb39f8b8b32778beaf9, Permissions::TEAM_MEMBER);
    }
    
    
    
    
    
    
    
    
    
    public function GetProjectMembersWithReceiveRights($project_id, $_1be2ab9e3ab3bcb39f8b8b32778beaf9 = true)
    {
        return $this->GetProjectMembersWithRight($project_id, $_1be2ab9e3ab3bcb39f8b8b32778beaf9, Permissions::TEAM_NOTIFICATIONS);
    }
    
    
    
    
    
    
    
    
    public function GetProjectMembersWithExtendedNotificationRights($project_id, $_1be2ab9e3ab3bcb39f8b8b32778beaf9 = true)
    {
        return $this->GetProjectMembersWithRight($project_id, $_1be2ab9e3ab3bcb39f8b8b32778beaf9, Permissions::EXTENDED_NOTIFICATIONS);
    }
    
    
    
    
    
    
    
    
    public function GetProjectMembersWithViewAllTasksRights($project_id, $_1be2ab9e3ab3bcb39f8b8b32778beaf9 = true)
    {
        return $this->GetProjectMembersWithRight($project_id, $_1be2ab9e3ab3bcb39f8b8b32778beaf9, Permissions::VIEW_ALL_TASKS);
    }
    
    
    
    
    
    
    
    
    
    
    protected function GetProjectMembersWithRight($project_id, $_1be2ab9e3ab3bcb39f8b8b32778beaf9 = true, $_18f48e103c59a05cbe75b66b44ec5728 = Permissions::TEAM_MEMBER)
    {
        $_8a659815ed3f1e08e16380582ab21e8f = $this->team_repository->GetKnownTeamMembers($project_id);
        $_aac32009fb9ef1cb19bac01bd59aa3f5 = $this->GetMemberRolesWithRight($project_id, $_18f48e103c59a05cbe75b66b44ec5728);
        $_e4543e131c67c631b14751cc849d1310 = [];
        
        
        foreach ($_aac32009fb9ef1cb19bac01bd59aa3f5 as $user_id => $_0c631db04b533c5644eb7fbaafc14b19) {
            if ($_1be2ab9e3ab3bcb39f8b8b32778beaf9) {
                if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_49c6565477ee9f822b499a53e6d2" . "995f"]($user_id, $_8a659815ed3f1e08e16380582ab21e8f)) {
                    $_a71dc9333bd8ad95d55d6624b477875f = $_8a659815ed3f1e08e16380582ab21e8f[$user_id];
                } else {
                    $_a71dc9333bd8ad95d55d6624b477875f = [$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["proje" . "ct_id"] => $project_id, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["user" . "_id"] => $user_id, $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_cfc7ad3" . "57eb2a42" . "787a6317" . "9d50bbb5" . "3"] => $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_4d707fab93bebb" . "00bbe69e8159697" . "c90"]];
                }
                $_a71dc9333bd8ad95d55d6624b477875f[$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_d1071a032215f0eb5c4a" . "8ef175f7049d"]] = $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_5159b3572969eca" . "46acd1b2e1418459" . "c"]($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_01f117db67aa749d3ec8da" . "7eb478730c"], $_0c631db04b533c5644eb7fbaafc14b19[$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_23ab4dd81b6c6" . "19f47099ef7c24" . "85a12"]]);
                $_a35dab1038a75763ebdb4c72b9c7d59a = new Member();
                $_a35dab1038a75763ebdb4c72b9c7d59a->LoadInfo($_a71dc9333bd8ad95d55d6624b477875f);
            } else {
                $_a35dab1038a75763ebdb4c72b9c7d59a = $user_id;
            }
            $_e4543e131c67c631b14751cc849d1310[] = $_a35dab1038a75763ebdb4c72b9c7d59a;
        }
        return $_e4543e131c67c631b14751cc849d1310;
    }
    
    
    
    
    public function CanViewTask(SecurityContext $context, Task $_696b535739055ed7d827709916d07dea) : bool
    {
        $project_id = $_696b535739055ed7d827709916d07dea->GetProject();
        
        
        if ($this->PermitsProjectAction($context, $project_id, Permissions::VIEW_ALL_TASKS)) {
            return true;
        }
        
        
        if (!$this->PermitsProjectAction($context, $project_id, Permissions::VIEW_TASKS)) {
            return false;
        }
        if ($_696b535739055ed7d827709916d07dea->GetPrivate()) {
            
            
            return $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_bd71c3b5c201fc11db82ed" . "14ce424de5"]($context->GetUserId(), $_696b535739055ed7d827709916d07dea->GetAssignees());
        }
        
        
        return true;
    }
    
    
    
    
    public function GetTaskOwnerAggregation() : int
    {
        return Permissions::PROJECT_AGGREGATION;
    }
    public function GetRolesWithAcl(int $project_id, int $_18f48e103c59a05cbe75b66b44ec5728) : array
    {
        $_23ab4dd81b6c619f47099ef7c2485a12 = $this->role_repository->GetRolesPopulated(Permissions::PROJECT_AGGREGATION, $project_id);
        $_756cf0b93e827668ee7c9980c715439c = [];
        foreach ($_23ab4dd81b6c619f47099ef7c2485a12 as $_d1071a032215f0eb5c4a8ef175f7049d) {
            if (($_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_a48eb1db4f6ab2c82fb9db687c5f4" . "a32"]] & $_18f48e103c59a05cbe75b66b44ec5728) === $_18f48e103c59a05cbe75b66b44ec5728) {
                $_756cf0b93e827668ee7c9980c715439c[] = $_d1071a032215f0eb5c4a8ef175f7049d;
            }
        }
        return $_756cf0b93e827668ee7c9980c715439c;
    }
}