Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmackay committed Jun 14, 2016
2 parents 70d6b97 + 6e27bfe commit d7c16bf
Show file tree
Hide file tree
Showing 68 changed files with 1,317 additions and 121 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ puppet/modules
Puppetfile.lock
.tmp/*
.env
phpunit.xml
phpspec.yml

# Kohana deployment specifics
application/logs/*
Expand All @@ -35,3 +37,8 @@ modules/image
modules/unittest
modules/minion
modules/orm

# Docker Deployment Specifics
*.aes
deployment.env
vault.txt
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ install:
- composer install --no-interaction
before_script:
- "./bin/tests install"
- mysql -e 'SET @@GLOBAL.wait_timeout=1800'
script:
- "./bin/tests run --no-install $coverage"
- composer lint
Expand Down
2 changes: 2 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ssh_connection]
ssh_args=
2 changes: 2 additions & 0 deletions ansible/hosts/group_vars/rackspace_staging/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
platform_api_version: "develop"
6 changes: 6 additions & 0 deletions ansible/hosts/group_vars/rackspace_staging/secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$ANSIBLE_VAULT;1.1;AES256
61346232653030613664363330616361363164306434323730613839306139356437383534343532
3036343331636266656663663036303966336536303430390a356438333330373862646161656665
39653537303438396538343338346634303434376139363763333435616330626630623137303131
3133376663353437660a396432633965323736373131633137306666336130366661393430393737
6639
25 changes: 25 additions & 0 deletions ansible/hosts/rackspace_staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$ANSIBLE_VAULT;1.1;AES256
62663066333665383661343433303033623239613936306361336134666566613136326535363532
6637393865376636663233666432386338343837363035620a633332343536363531316339613464
38366132313537343033656662373030316135613934316236616231633638666266626335613866
3365633335616361650a646637656139623531653939383537323666346238393136613737393133
36656661316337393739346236313865313637613135316165616137666235653865636539393163
62353031353638616533303664663238313135346164613537393733616465313435393866616535
33363335666438613461326364656265333730363163393937626562336266383064393236636231
35303534333332306539386438373236623535396639373361366661313761393533303735313933
32393561393637633664383632373930353962646661663439323839646536613433313933373064
62313462316561646362323032336164303434613637303232613864386163633632313666356266
31613034343838623832363662623331326461366538613231633738623134366335633765313861
34363931633965626265656365343561623361623834353232366132316530313035303161353139
65653864333165643661646261376536303534666266303535363135623932643364386638316665
66396531316337303066353233386238396461386534643738326131306536623330356262326236
30376233316463303265643532633663653630376565373066343065656332643934326232623766
36343866373464653934353661313839366366366438303364666631626234653362626635623165
35616163663562643034313564376435633335303165333962613832656434306533393133623964
65633064656661326637643265303465656561323739383730383864353738366331363832373432
61383831343261303331333163363762306239376632386532376331336239353237613639663536
61353633333438623438393064356431613934366532346634663531333865393938383062303566
64303730646138643164386566306337313030343031396562346331303835373034616131373663
64616564616133323463336266363337636532303036663763303861356137343466303339613733
32656363643033396133323963336663633437653034623664306535366266313730656536643264
62383235656266653037
6 changes: 6 additions & 0 deletions ansible/playbooks/platform-api-code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: deploy platform-api code
hosts: platform

roles:
- platform-api-code
3 changes: 3 additions & 0 deletions ansible/roles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- src: git+https://github.com/ushahidi/ansible-platform-api-code.git
version: master
name: platform-api-code
77 changes: 77 additions & 0 deletions application/classes/Controller/Api/Migration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi API Migration 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_Migration extends Ushahidi_Rest {

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

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

public function action_get_index_collection($command = 'status')
{

$user = service('session.user');

if ('admin' != $user->role) {
throw new HTTP_Exception_403('Must be an admin to access this service');
}

$commands = [
'status' => 'getStatus',
'rollback' => 'getRollback',
];

// add return status if invalid command is selected

if (!array_key_exists($command, $commands)) {
$command = 'status';
}

$db = service('db.config');
$phinx_config = ['configuration' => realpath(APPPATH . '../application/phinx.php'),
'parser' => 'php',
];

$phinx_app = new Phinx\Console\PhinxApplication();

$phinx_wrapper = new Phinx\Wrapper\TextWrapper($phinx_app, $phinx_config);

$migration_results = call_user_func([$phinx_wrapper, $commands[$command]], 'ushahidi', null);
$error = $phinx_wrapper->getExitCode() > 0;

$this->_response_payload = [
'results' => explode("\n", $migration_results, -1),
];
}

public function action_post_migrate_collection()
{
$this->action_get_index_collection('migrate');
}

public function action_post_rollback_collection()
{
$this->action_get_index_collection('rollback');
}

public function action_get_status_collection()
{
$this->action_get_index_collection('status');
}
}
53 changes: 53 additions & 0 deletions application/classes/Controller/Api/Posts/Export.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi API Posts Exports 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_Posts_Export extends Ushahidi_Rest
{
protected $_action_map = array
(
Http_Request::GET => 'get',
Http_Request::OPTIONS => 'options',
);

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

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

public function action_get_index_collection()
{
// Get usecase with default formatter
$this->_usecase = service('factory.usecase')
->get($this->_resource(), 'export')
->setFilters($this->_filters());

// ...or use a different one if requested
$format = strtolower($this->request->query('format'));

if ($format) {
$this->_usecase->setFormatter(service("formatter.entity.post.$format"));
}
}

public function action_get_index()
{
throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(
':method' => $this->request->method(),
':allowed_methods' => implode(', ', array_keys($this->_action_map)),
))
->allowed(array_keys($this->_action_map));
}
}
50 changes: 50 additions & 0 deletions application/classes/Controller/Migrate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi API Migration 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_Migrate extends Ushahidi_Rest {

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

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

protected function _is_auth_required()
{
return FALSE;
}

public function action_get_index_collection()
{

$db = service('db.config');
$phinx_config = ['configuration' => realpath(APPPATH . '../application/phinx.php'),
'parser' => 'php',
];

$phinx_app = new Phinx\Console\PhinxApplication();

$phinx_wrapper = new Phinx\Wrapper\TextWrapper($phinx_app, $phinx_config);

$migration_results = call_user_func([$phinx_wrapper, 'getMigrate'], 'ushahidi', null);
$error = $phinx_wrapper->getExitCode() > 0;

$this->_response_payload = [
'results' => explode("\n", $migration_results, -1),
];
}

}
5 changes: 5 additions & 0 deletions application/classes/Ushahidi/Console/Dataprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ protected function executeOutgoing(InputInterface $input, OutputInterface $outpu
$providers = $this->get_providers($input, $output);
$limit = $input->getOption('limit');

// Hack: always include email no matter what!
if (!isset($providers['email'])) {
$providers['email'] = $this->repo->get('email');
}

$totals = [];
foreach ($providers as $id => $provider)
{
Expand Down
18 changes: 15 additions & 3 deletions application/classes/Ushahidi/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ public static function init()
'csv' => $di->lazyNew('Ushahidi_Formatter_CSV'),
'roles' => $di->lazyNew('Ushahidi_Formatter_Role'),
'permissions' => $di->lazyNew('Ushahidi_Formatter_Permission'),
// Formatter for post exports. Defaults to CSV export
'posts_export' => $di->lazyNew('Ushahidi_Formatter_Post_CSV'),
];

// Formatter parameters
Expand Down Expand Up @@ -378,6 +380,7 @@ public static function init()
$di->set('formatter.entity.post.geojson', $di->lazyNew('Ushahidi_Formatter_Post_GeoJSON'));
$di->set('formatter.entity.post.geojsoncollection', $di->lazyNew('Ushahidi_Formatter_Post_GeoJSONCollection'));
$di->set('formatter.entity.post.stats', $di->lazyNew('Ushahidi_Formatter_Post_Stats'));
$di->set('formatter.entity.post.csv', $di->lazyNew('Ushahidi_Formatter_Post_CSV'));

$di->set('formatter.output.json', $di->lazyNew('Ushahidi_Formatter_JSON'));
$di->set('formatter.output.jsonp', $di->lazyNew('Ushahidi_Formatter_JSONP'));
Expand Down Expand Up @@ -456,6 +459,7 @@ public static function init()
$di->set('repository.post.relation', $di->lazyNew('Ushahidi_Repository_Post_Relation'));
$di->set('repository.post.text', $di->lazyNew('Ushahidi_Repository_Post_Text'));
$di->set('repository.post.varchar', $di->lazyNew('Ushahidi_Repository_Post_Varchar'));
$di->set('repository.post.media', $di->lazyNew('Ushahidi_Repository_Post_Media'));

// The post value repo factory
$di->set('repository.post_value_factory', $di->lazyNew('Ushahidi_Repository_Post_ValueFactory'));
Expand All @@ -469,7 +473,8 @@ public static function init()
'point' => $di->lazyGet('repository.post.point'),
'relation' => $di->lazyGet('repository.post.relation'),
'text' => $di->lazyGet('repository.post.text'),
'varchar' => $di->lazyGet('repository.post.varchar')
'varchar' => $di->lazyGet('repository.post.varchar'),
'media' => $di->lazyGet('repository.post.media'),
],
];

Expand All @@ -480,6 +485,7 @@ public static function init()
// Validators
$di->set('validator.user.login', $di->lazyNew('Ushahidi_Validator_User_Login'));
$di->set('validator.contact.create', $di->lazyNew('Ushahidi_Validator_Contact_Create'));
$di->set('validator.contact.receive', $di->lazyNew('Ushahidi_Validator_Contact_Receive'));

$di->params['Ushahidi_Validator_Contact_Update'] = [
'repo' => $di->lazyGet('repository.user'),
Expand Down Expand Up @@ -592,10 +598,15 @@ public static function init()
$di->set('validator.post.point', $di->lazyNew('Ushahidi_Validator_Post_Point'));
$di->set('validator.post.relation', $di->lazyNew('Ushahidi_Validator_Post_Relation'));
$di->set('validator.post.varchar', $di->lazyNew('Ushahidi_Validator_Post_Varchar'));
$di->set('validator.post.media', $di->lazyNew('Ushahidi_Validator_Post_Media'));
$di->params['Ushahidi_Validator_Post_Media'] = [
'media_repo' => $di->lazyGet('repository.media')
];


$di->set('validator.post.value_factory', $di->lazyNew('Ushahidi_Validator_Post_ValueFactory'));
$di->params['Ushahidi_Validator_Post_ValueFactory'] = [
// a map of attribute types to repositories
// a map of attribute types to validators
'map' => [
'datetime' => $di->lazyGet('validator.post.datetime'),
'decimal' => $di->lazyGet('validator.post.decimal'),
Expand All @@ -604,7 +615,8 @@ public static function init()
'link' => $di->lazyGet('validator.post.link'),
'point' => $di->lazyGet('validator.post.point'),
'relation' => $di->lazyGet('validator.post.relation'),
'varchar' => $di->lazyGet('validator.post.varchar')
'varchar' => $di->lazyGet('validator.post.varchar'),
'media' => $di->lazyGet('validator.post.media'),
],
];

Expand Down
4 changes: 2 additions & 2 deletions application/classes/Ushahidi/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public function send($to, $message, $title = "")
* @param string data_provider_message_id Message ID
* @return void
*/
public function receive($type, $from, $message, $to = NULL, $title = NULL, $data_provider_message_id = NULL)
public function receive($type, $from, $message, $to = NULL, $title = NULL, $data_provider_message_id = NULL, Array $additional_data = NULL)
{
$data_provider = $this->provider_name();
$contact_type = $this->contact_type;

$usecase = service('factory.usecase')->get('messages', 'receive');
try
{
$usecase->setPayload(compact(['type', 'from', 'message', 'to', 'title', 'data_provider_message_id', 'data_provider', 'contact_type']))
$usecase->setPayload(compact(['type', 'from', 'message', 'to', 'title', 'data_provider_message_id', 'data_provider', 'contact_type', 'additional_data']))
->interact();
}
catch (Ushahidi\Core\Exception\NotFoundException $e)
Expand Down
6 changes: 6 additions & 0 deletions application/classes/Ushahidi/Formatter/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected function get_field_name($field)
$remap = [
'form_id' => 'form',
'message_id' => 'message',
'contact_id' => 'contact'
];

if (isset($remap[$field])) {
Expand All @@ -40,6 +41,11 @@ protected function format_message_id($form_id)
return $this->get_relation('messages', $form_id);
}

protected function format_contact_id($contact_id)
{
return $this->get_relation('contact', $contact_id);
}

protected function format_tags($tags)
{
$output = [];
Expand Down
Loading

0 comments on commit d7c16bf

Please sign in to comment.