Hopefully re-greening the build.

This commit is contained in:
Dan Cryer 2014-12-22 15:48:35 +00:00
commit ead24da1a5
4 changed files with 34 additions and 26 deletions

View file

@ -47,24 +47,7 @@ class Application extends b8\Application
return false;
};
// Check settings for disable_authentication enabled and user_id
$skipAuth = function () {
$config = b8\Config::getInstance();
$state = (bool)$config->get('phpci.authentication_settings.state', false);
$id = $config->get('phpci.authentication_settings.user_id', 0);
if (false !== $state && 0 != (int)$id) {
$user = b8\Store\Factory::getStore('User')
->getByPrimaryKey($id);
if ($user) {
$_SESSION['phpci_user'] = $user;
return true;
}
}
return false;
};
$skipAuth = [$this, 'shouldSkipAuth'];
// Handler for the route we're about to register, checks for a valid session where necessary:
$routeHandler = function (&$route, Response &$response) use (&$request, $validateSession, $skipAuth) {
@ -152,4 +135,27 @@ class Application extends b8\Application
$projectStore = b8\Store\Factory::getStore('Project');
$layout->projects = $projectStore->getAll();
}
/**
* Check whether we should skip auth (because it is disabled)
* @return bool
*/
protected function shouldSkipAuth()
{
$config = b8\Config::getInstance();
$state = (bool)$config->get('phpci.authentication_settings.state', false);
$userId = $config->get('phpci.authentication_settings.user_id', 0);
if (false !== $state && 0 != (int)$userId) {
$user = b8\Store\Factory::getStore('User')
->getByPrimaryKey($userId);
if ($user) {
$_SESSION['phpci_user'] = $user;
return true;
}
}
return false;
}
}

View file

@ -62,16 +62,16 @@ class SettingsController extends Controller
$buildSettings = $this->settings['phpci']['build'];
}
$authenticationSettings = array();
$authSettings = array();
if (isset($this->settings['phpci']['authentication_settings'])) {
$authenticationSettings = $this->settings['phpci']['authentication_settings'];
$authSettings = $this->settings['phpci']['authentication_settings'];
}
$this->view->github = $this->getGithubForm();
$this->view->emailSettings = $this->getEmailForm($emailSettings);
$this->view->buildSettings = $this->getBuildForm($buildSettings);
$this->view->isWriteable = $this->canWriteConfig();
$this->view->authenticationSettings = $this->getAuthenticationForm($authenticationSettings);
$this->view->authenticationSettings = $this->getAuthenticationForm($authSettings);
if (!empty($this->settings['phpci']['github']['token'])) {
$this->view->githubUser = $this->getGithubUser($this->settings['phpci']['github']['token']);

View file

@ -260,13 +260,13 @@ class WebhookController extends \PHPCI\Controller
// build on merge request events
if (isset($payload['object_kind']) && $payload['object_kind'] == 'merge_request') {
$attributes = $payload['object_attributes'];
if ( $attributes['state'] == 'opened' || $attributes['state'] == 'reopened') {
if ($attributes['state'] == 'opened' || $attributes['state'] == 'reopened') {
$branch = $attributes['source_branch'];
$commit = $attributes['last_commit'];
$committer = $commit['author']['email'];
$this->createBuild($project, $commit['id'], $branch, $committer, $commit['message'] );
$this->createBuild($project, $commit['id'], $branch, $committer, $commit['message']);
}
}

View file

@ -123,11 +123,13 @@ class BuildStore extends BuildStoreBase
$select = '`bm`.`build_id`, `bm`.`meta_key`, `bm`.`meta_value`';
$and = $numResults > 1 ? ' AND (`bm`.`build_id` <= :buildId) ' : ' AND (`bm`.`build_id` = :buildId) ';
$where = '`bm`.`meta_key` = :key AND `bm`.`project_id` = :projectId ' . $and;
$from = ' `build_meta` AS `bm`';
if($branch !== null) {
$from = ' `build_meta` AS `bm`';
if ($branch !== null) {
$where .= ' AND `b`.`branch` = :branch AND `b`.`id`= `bm`.`build_id` ';
$from .= ', `build` AS `b`';
}
}
$query = 'SELECT '.$select.' FROM '.$from.' WHERE '.$where.' ORDER BY `bm`.id DESC LIMIT :numResults';
$stmt = Database::getConnection('read')->prepare($query);