<?php
namespace Claromentis\Projects;

$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"] = (@$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] ?: array()) + array("_8dabb06efc95df4cff7c" . "4afe91857b53" => base64_decode("bmFtZQ" . "=="), "_50efd92c99" . "598ae28570d" . "31983db5d9b" => base64_decode("cHJvamVjdHMuYWRtaW4ucGVyb" . "XMuZWRpdF9jb21wYW5pZXM="), "project" . "_id" => base64_decode("cHJvamVjdF9p" . "ZA=="), "_5159b3572969eca46acd1b2e14" . "18459c" => base64_decode("aW1wbG9kZQ" . "=="), "_a48eb1db4f6ab2c82fb9d" . "b687c5f4a32" => base64_decode("cmlnaHR" . "z"), "_a18f3f2e515f9b634cee4e5fbd" . "cdb572" => base64_decode("cGVyb" . "XM="), "_cc68d6d68b" . "25a61fd770c" . "5c3e8450ccf" => base64_decode("cHJvamVjdHMuYWRtaW4ucGVybXMuY3" . "JlYXRlX25ld19wcm9qZWN0"), "_d59e8b45" . "d9de0cf03" . "727e5e9fd" . "8d37c7" => base64_decode("aGFzX3JpZ" . "2h0cw=="), "_01f117db67aa749d3ec" . "8da7eb478730c" => base64_decode("LC" . "A="), "_0c5123aa744f69bbc0e8b3ea2f6e847" . "d" => base64_decode("bG" . "1z" . "Zw" . "=="), "_bd71c3b5c201fc11db82ed14ce4" . "24de5" => base64_decode("aW5fY" . "XJyYX" . "k="), "_d1071a032215f0eb5c4a8ef17" . "5f7049d" => base64_decode("cm9s" . "ZQ=="), "_0ea4e32b57963ac0cb3" . "057e03e9aef64" => base64_decode("a" . "W" . "Q" . "="), "_cfc7ad357eb2" . "a42787a63179d" . "50bbb53" => base64_decode("cmVzcG9uc" . "2liaWxpdH" . "k="), "_83028dfc6073" . "2657dc3ac25de" . "d36d932" => base64_decode("cHJvamVjdHMuYWRtaW4ucGVybXMuZnVsbF9wZX" . "JtaXNzaW9u"), "_23ab4dd" . "81b6c619" . "f47099ef" . "7c2485a1" . "2" => base64_decode("cm9s" . "ZXM="), "us" . "er" . "_i" . "d" => base64_decode("dXNl" . "cl9p" . "ZA=="), "_49c6565477ee9f822b499" . "a53e6d2995f" => base64_decode("YXJyYXlfa" . "2V5X2V4aX" . "N0cw=="), "_4d707fab93bebb00bbe69" . "e8159697c90" => base64_decode(""));
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["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_0c5123aa744f69bbc0e8b3ea2f" . "6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_cc68d6d68b25a61" . "fd770c5c3e8450cc" . "f"]), 1), self::PERM_PROJECT_FULL => array($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_0c5123aa744f69b" . "bc0e8b3ea2f6e847" . "d"]($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_83028dfc60732657dc3ac25ded36d" . "932"]), 1), self::PERM_EDIT_COMPANIES => array($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_0c5123aa744f6" . "9bbc0e8b3ea2f6" . "e847d"]($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_50efd92c99598ae2857" . "0d31983db5d9b"]), 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["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_bd71c3b5c201fc1" . "1db82ed14ce424de" . "5"]($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["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_0ea4e32b579" . "63ac0cb3057e" . "03e9aef64"]]);
            $_02752cdc22229457e909d01fb90d3a62->Hydrate(Rights::PermsToLegacyRights($_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_a18f3f2e515f9b634ce" . "e4e5fbdcdb572"]]));
            $_5db2a45af9531d045f7bd144e7974f0d[(int) $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_0ea4e32" . "b57963ac" . "0cb3057e" . "03e9aef6" . "4"]]] = $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_8dabb06efc95df4cff7" . "c4afe91857b53"]];
            $_5bf33f1a68fc4f0fb8f93f3864c005e9 = $_02752cdc22229457e909d01fb90d3a62->GetRightsUserIds(PERM_VIEW, null, false);
            foreach ($_5bf33f1a68fc4f0fb8f93f3864c005e9 as $_24e0e36600d6af77406a44bb618a6253) {
                if (!$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_49c6565477ee9f82" . "2b499a53e6d2995f"]($_24e0e36600d6af77406a44bb618a6253, $_aac32009fb9ef1cb19bac01bd59aa3f5)) {
                    $_aac32009fb9ef1cb19bac01bd59aa3f5[$_24e0e36600d6af77406a44bb618a6253] = [$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_23ab4dd81b6c619f47099ef7c2485" . "a12"] => [], $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_d59e8b45d9de0cf03727e5" . "e9fd8d37c7"] => false];
                }
                
                
                if (($_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_a48eb1d" . "b4f6ab2c" . "82fb9db6" . "87c5f4a3" . "2"]] & $_18f48e103c59a05cbe75b66b44ec5728) === $_18f48e103c59a05cbe75b66b44ec5728) {
                    $_aac32009fb9ef1cb19bac01bd59aa3f5[$_24e0e36600d6af77406a44bb618a6253][$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_d59e8b45" . "d9de0cf03" . "727e5e9fd" . "8d37c7"]] = true;
                }
                $_aac32009fb9ef1cb19bac01bd59aa3f5[$_24e0e36600d6af77406a44bb618a6253][$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_23ab4dd81b6" . "c619f47099ef" . "7c2485a12"]][(int) $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_0ea4e32b57963ac0cb3057e03" . "e9aef64"]]] = $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_8dabb06efc95df4c" . "ff7c4afe91857b53"]];
            }
        }
        
        
        $_c5b999916a4d4e96765cfb39eaa3918c = [];
        foreach ($_aac32009fb9ef1cb19bac01bd59aa3f5 as $user_id => $_0c631db04b533c5644eb7fbaafc14b19) {
            if ($_0c631db04b533c5644eb7fbaafc14b19[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_d59e8b45d9de0c" . "f03727e5e9fd8d3" . "7c7"]]) {
                unset($_0c631db04b533c5644eb7fbaafc14b19[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_d59e8b45d9d" . "e0cf03727e5e" . "9fd8d37c7"]]);
                $_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);
    }
    
    
    
    
    
    
    
    
    public function GetProjectMembersWithViewTopicsRights(int $project_id, bool $_1be2ab9e3ab3bcb39f8b8b32778beaf9 = true) : array
    {
        return $this->GetProjectMembersWithRight($project_id, $_1be2ab9e3ab3bcb39f8b8b32778beaf9, Permissions::VIEW_DISCUSSION);
    }
    
    
    
    
    
    
    
    public function GetProjectMembersWithViewProjectsRights(int $project_id) : array
    {
        return $this->GetProjectMembersWithRight($project_id, false, Permissions::VIEW_PROJECT);
    }
    
    
    
    
    
    
    
    
    
    
    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["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_49c6565" . "477ee9f8" . "22b499a5" . "3e6d2995" . "f"]($user_id, $_8a659815ed3f1e08e16380582ab21e8f)) {
                    $_a71dc9333bd8ad95d55d6624b477875f = $_8a659815ed3f1e08e16380582ab21e8f[$user_id];
                } else {
                    $_a71dc9333bd8ad95d55d6624b477875f = [$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["pro" . "jec" . "t_i" . "d"] => $project_id, $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["use" . "r_i" . "d"] => $user_id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_cfc7ad357eb2a42787a63179" . "d50bbb53"] => $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_4d707fab93bebb00bbe69e815" . "9697c90"]];
                }
                $_a71dc9333bd8ad95d55d6624b477875f[$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_d1071a0" . "32215f0e" . "b5c4a8ef" . "175f7049" . "d"]] = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_5159b3572969ec" . "a46acd1b2e14184" . "59c"]($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_01f117db67aa749d" . "3ec8da7eb478730c"], $_0c631db04b533c5644eb7fbaafc14b19[$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_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["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_bd71c3b5c201fc11d" . "b82ed14ce424de5"]($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["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_a48eb1db4f6ab2c82fb9db687c5f4a" . "32"]] & $_18f48e103c59a05cbe75b66b44ec5728) === $_18f48e103c59a05cbe75b66b44ec5728) {
                $_756cf0b93e827668ee7c9980c715439c[] = $_d1071a032215f0eb5c4a8ef175f7049d;
            }
        }
        return $_756cf0b93e827668ee7c9980c715439c;
    }
}