<?php
namespace Claromentis\Projects;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"] ?: array()) + array("_4d707fab93bebb00bbe69e8" . "159697c90" => base64_decode(""), "_a18f3f2e515f9" . "b634cee4e5fbdc" . "db572" => base64_decode("cG" . "Vy" . "bX" . "M="), "_0c5123aa74" . "4f69bbc0e8b" . "3ea2f6e847d" => base64_decode("bG1zZ" . "w=="), "_83028dfc60732" . "657dc3ac25ded3" . "6d932" => base64_decode("cHJvamVjdHMuYWRtaW4ucGVybXMuZnVsbF9wZXJtaXNza" . "W9u"), "_01f117db67aa749d3ec8da7eb478730" . "c" => base64_decode("L" . "C" . "A" . "="), "projec" . "t_id" => base64_decode("cHJva" . "mVjdF" . "9pZA=" . "="), "_cc68d6d68b25a61" . "fd770c5c3e8450cc" . "f" => base64_decode("cHJvamVjdHMuYWRtaW4uc" . "GVybXMuY3JlYXRlX25ld1" . "9wcm9qZWN0"), "_d59e8b45d9de0cf03727e5e9fd8d3" . "7c7" => base64_decode("aGFz" . "X3Jp" . "Z2h0" . "cw=="), "_49c6565477ee9f822b499a53e6d" . "2995f" => base64_decode("YXJyYXlfa2V5" . "X2V4aXN0cw=="), "_50efd92c99598ae28570d31983db5d9" . "b" => base64_decode("cHJvamVjdHMuYWRtaW4ucGVybXMuZWRpdF9jb21" . "wYW5pZXM="), "user_" . "id" => base64_decode("dXNl" . "cl9p" . "ZA=="), "_23ab4dd81b6c619f47099ef7c24" . "85a12" => base64_decode("cm9" . "sZX" . "M="), "_bd71c3b5c2" . "01fc11db82e" . "d14ce424de5" => base64_decode("aW5fYXJyY" . "Xk="), "_a48eb1db4f6ab2c82f" . "b9db687c5f4a32" => base64_decode("cmlnaH" . "Rz"), "_d1071a032215f0eb5c" . "4a8ef175f7049d" => base64_decode("cm9s" . "ZQ=="), "_8dabb06efc95df4cff7c4" . "afe91857b53" => base64_decode("bmFtZQ=" . "="), "_cfc7ad357eb2" . "a42787a63179d" . "50bbb53" => base64_decode("cmVzcG" . "9uc2li" . "aWxpdH" . "k="), "_5159b3572969eca46acd1b2e141" . "8459c" => base64_decode("aW1wb" . "G9kZQ" . "=="), "_0ea4e32b57963ac0cb3057e" . "03e9aef64" => base64_decode("aWQ" . "="));
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["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_0c5123aa744f69bbc0e8b3ea2f6" . "e847d"]($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_cc68d6d68b25a61fd770c5c3e8450c" . "cf"]), 1), self::PERM_PROJECT_FULL => array($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_0c5123aa744f69bbc0e8b3ea2f6e84" . "7d"]($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_83028dfc60732657dc3ac25ded" . "36d932"]), 1), self::PERM_EDIT_COMPANIES => array($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_0c5123aa744f6" . "9bbc0e8b3ea2f6" . "e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_50efd92c99598ae28570d319" . "83db5d9b"]), 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["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_bd71c3b5c201fc11d" . "b82ed14ce424de5"]($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["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_0ea4e32b5796" . "3ac0cb3057e03" . "e9aef64"]]);
            $_02752cdc22229457e909d01fb90d3a62->Hydrate(Rights::PermsToLegacyRights($_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_a18f3f2e515f9b634cee4e5" . "fbdcdb572"]]));
            $_5db2a45af9531d045f7bd144e7974f0d[(int) $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_0ea4e32b57963ac0cb3057e03e9ae" . "f64"]]] = $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_8dabb06efc95df4cff7c4afe9" . "1857b53"]];
            $_5bf33f1a68fc4f0fb8f93f3864c005e9 = $_02752cdc22229457e909d01fb90d3a62->GetRightsUserIds(PERM_VIEW, null, false);
            foreach ($_5bf33f1a68fc4f0fb8f93f3864c005e9 as $_24e0e36600d6af77406a44bb618a6253) {
                if (!$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_49c6565477ee9f822b499a53e6d2995" . "f"]($_24e0e36600d6af77406a44bb618a6253, $_aac32009fb9ef1cb19bac01bd59aa3f5)) {
                    $_aac32009fb9ef1cb19bac01bd59aa3f5[$_24e0e36600d6af77406a44bb618a6253] = [$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_23ab4dd81b6c619f47099ef7c2485a" . "12"] => [], $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_d59e8b45d9d" . "e0cf03727e5e" . "9fd8d37c7"] => false];
                }
                
                
                if (($_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_a48eb1db4f6ab2c82f" . "b9db687c5f4a32"]] & $_18f48e103c59a05cbe75b66b44ec5728) === $_18f48e103c59a05cbe75b66b44ec5728) {
                    $_aac32009fb9ef1cb19bac01bd59aa3f5[$_24e0e36600d6af77406a44bb618a6253][$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_d59e8b45d9de0cf03727e5e9fd8d37" . "c7"]] = true;
                }
                $_aac32009fb9ef1cb19bac01bd59aa3f5[$_24e0e36600d6af77406a44bb618a6253][$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_23ab4dd81b6c619f47099ef7c" . "2485a12"]][(int) $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_0ea4e32b57963ac0" . "cb3057e03e9aef64"]]] = $_d1071a032215f0eb5c4a8ef175f7049d[$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_8dabb06efc95" . "df4cff7c4afe9" . "1857b53"]];
            }
        }
        
        
        $_c5b999916a4d4e96765cfb39eaa3918c = [];
        foreach ($_aac32009fb9ef1cb19bac01bd59aa3f5 as $user_id => $_0c631db04b533c5644eb7fbaafc14b19) {
            if ($_0c631db04b533c5644eb7fbaafc14b19[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_d59e8b45d9de0cf0" . "3727e5e9fd8d37c7"]]) {
                unset($_0c631db04b533c5644eb7fbaafc14b19[$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_d59e8b45d9de0cf0" . "3727e5e9fd8d37c7"]]);
                $_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["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_49c6565477ee9f822b499a53" . "e6d2995f"]($user_id, $_8a659815ed3f1e08e16380582ab21e8f)) {
                    $_a71dc9333bd8ad95d55d6624b477875f = $_8a659815ed3f1e08e16380582ab21e8f[$user_id];
                } else {
                    $_a71dc9333bd8ad95d55d6624b477875f = [$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["proj" . "ect_" . "id"] => $project_id, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["use" . "r_i" . "d"] => $user_id, $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_cfc7ad357eb2a42787a631" . "79d50bbb53"] => $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_4d707fab" . "93bebb00b" . "be69e8159" . "697c90"]];
                }
                $_a71dc9333bd8ad95d55d6624b477875f[$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_d1071a032215f0eb5c4" . "a8ef175f7049d"]] = $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_5159b3572969eca46" . "acd1b2e1418459c"]($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_01f117db67aa749d3ec8da7e" . "b478730c"], $_0c631db04b533c5644eb7fbaafc14b19[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_23ab4dd81b6c619f47099" . "ef7c2485a12"]]);
                $_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["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_bd71c3b5c201fc" . "11db82ed14ce424" . "de5"]($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["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_a48eb1db4f6ab2" . "c82fb9db687c5f4" . "a32"]] & $_18f48e103c59a05cbe75b66b44ec5728) === $_18f48e103c59a05cbe75b66b44ec5728) {
                $_756cf0b93e827668ee7c9980c715439c[] = $_d1071a032215f0eb5c4a8ef175f7049d;
            }
        }
        return $_756cf0b93e827668ee7c9980c715439c;
    }
}