Skip to content

Commit

Permalink
Merge pull request #2769 from ushahidi/release/cycle-3-sms-csv
Browse files Browse the repository at this point in the history
Release/cycle 3 sms+csv to Master
  • Loading branch information
rowasc authored Apr 16, 2018
2 parents 4994bca + 8c08abc commit 4769c99
Show file tree
Hide file tree
Showing 132 changed files with 6,380 additions and 919 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.*swp
*~
*.DS_Store
Expand Down
12 changes: 10 additions & 2 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@

### Steps to reproduce the behaviour/error


##### Where
#### Where does this issue happen?
- [ ] [Local setup with Vagrant ](https://www.ushahidi.com/support/install-ushahidi#installing-for-development)
- [ ] [Local setup from platform-release ](https://www.ushahidi.com/support/install-ushahidi#installing-the-latest-release)
- [ ] Ushahidi.io / SaaS solution
- [ ] Ushahidi's QA environment
- [ ] Other (explain):

#### It is ready for development when
- [ ] Has a description that includes purpose of this particular feature/improvement (how it will help the user and for which use cases)
- [ ] Can be delivered within a sprint (make sure issues are small pieces of work, not huge epics)
- [ ] Has all designs and UI assets available
- [ ] Has all (probable) dependencies identified
- [ ] Is estimated by the team
- [ ] Has acceptance criteria defined (do we want to do this before we send to dev? might help us identify dependencies/holes earlier?)


24 changes: 24 additions & 0 deletions application/classes/Controller/Api/CountryCodes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi API CountryCodes Controller
*
* @author Ushahidi Team <[email protected]>
* @package Ushahidi\Application\Controllers
* @copyright 2013 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/

class Controller_Api_CountryCodes extends Ushahidi_Rest {

protected $_action_map = array
(
Http_Request::GET => 'get',
Http_Request::OPTIONS => 'options'
);

protected function _scope()
{
return 'country_codes';
}
}
73 changes: 73 additions & 0 deletions application/classes/Controller/Api/Exports/External/Cli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi API Export Execute CLI Controller
*
* @author Ushahidi Team <[email protected]>
* @package Ushahidi\Application\Controllers
* @copyright 2018 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;

class Controller_Api_Exports_External_Cli extends Controller_Api_External {

protected function _scope()
{
return 'export_jobs';
}

public function action_get_index()
{
// Get Symfony console app
$app = service('app.console');
$command = $app->get('exporter');

$job_id = $this->request->param('id');

//Deal with query string -
// init and assume unset
$limit = 0;
$offset = 0;
$add_header = true;
// then do some validation (remove this if Kohana is better at this)
if (is_numeric($this->request->query('limit')))
{
$limit = $this->request->query('limit');
}
if (is_numeric($this->request->query('offset')))
{
$offset = $this->request->query('offset');
}
// this is a trick to convert 'false' to falsy (which would be true),
// 'true' to true, and an unset param to false
$include_header = json_decode($this->request->query('include_header')) == true ? 1 : 0;

// Construct console command input
$input = new ArrayInput(array(
'--limit' => $limit,
'--offset' => $offset,
'--job' => $job_id,
'--include_header' => $include_header,
), $command->getDefinition());

// Create Output Buffer
$output = new BufferedOutput();


// Run the command
$command->run($input, $output);

// Retrieve the results of rhe export
// which should be a json formatted string
// containing information aboutt he file generated and
// saved by the exporter
$file_details = json_decode($output->fetch());

$this->_response_payload = [
'results' => $file_details,
];
}
}
25 changes: 25 additions & 0 deletions application/classes/Controller/Api/Exports/External/Count.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi API External Export Jobs Post Count Controller
*
* @author Ushahidi Team <[email protected]>
* @package Ushahidi\Application\Controllers
* @copyright 2018 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/

class Controller_Api_Exports_External_Count extends Controller_Api_External {

protected function _scope()
{
return 'export_jobs';
}

public function action_get_index()
{
$this->_usecase = service('factory.usecase')
->get($this->_resource(), 'post-count')
->setIdentifiers($this->_identifiers());
}
}
18 changes: 18 additions & 0 deletions application/classes/Controller/Api/Exports/External/Jobs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi API External Webhook Posts Controller
*
* @author Ushahidi Team <[email protected]>
* @package Ushahidi\Application\Controllers
* @copyright 2013 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/

class Controller_Api_Exports_External_Jobs extends Controller_Api_External {

protected function _scope()
{
return 'export_jobs';
}
}
23 changes: 23 additions & 0 deletions application/classes/Controller/Api/Exports/Jobs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi API Export Jobs Controller
*
* @author Ushahidi Team <[email protected]>
* @package Ushahidi\Application\Controllers
* @copyright 2013 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/

class Controller_Api_Exports_Jobs extends Ushahidi_Rest {

protected function _scope()
{
return 'posts';
}

protected function _resource()
{
return 'export_jobs';
}
}
120 changes: 120 additions & 0 deletions application/classes/Controller/Api/External.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi API Export Execute CLI Controller
*
* @author Ushahidi Team <[email protected]>
* @package Ushahidi\Application\Controllers
* @copyright 2018 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;

use Ushahidi\Core\Tool\Verifier;

class Controller_Api_External extends Ushahidi_Rest {

protected function _scope()
{
return 'external';
}

public function before()
{
parent::before();
$data = $this->_request_payload;
$api_key = isset($data['api_key']) ? $data['api_key'] : null;

if ($this->request->method() === 'GET') {
$data = [];
$api_key = $this->request->query('api_key');
}

$signature = $this->request->headers('X-Ushahidi-Signature');

$shared_secret = getenv('PLATFORM_SHARED_SECRET');
$fullURL = URL::site(Request::detect_uri(), TRUE) . URL::query();

$verifier = new Verifier($signature, $api_key, $shared_secret, $fullURL, $data);

if (!$verifier->verified()) {
throw HTTP_Exception::factory(403, 'Forbidden');
}
}

protected function _is_auth_required()
{
return false;
}


public function setExternalAuth() {
$this->_usecase->setAuthorizer(service('authorizer.external_auth'));
}
/**
* Create An Entity
*
* POST /api/foo
*
* @return void
*/
public function action_post_index_collection()
{
parent::action_post_index_collection();
$this->setExternalAuth();
}

/**
* Retrieve All Entities
*
* GET /api/foo
*
* @return void
*/
public function action_get_index_collection()
{
parent::action_get_index_collection();
$this->setExternalAuth();
}

/**
* Retrieve An Entity
*
* GET /api/foo/:id
*
* @return void
*/
public function action_get_index()
{
parent::action_get_index();
$this->setExternalAuth();
}

/**
* Update An Entity
*
* PUT /api/foo/:id
*
* @return void
*/
public function action_put_index()
{
parent::action_put_index();
$this->setExternalAuth();
}

/**
* Delete An Entity
*
* DELETE /api/foo/:id
*
* @return void
*/
public function action_delete_index()
{
parent::action_delete_index();
$this->setExternalAuth();
}
}
43 changes: 43 additions & 0 deletions application/classes/Controller/Api/Forms/Contacts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi API Forms Controller
*
* @author Ushahidi Team <[email protected]>
* @package Ushahidi\Application\Controllers
* @copyright 2013 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/

class Controller_API_Forms_Contacts extends Ushahidi_Rest {

protected function _scope()
{
return 'forms';
}

protected function _resource()
{
return 'form_contacts';
}

// Get Lock
public function action_post_index_collection()
{

$this->_usecase = service('factory.usecase')
->get($this->_resource(), 'create');
$this->_usecase->setIdentifiers($this->request->param());
$this->_usecase->setPayload($this->_request_payload);
}

// Get Lock
public function action_get_index_collection()
{
$this->_usecase = service('factory.usecase')
->get($this->_resource(), 'search');
$this->_usecase->setIdentifiers($this->request->param());
$this->_usecase
->setFormatter(service("formatter.entity.form.contactcollection"));
}
}
37 changes: 37 additions & 0 deletions application/classes/Controller/Api/Forms/Stats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Ushahidi API Form Stats Controller
*
* @author Ushahidi Team <[email protected]>
* @package Ushahidi\Application\Controllers
* @copyright 2018 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/
class Controller_Api_Forms_Stats extends Ushahidi_Rest {

protected $_action_map = array
(
Http_Request::GET => 'get',
Http_Request::OPTIONS => 'options'
);
protected function _scope()
{
return 'forms';
}

protected function _resource()
{
return 'form_stats';
}

// Get Lock
public function action_get_index_collection()
{
$this->_usecase = service('factory.usecase')
->get($this->_resource(), 'search');
$this->_usecase->setIdentifiers($this->request->param());
$this->_usecase
->setFormatter(service("formatter.entity.form.stats"));
}
}
Loading

0 comments on commit 4769c99

Please sign in to comment.