From 8b0261417a351dd388b3943e1399ae63e5ac337f Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Fri, 11 Jul 2014 14:29:27 +0000 Subject: [PATCH] Various bits of cleanup, should hopefully fix the build --- PHPCI/Controller.php | 7 +++ PHPCI/Controller/ProjectController.php | 71 ++++++++++---------------- PHPCI/Helper/Github.php | 2 +- composer.lock | 13 +++-- 4 files changed, 40 insertions(+), 53 deletions(-) diff --git a/PHPCI/Controller.php b/PHPCI/Controller.php index 8b5cb806..1cc2633c 100644 --- a/PHPCI/Controller.php +++ b/PHPCI/Controller.php @@ -71,4 +71,11 @@ class Controller extends \b8\Controller return $this->response; } + + protected function requireAdmin() + { + if (!$_SESSION['user']->getIsAdmin()) { + throw new ForbiddenException('You do not have permission to do that.'); + } + } } diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index b2f86f40..b02e4f0c 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -152,10 +152,7 @@ class ProjectController extends \PHPCI\Controller public function add() { $this->config->set('page_title', 'Add Project'); - - if (!$_SESSION['user']->getIsAdmin()) { - throw new ForbiddenException('You do not have permission to do that.'); - } + $this->requireAdmin(); $method = $this->request->getMethod(); @@ -181,8 +178,13 @@ class ProjectController extends \PHPCI\Controller $view->key = $pub; return $view->render(); + } else { + return $this->addProject($form); } + } + protected function addProject(Form $form) + { $values = $form->getValues(); $matches = array(); @@ -291,69 +293,48 @@ class ProjectController extends \PHPCI\Controller 'hg' => 'Mercurial', ); - $field = new Form\Element\Select('type'); - $field->setRequired(true); + $field = Form\Element\Select::create('type', 'Where is your project hosted?', true); $field->setPattern('^(github|bitbucket|gitlab|remote|local|hg)'); $field->setOptions($options); - $field->setLabel('Where is your project hosted?'); - $field->setClass('form-control'); - $field->setContainerClass('form-group'); + $field->setClass('form-control')->setContainerClass('form-group'); $form->addField($field); - $container = new Form\ControlGroup('github-container'); $container->setClass('github-container'); - $field = new Form\Element\Select('github'); - $field->setLabel('Choose a Github repository:'); - $field->setClass('form-control'); - $field->setContainerClass('form-group'); + $field = Form\Element\Select::create('github', 'Choose a Github repository:', false); + $field->setClass('form-control')->setContainerClass('form-group'); $container->addField($field); $form->addField($container); - $field = new Form\Element\Text('reference'); - $field->setRequired(true); + $field = Form\Element\Text::create('reference', 'Repository Name / URL (Remote) or Path (Local)', true); $field->setValidator($this->getReferenceValidator($values)); - $field->setLabel('Repository Name / URL (Remote) or Path (Local)'); - $field->setClass('form-control'); - $field->setContainerClass('form-group'); + $field->setClass('form-control')->setContainerClass('form-group'); $form->addField($field); - $field = new Form\Element\Text('branch'); - $field->setRequired(true); - $field->setValidator($this->getReferenceValidator($values)); - $field->setLabel('Branch name'); - $field->setClass('form-control'); - $field->setContainerClass('form-group'); + $field = Form\Element\Text::create('title', 'Project Title', true); + $field->setClass('form-control')->setContainerClass('form-group'); $form->addField($field); - $field = new Form\Element\Text('title'); - $field->setRequired(true); - $field->setLabel('Project Title'); - $field->setClass('form-control'); - $field->setContainerClass('form-group'); - $form->addField($field); - - $field = new Form\Element\TextArea('key'); - $field->setRequired(false); - $field->setLabel('Private key to use to access repository (leave blank for local and/or anonymous remotes)'); - $field->setClass('form-control'); - $field->setContainerClass('form-group'); + $title = 'Private key to use to access repository (leave blank for local and/or anonymous remotes)'; + $field = Form\Element\TextArea::create('key', $title, false); + $field->setClass('form-control')->setContainerClass('form-group'); $field->setRows(6); $form->addField($field); - $field = new Form\Element\TextArea('build_config'); - $field->setRequired(false); $label = 'PHPCI build config for this project (if you cannot add a phpci.yml file in the project repository)'; - $field->setLabel($label); - $field->setClass('form-control'); - $field->setContainerClass('form-group'); + $field = Form\Element\TextArea::create('build_config', $label, false); + $field->setClass('form-control')->setContainerClass('form-group'); $field->setRows(6); $form->addField($field); - $field = new Form\Element\Checkbox('allow_public_status'); - $field->setRequired(false); - $field->setLabel('Enable public status page and image for this project?'); + $field = Form\Element\Text::create('branch', 'Default branch name', true); + $field->setValidator($this->getReferenceValidator($values)); + $field->setClass('form-control')->setContainerClass('form-group')->setValue('master'); + $form->addField($field); + + $label = 'Enable public status page and image for this project?'; + $field = Form\Element\Checkbox::create('allow_public_status', $label, false); $field->setContainerClass('form-group'); $field->setCheckedValue(1); $field->setValue(1); diff --git a/PHPCI/Helper/Github.php b/PHPCI/Helper/Github.php index 015d8d0e..6060f2fe 100644 --- a/PHPCI/Helper/Github.php +++ b/PHPCI/Helper/Github.php @@ -37,7 +37,7 @@ class Github $http = new HttpClient('https://api.github.com'); $res = $http->get($url, $params); - foreach ($res['body'] as $key => $item) { + foreach ($res['body'] as $item) { $results[] = $item; diff --git a/composer.lock b/composer.lock index 1fe95938..15a3adf6 100644 --- a/composer.lock +++ b/composer.lock @@ -1,23 +1,22 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], "hash": "6f9eb9a5f893e600062aa7810ed06257", "packages": [ { "name": "block8/b8framework", - "version": "1.1.5", + "version": "1.1.7", "source": { "type": "git", "url": "https://github.com/Block8/b8framework.git", - "reference": "2ae699b8b6a28752e9eebbd43c518fdc80a9d322" + "reference": "27c435a7cec78257851d860fa320e1973b164992" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Block8/b8framework/zipball/2ae699b8b6a28752e9eebbd43c518fdc80a9d322", - "reference": "2ae699b8b6a28752e9eebbd43c518fdc80a9d322", + "url": "https://api.github.com/repos/Block8/b8framework/zipball/27c435a7cec78257851d860fa320e1973b164992", + "reference": "27c435a7cec78257851d860fa320e1973b164992", "shasum": "" }, "require": { @@ -51,7 +50,7 @@ "mvc", "php" ], - "time": "2014-05-13 09:41:11" + "time": "2014-07-11 14:24:08" }, { "name": "ircmaxell/password-compat",