Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmackay committed Mar 26, 2017
2 parents 4d2f0bf + 5d03813 commit 7a27fcd
Show file tree
Hide file tree
Showing 58 changed files with 3,037 additions and 61 deletions.
40 changes: 5 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[download]: https://github.com/ushahidi/platform/releases
[download]: https://github.com/ushahidi/platform-release/releases
[install]: https://www.ushahidi.com/support/install-ushahidi
[docs]: https://www.ushahidi.com/support
[tech-docs]: ./docs/README.md
[getin]: https://www.ushahidi.com/support/get-involved
[issues]: https://github.com/ushahidi/platform/issues
[ush2]: https://github.com/ushahidi/Ushahidi_Web
[ushahidi]: http://ushahidi.com
[ushblog]: http://blog.ushahidi.com

Ushahidi 3
============

[![Build Status](https://travis-ci.org/ushahidi/platform.png)](https://travis-ci.org/ushahidi/platform)
[![Stories up next](https://badge.waffle.io/ushahidi/platform.png?label=2 - Up Next&title=Up Next)](https://waffle.io/ushahidi/platform)
[![Stories up next](https://badge.waffle.io/ushahidi/platform.png?label=Stage: Backlog&title=Backlog)](https://waffle.io/ushahidi/platform)
[![Coverage Status](https://coveralls.io/repos/github/ushahidi/platform/badge.svg)](https://coveralls.io/github/ushahidi/platform)

[Download][download]
Expand All @@ -24,17 +24,6 @@ Ushahidi 3

Ushahidi is an open source web application for information collection, visualization and interactive mapping. It helps you to collect info from: SMS, Twitter, RSS feeds, Email. It helps you to process that information, categorize it, geo-locate it and publish it on a map.

## What is Ushahidi v3?

Ushahidi v3 is the next iteration of this tool, rebuilt from the ground up -- not only the code but the way in which we think about users interacting with mobile and social data.

Crowdsourcing strategies have come a long way in the five years Ushahidi has been around and we've been fortunate enough to learn a lot from our global community.

### Should I use Ushahidi v3 for my new project?

That depends.. we've released v3 to the public and it should be usable in production.
However it's still missing a few features we had in v2. We recommend you give it a try and see if it meets your needs. If somethings missing let us know! It helps us prioritise future development

### I'm a developer, should I contribute to Ushahidi v3?

Yes! Development moves pretty quickly but the tech stack is getting more and more stable. If you're keen to help build something awesome, [Jump on board..][getin]
Expand All @@ -43,32 +32,13 @@ Yes! Development moves pretty quickly but the tech stack is getting more and mor

Please see our [Installation Guide][install] to get set up first!

### Logging in for the first time

The default install creates the user `admin` with a password of `admin`.
This user has admin privileges. Once logged in, this user can create more user
accounts or give admin permissions to others as well.

Extras
------

### Vagrantfile

We've included a Vagrantfile and puppet manifests to help build a quick development box.
Install [Vagrant](http://www.vagrantup.com/), then run `vagrant up` to get started!

### Travis-CI

Unit and functional tests are run automatically by [Travis-CI](https://travis-ci.org/ushahidi/platform).
See [.travis.yml](https://github.com/ushahidi/platform/blob/master/.travis.yml) for config details.

## Useful Links

- [Download][download]
- [Installation Guide][install]
- [Documentation][docs]
- [User Documentation][docs]
- [Technical Documentation][tech-docs]
- [Get Involved][getin]
- [Bug tracker][issues]
- [Ushahidi][ushahidi]
- [Ushahidi Blog][ushblog]
- [Ushahidi Platform v2][ush2]
18 changes: 18 additions & 0 deletions application/classes/Controller/Api/Webhooks.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 webhooks Controller
*
* @author Ushahidi Team <team@ushahidi.com>
* @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_Webhooks extends Ushahidi_Rest {

protected function _scope()
{
return 'webhooks';
}
}
137 changes: 137 additions & 0 deletions application/classes/Ushahidi/Console/Webhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php defined('SYSPATH') or die('No direct script access');

/**
* Ushahidi Webhook Console Command
*
* @author Ushahidi Team <team@ushahidi.com>
* @package Ushahidi\Console
* @copyright 2014 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/

use Ushahidi\Console\Command;

use Ushahidi\Core\Tool\Signer;
use Ushahidi\Core\Entity\PostRepository;
use Ushahidi\Core\Entity\WebhookJobRepository;
use Ushahidi\Core\Entity\WebhookRepository;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

class Ushahidi_Console_Webhook extends Command
{
private $db;
private $postRepository;
private $webhookRepository;
private $webhookJobRepository;
private $signer;
private $client;

public function setDatabase(Database $db)
{
$this->db = $db;
}

public function setWebhookRepo(WebhookRepository $repo)
{
$this->webhookRepository = $repo;
}

public function setPostRepo(PostRepository $repo)
{
$this->postRepository = $repo;
}

public function setSigner(Signer $signer)
{
$this->signer = $signer;
}

public function setWebhookJobRepo(WebhookJobRepository $repo)
{
$this->webhookJobRepository = $repo;
}

protected function configure()
{
$this
->setName('webhook')
->setDescription('Manage webhook requests')
->addArgument('action', InputArgument::OPTIONAL, 'list, send', 'list')
->addOption('limit', ['l'], InputOption::VALUE_OPTIONAL, 'number of webhook requests to be sent')
;
}

protected function executeList(InputInterface $input, OutputInterface $output)
{
return [
[
'Available actions' => 'send'
]
];
}

protected function executeSend(InputInterface $input, OutputInterface $output)
{

$this->client = new GuzzleHttp\Client();

$limit = $input->getOption('limit');

$count = 0;

// Get Queued webhook requests
$webhook_requests = $this->webhookJobRepository->getJobs($limit);

// Start transaction
$this->db->begin();

foreach ($webhook_requests as $webhook_request) {
$this->generateRequest($webhook_request);

$count++;
}

// Finally commit changes
$this->db->commit();

return [
[
'Message' => sprintf('%d webhook requests sent', $count)
]
];
}

private function generateRequest($webhook_request)
{
// Delete queued webhook request
//$this->webhookJobRepository->delete($webhook_request);

// Get post data
$post = $this->postRepository->get($webhook_request->post_id);
$json = json_encode($post->asArray());

// Get webhook data
$webhook = $this->webhookRepository->getByEventType($webhook_request->event_type);

$this->signer = new Signer($webhook->shared_secret);

$signature = $this->signer->sign($webhook->url, $json);

// This is an asynchronous request, we don't expect a result
// this can be extended to allow for handling of the returned promise
$promise = $this->client->requestAsync('POST', $webhook->url, [
'headers' => [
'X-Platform-Signature' => $signature,
'Accept' => 'application/json'
],
'json' => $post->asArray()
]);
}
}
41 changes: 41 additions & 0 deletions application/classes/Ushahidi/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public static function init()
return Kohana::$config->load('features.roles.enabled');
});

// Webhooks config settings
$di->set('webhooks.enabled', function() use ($di) {
return Kohana::$config->load('features.webhooks.enabled');
});

// Data import config settings
$di->set('data-import.enabled', function() use ($di) {
return Kohana::$config->load('features.data-import.enabled');
Expand Down Expand Up @@ -140,6 +145,14 @@ public static function init()
$di->setter['Ushahidi_Console_SavedSearch']['setContactRepo'] = $di->lazyGet('repository.contact');
$di->setter['Ushahidi_Console_SavedSearch']['setDataFactory'] = $di->lazyGet('factory.data');

// Webhook command
$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi_Console_Webhook');
$di->setter['Ushahidi_Console_Webhook']['setDatabase'] = $di->lazyGet('kohana.db');
$di->setter['Ushahidi_Console_Webhook']['setPostRepo'] = $di->lazyGet('repository.post');
$di->setter['Ushahidi_Console_Webhook']['setSigner'] = $di->lazyGet('tool.signer');
$di->setter['Ushahidi_Console_Webhook']['setWebhookRepo'] = $di->lazyGet('repository.webhook');
$di->setter['Ushahidi_Console_Webhook']['setWebhookJobRepo'] = $di->lazyGet('repository.webhook.job');

// OAuth servers
$di->set('oauth.server.auth', function() use ($di) {
$server = $di->newInstance('League\OAuth2\Server\Authorization');
Expand Down Expand Up @@ -246,6 +259,10 @@ public static function init()
'create' => $di->lazyNew('Ushahidi_Validator_Notification_Create'),
'update' => $di->lazyNew('Ushahidi_Validator_Notification_Update'),
];
$di->params['Ushahidi\Factory\ValidatorFactory']['map']['webhooks'] = [
'create' => $di->lazyNew('Ushahidi_Validator_Webhook_Create'),
'update' => $di->lazyNew('Ushahidi_Validator_Webhook_Update'),
];
$di->params['Ushahidi\Factory\ValidatorFactory']['map']['contacts'] = [
'create' => $di->lazyNew('Ushahidi_Validator_Contact_Create'),
'update' => $di->lazyNew('Ushahidi_Validator_Contact_Update'),
Expand Down Expand Up @@ -292,6 +309,7 @@ public static function init()
'savedsearches_posts' => $di->lazyNew('Ushahidi_Formatter_Post'),
'users' => $di->lazyNew('Ushahidi_Formatter_User'),
'notifications' => $di->lazyNew('Ushahidi_Formatter_Notification'),
'webhooks' => $di->lazyNew('Ushahidi_Formatter_Webhook'),
'contacts' => $di->lazyNew('Ushahidi_Formatter_Contact'),
'csv' => $di->lazyNew('Ushahidi_Formatter_CSV'),
'roles' => $di->lazyNew('Ushahidi_Formatter_Role'),
Expand All @@ -317,6 +335,7 @@ public static function init()
'savedsearch',
'set_post',
'notification',
'webhook',
'contact',
'role',
'permission',
Expand All @@ -334,6 +353,7 @@ public static function init()

// Helpers, tools, etc
$di->set('tool.hasher.password', $di->lazyNew('Ushahidi_Hasher_Password'));
$di->set('tool.signer', $di->lazyNew('Ushahidi\Core\Tool\Signer'));
$di->set('tool.authenticator.password', $di->lazyNew('Ushahidi_Authenticator_Password'));

$di->set('tool.validation', $di->lazyNew('Ushahidi_ValidationEngine'));
Expand Down Expand Up @@ -425,8 +445,10 @@ public static function init()
$di->set('repository.user', $di->lazyNew('Ushahidi_Repository_User'));
$di->set('repository.role', $di->lazyNew('Ushahidi_Repository_Role'));
$di->set('repository.notification', $di->lazyNew('Ushahidi_Repository_Notification'));
$di->set('repository.webhook', $di->lazyNew('Ushahidi_Repository_Webhook'));
$di->set('repository.csv', $di->lazyNew('Ushahidi_Repository_CSV'));
$di->set('repository.notification.queue', $di->lazyNew('Ushahidi_Repository_Notification_Queue'));
$di->set('repository.webhook.job', $di->lazyNew('Ushahidi_Repository_Webhook_Job'));
$di->set('repository.permission', $di->lazyNew('Ushahidi_Repository_Permission'));
$di->set('repository.oauth.client', $di->lazyNew('OAuth2_Storage_Client'));
$di->set('repository.oauth.session', $di->lazyNew('OAuth2_Storage_Session'));
Expand Down Expand Up @@ -469,6 +491,7 @@ public static function init()
$di->set('repository.post.text', $di->lazyNew('Ushahidi_Repository_Post_Text'));
$di->set('repository.post.description', $di->lazyNew('Ushahidi_Repository_Post_Description'));
$di->set('repository.post.varchar', $di->lazyNew('Ushahidi_Repository_Post_Varchar'));
$di->set('repository.post.markdown', $di->lazyNew('Ushahidi_Repository_Post_Markdown'));
$di->set('repository.post.title', $di->lazyNew('Ushahidi_Repository_Post_Title'));
$di->set('repository.post.media', $di->lazyNew('Ushahidi_Repository_Post_Media'));

Expand All @@ -486,6 +509,7 @@ public static function init()
'text' => $di->lazyGet('repository.post.text'),
'description' => $di->lazyGet('repository.post.description'),
'varchar' => $di->lazyGet('repository.post.varchar'),
'markdown' => $di->lazyGet('repository.post.markdown'),
'title' => $di->lazyGet('repository.post.title'),
'media' => $di->lazyGet('repository.post.media'),
],
Expand Down Expand Up @@ -548,6 +572,8 @@ public static function init()
'user_repo' => $di->lazyGet('repository.user'),
'collection_repo' => $di->lazyGet('repository.set'),
'savedsearch_repo' => $di->lazyGet('repository.savedsearch'),
];$di->params['Ushahidi_Validator_Webhook_Update'] = [
'user_repo' => $di->lazyGet('repository.user'),
];
$di->params['Ushahidi_Validator_SavedSearch_Create'] = [
'repo' => $di->lazyGet('repository.user'),
Expand Down Expand Up @@ -616,6 +642,7 @@ 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.markdown', $di->lazyNew('Ushahidi_Validator_Post_Markdown'));
$di->set('validator.post.video', $di->lazyNew('Ushahidi_Validator_Post_Video'));
$di->set('validator.post.title', $di->lazyNew('Ushahidi_Validator_Post_Title'));
$di->set('validator.post.media', $di->lazyNew('Ushahidi_Validator_Post_Media'));
Expand All @@ -636,6 +663,7 @@ public static function init()
'point' => $di->lazyGet('validator.post.point'),
'relation' => $di->lazyGet('validator.post.relation'),
'varchar' => $di->lazyGet('validator.post.varchar'),
'markdown' => $di->lazyGet('validator.post.markdown'),
'title' => $di->lazyGet('validator.post.title'),
'media' => $di->lazyGet('validator.post.media'),
'video' => $di->lazyGet('validator.post.video'),
Expand Down Expand Up @@ -670,6 +698,19 @@ public static function init()
$di->setter['Ushahidi_Listener_PostSetListener']['setRepo'] =
$di->lazyGet('repository.notification.queue');

// Event listener for the Post repo
$di->setter['Ushahidi_Repository_Post']['setEvent'] = 'PostCreateEvent';
$di->setter['Ushahidi_Repository_Post']['setListener'] =
$di->lazyNew('Ushahidi_Listener_PostListener');

// WebhookJob repo for Post listener
$di->setter['Ushahidi_Listener_PostListener']['setRepo'] =
$di->lazyGet('repository.webhook.job');

// Webhook repo for Post listener
$di->setter['Ushahidi_Listener_PostListener']['setWebhookRepo'] =
$di->lazyGet('repository.webhook');

// Defined memcached
$di->set('memcached', $di->lazy(function () use ($di) {
$config = $di->get('ratelimiter.config');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __invoke($entities)
'type' => 'FeatureCollection',
'features' => []
];
$unmapped = 0;

foreach ($entities as $entity)
{
Expand Down Expand Up @@ -67,7 +68,12 @@ public function __invoke($entities)
]
];
}
if(empty($geometries))
{
$unmapped++;
}
}
$output['unmapped'] = $unmapped;

if ($this->search->bbox)
{
Expand All @@ -82,7 +88,6 @@ public function __invoke($entities)

$output['bbox'] = $bbox;
}

return $output;
}

Expand Down
Loading

0 comments on commit 7a27fcd

Please sign in to comment.