public function __construct() { $sites = (new WebSite())->getList(); $user = GithubLogin::getLoginUser(); $validSites = array(); $adminSites = array(); foreach ($sites as $m) { if (!empty($user->permissions[$m['siteId']])) { $validSites[] = $m; if (DeployPermissions::havePermission(DeployPermissions::WRITE, $user->permissions[$m['siteId']])) { $adminSites[] = $m['siteId']; } } } $isSuperUser = false; $i = 0; while (!empty($_ENV["SUPER_USERS.{$i}"])) { if ($_ENV["SUPER_USERS.{$i}"] == $user->login) { $isSuperUser = true; break; } $i++; } $this->validSites = $validSites; View::share('sites', $validSites); View::share('isSuperUser', $isSuperUser); View::share('adminSites', $adminSites); }
public function deploy($siteId) { $pr = new PullRequest($siteId); $commits = $pr->getList(); $commitList = array(); foreach ($commits as $m) { if ($m->testStatus == 'Success' && $m->status == 'open') { $commitList[] = array('title' => $m->title, 'commit' => $m->commit); } } $ht = new HostType(); $hostTypes = $ht->getList(); $hostList = array(); foreach ($hostTypes as $hostType) { $hostList = array_merge($hostList, (new SiteHost($siteId, $hostType, SiteHost::STATIC_HOST))->getList()); $hostList = array_merge($hostList, (new SiteHost($siteId, $hostType, SiteHost::WEB_HOST))->getList()); } $existHostTypes = array(); $user = GithubLogin::getLoginUser(); $hp = (new HostType())->permissionList(); $deployPermissions = array(); foreach ($_ENV as $key => $value) { if (strpos($key, 'DEPLOY_PERMISSIONS') === 0) { $deployPermissions[substr($key, strlen('DEPLOY_PERMISSIONS') + 1)] = $value; } } $userTeams = array(); foreach ($user->teams as $team) { $userTeams[] = $team->name; } foreach ($hostList as $host) { //Debugbar::info($user->permissions[$siteId] . ' ' . $hp[$host['hosttype']]); $canDeploy = true; if (!empty($deployPermissions[$host['hosttype']])) { $teamName = $deployPermissions[$host['hosttype']]; if (!in_array($teamName, $userTeams)) { $canDeploy = false; } } if ($canDeploy && !empty($user->permissions[$siteId]) && $hp[$host['hosttype']] == 'pull' && DeployPermissions::havePermission($hp[$host['hosttype']], $user->permissions[$siteId])) { $existHostTypes[$host['hosttype']] = $host['hosttype']; } } $pr = new PullRequest($siteId); $list = $pr->getList(); $prList = array(); foreach ($list as &$m) { $prList[$m->commit] = array('url' => $m->url, 'repo' => $m->repo, 'branch' => $m->branch); } $prd = new PullRequestDeploy($siteId); $prdList = $prd->getList(); return View::make('pullrequest.deploy', array('siteId' => $siteId, 'leftNavActive' => 'pullRequestDeploy', 'commitList' => $commitList, 'hostTypeList' => $existHostTypes, 'toDeploy' => Input::get('toDeploy'), 'prdList' => $prdList, 'prList' => $prList)); }
public function maxPermissionOfRepo($repoFullName) { if ($repoFullName == 'heimonsy/eleme-deploy') { return DeployPermissions::PULL; } $maxPermission = DeployPermissions::DENY; foreach ($this->teams as $team) { $repos = new TeamRepos($team->id, $this->token); foreach ($repos->repos() as $repo) { if ($repo->fullName == $repoFullName && DeployPermissions::havePermission($maxPermission, $team->permission)) { $maxPermission = $team->permission; } } } return $maxPermission == DeployPermissions::DENY ? NULL : $maxPermission; }
public function index($siteId) { $defaultBranch = (new DC($siteId))->get(DC::DEFAULT_BRANCH); $commitVersion = (new CommitVersion($siteId))->getList(); $infoList = (new DeployInfo($siteId))->getList(); $hostTypes = (new HostType())->getList(); $hostList = array(); foreach ($hostTypes as $hostType) { $hostList = array_merge($hostList, (new SiteHost($siteId, $hostType, SiteHost::STATIC_HOST))->getList()); $hostList = array_merge($hostList, (new SiteHost($siteId, $hostType, SiteHost::WEB_HOST))->getList()); } $existHostTypes = array(); $user = GithubLogin::getLoginUser(); $hp = (new HostType())->permissionList(); $deployPermissions = array(); foreach ($_ENV as $key => $value) { if (strpos($key, 'DEPLOY_PERMISSIONS') === 0) { $deployPermissions[substr($key, strlen('DEPLOY_PERMISSIONS') + 1)] = $value; } } $userTeams = array(); foreach ($user->teams as $team) { $userTeams[] = $team->name; } foreach ($hostList as $host) { //Debugbar::info($user->permissions[$siteId] . ' ' . $hp[$host['hosttype']]); $canDeploy = true; if (!empty($deployPermissions[$host['hosttype']])) { $teamName = $deployPermissions[$host['hosttype']]; if (!in_array($teamName, $userTeams)) { $canDeploy = false; } } if ($canDeploy && !empty($user->permissions[$siteId]) && DeployPermissions::havePermission($hp[$host['hosttype']], $user->permissions[$siteId])) { $existHostTypes[$host['hosttype']] = $host['hosttype']; } } return View::make('deploy.deploy', array('defaultBranch' => $defaultBranch, 'commit_version' => $commitVersion, 'results' => $infoList, 'hostTypes' => $existHostTypes, 'siteId' => $siteId, 'leftNavActive' => 'deploy')); }