Skip to content

Commit 88d5518

Browse files
committed
Merge remote-tracking branch 'origin/master' into lumen
Conflicts: application/classes/Controller/Api/Index.php application/classes/Controller/Api/Migration.php application/classes/Controller/Api/Users.php application/classes/Ushahidi/Core.php application/classes/Ushahidi/DataProvider.php application/classes/Ushahidi/Repository/Post/Export.php application/config/init.php application/routes/default.php composer.json composer.lock modules/data-provider/classes/DataProvider/Core.php plugins/nexmo/classes/Controller/Sms/Nexmo.php plugins/nexmo/classes/DataProvider/Nexmo.php plugins/nexmo/lib/nexmo/NexmoAccount.php plugins/nexmo/lib/nexmo/NexmoMessage.php plugins/nexmo/lib/nexmo/NexmoReceipt.php plugins/twilio/classes/Controller/Sms/Twilio.php src/App/Formatter/Post/CSV.php src/App/Init.php src/App/Repository/Config/features.php src/App/Repository/OhanzeeRepository.php src/App/Repository/Post/MediaRepository.php src/App/Repository/PostRepository.php src/App/Validator/Form/Update.php src/Console/Command.php src/Console/Command/ConfigGet.php src/Console/Command/ConfigSet.php src/Console/Command/PostExporter.php src/Console/Command/User.php src/Core/Traits/UserContext.php src/Core/Usecase/Message/ReceiveMessage.php src/Init.php tests/datasets/ushahidi/Base.yml tests/integration/acl.feature tests/integration/bootstrap/FeatureContext.php tests/integration/export.feature tests/integration/posts/posts.feature
2 parents ca9af47 + 06e055d commit 88d5518

File tree

116 files changed

+6228
-722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+6228
-722
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.idea
12
.*swp
23
*~
34
*.DS_Store

ISSUE_TEMPLATE.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
### Steps to reproduce the behaviour/error
66

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

14+
#### It is ready for development when
15+
- [ ] Has a description that includes purpose of this particular feature/improvement (how it will help the user and for which use cases)
16+
- [ ] Can be delivered within a sprint (make sure issues are small pieces of work, not huge epics)
17+
- [ ] Has all designs and UI assets available
18+
- [ ] Has all (probable) dependencies identified
19+
- [ ] Is estimated by the team
20+
- [ ] Has acceptance criteria defined (do we want to do this before we send to dev? might help us identify dependencies/holes earlier?)
21+
22+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php defined('SYSPATH') OR die('No direct access allowed.');
2+
3+
/**
4+
* Ushahidi API CountryCodes Controller
5+
*
6+
* @author Ushahidi Team <[email protected]>
7+
* @package Ushahidi\Application\Controllers
8+
* @copyright 2013 Ushahidi
9+
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
10+
*/
11+
12+
class Controller_Api_CountryCodes extends Ushahidi_Rest {
13+
14+
protected $_action_map = array
15+
(
16+
Http_Request::GET => 'get',
17+
Http_Request::OPTIONS => 'options'
18+
);
19+
20+
protected function _scope()
21+
{
22+
return 'country_codes';
23+
}
24+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php defined('SYSPATH') OR die('No direct access allowed.');
2+
3+
/**
4+
* Ushahidi API Export Execute CLI Controller
5+
*
6+
* @author Ushahidi Team <[email protected]>
7+
* @package Ushahidi\Application\Controllers
8+
* @copyright 2018 Ushahidi
9+
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
10+
*/
11+
12+
use Symfony\Component\Console\Input\ArrayInput;
13+
use Symfony\Component\Console\Output\BufferedOutput;
14+
15+
class Controller_Api_Exports_External_Cli extends Controller_Api_External {
16+
17+
protected function _scope()
18+
{
19+
return 'export_jobs';
20+
}
21+
22+
public function action_get_index()
23+
{
24+
// Get Symfony console app
25+
$app = service('app.console');
26+
$command = $app->get('exporter');
27+
28+
$job_id = $this->request->param('id');
29+
30+
//Deal with query string -
31+
// init and assume unset
32+
$limit = 0;
33+
$offset = 0;
34+
$add_header = true;
35+
// then do some validation (remove this if Kohana is better at this)
36+
if (is_numeric($this->request->query('limit')))
37+
{
38+
$limit = $this->request->query('limit');
39+
}
40+
if (is_numeric($this->request->query('offset')))
41+
{
42+
$offset = $this->request->query('offset');
43+
}
44+
// this is a trick to convert 'false' to falsy (which would be true),
45+
// 'true' to true, and an unset param to false
46+
$include_header = json_decode($this->request->query('include_header')) == true ? 1 : 0;
47+
48+
// Construct console command input
49+
$input = new ArrayInput(array(
50+
'--limit' => $limit,
51+
'--offset' => $offset,
52+
'--job' => $job_id,
53+
'--include_header' => $include_header,
54+
), $command->getDefinition());
55+
56+
// Create Output Buffer
57+
$output = new BufferedOutput();
58+
59+
60+
// Run the command
61+
$command->run($input, $output);
62+
63+
// Retrieve the results of rhe export
64+
// which should be a json formatted string
65+
// containing information aboutt he file generated and
66+
// saved by the exporter
67+
$file_details = json_decode($output->fetch());
68+
69+
$this->_response_payload = [
70+
'results' => $file_details,
71+
];
72+
}
73+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php defined('SYSPATH') OR die('No direct access allowed.');
2+
3+
/**
4+
* Ushahidi API External Export Jobs Post Count Controller
5+
*
6+
* @author Ushahidi Team <[email protected]>
7+
* @package Ushahidi\Application\Controllers
8+
* @copyright 2018 Ushahidi
9+
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
10+
*/
11+
12+
class Controller_Api_Exports_External_Count extends Controller_Api_External {
13+
14+
protected function _scope()
15+
{
16+
return 'export_jobs';
17+
}
18+
19+
public function action_get_index()
20+
{
21+
$this->_usecase = service('factory.usecase')
22+
->get($this->_resource(), 'post-count')
23+
->setIdentifiers($this->_identifiers());
24+
}
25+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php defined('SYSPATH') OR die('No direct access allowed.');
2+
3+
/**
4+
* Ushahidi API External Webhook Posts Controller
5+
*
6+
* @author Ushahidi Team <[email protected]>
7+
* @package Ushahidi\Application\Controllers
8+
* @copyright 2013 Ushahidi
9+
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
10+
*/
11+
12+
class Controller_Api_Exports_External_Jobs extends Controller_Api_External {
13+
14+
protected function _scope()
15+
{
16+
return 'export_jobs';
17+
}
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php defined('SYSPATH') OR die('No direct access allowed.');
2+
3+
/**
4+
* Ushahidi API Export Jobs Controller
5+
*
6+
* @author Ushahidi Team <[email protected]>
7+
* @package Ushahidi\Application\Controllers
8+
* @copyright 2013 Ushahidi
9+
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
10+
*/
11+
12+
class Controller_Api_Exports_Jobs extends Ushahidi_Rest {
13+
14+
protected function _scope()
15+
{
16+
return 'posts';
17+
}
18+
19+
protected function _resource()
20+
{
21+
return 'export_jobs';
22+
}
23+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php defined('SYSPATH') OR die('No direct access allowed.');
2+
3+
/**
4+
* Ushahidi API Export Execute CLI Controller
5+
*
6+
* @author Ushahidi Team <[email protected]>
7+
* @package Ushahidi\Application\Controllers
8+
* @copyright 2018 Ushahidi
9+
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
10+
*/
11+
12+
use Symfony\Component\Console\Input\ArrayInput;
13+
use Symfony\Component\Console\Output\BufferedOutput;
14+
15+
use Ushahidi\Core\Tool\Verifier;
16+
17+
class Controller_Api_External extends Ushahidi_Rest {
18+
19+
protected function _scope()
20+
{
21+
return 'external';
22+
}
23+
24+
public function before()
25+
{
26+
parent::before();
27+
$data = $this->_request_payload;
28+
$api_key = isset($data['api_key']) ? $data['api_key'] : null;
29+
30+
if ($this->request->method() === 'GET') {
31+
$data = [];
32+
$api_key = $this->request->query('api_key');
33+
}
34+
35+
$signature = $this->request->headers('X-Ushahidi-Signature');
36+
37+
$shared_secret = getenv('PLATFORM_SHARED_SECRET');
38+
$fullURL = URL::site(Request::detect_uri(), TRUE) . URL::query();
39+
40+
$verifier = new Verifier($signature, $api_key, $shared_secret, $fullURL, $data);
41+
42+
if (!$verifier->verified()) {
43+
throw HTTP_Exception::factory(403, 'Forbidden');
44+
}
45+
}
46+
47+
protected function _is_auth_required()
48+
{
49+
return false;
50+
}
51+
52+
53+
public function setExternalAuth() {
54+
$this->_usecase->setAuthorizer(service('authorizer.external_auth'));
55+
}
56+
/**
57+
* Create An Entity
58+
*
59+
* POST /api/foo
60+
*
61+
* @return void
62+
*/
63+
public function action_post_index_collection()
64+
{
65+
parent::action_post_index_collection();
66+
$this->setExternalAuth();
67+
}
68+
69+
/**
70+
* Retrieve All Entities
71+
*
72+
* GET /api/foo
73+
*
74+
* @return void
75+
*/
76+
public function action_get_index_collection()
77+
{
78+
parent::action_get_index_collection();
79+
$this->setExternalAuth();
80+
}
81+
82+
/**
83+
* Retrieve An Entity
84+
*
85+
* GET /api/foo/:id
86+
*
87+
* @return void
88+
*/
89+
public function action_get_index()
90+
{
91+
parent::action_get_index();
92+
$this->setExternalAuth();
93+
}
94+
95+
/**
96+
* Update An Entity
97+
*
98+
* PUT /api/foo/:id
99+
*
100+
* @return void
101+
*/
102+
public function action_put_index()
103+
{
104+
parent::action_put_index();
105+
$this->setExternalAuth();
106+
}
107+
108+
/**
109+
* Delete An Entity
110+
*
111+
* DELETE /api/foo/:id
112+
*
113+
* @return void
114+
*/
115+
public function action_delete_index()
116+
{
117+
parent::action_delete_index();
118+
$this->setExternalAuth();
119+
}
120+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php defined('SYSPATH') OR die('No direct access allowed.');
2+
3+
/**
4+
* Ushahidi API Forms Controller
5+
*
6+
* @author Ushahidi Team <[email protected]>
7+
* @package Ushahidi\Application\Controllers
8+
* @copyright 2013 Ushahidi
9+
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
10+
*/
11+
12+
class Controller_API_Forms_Contacts extends Ushahidi_Rest {
13+
14+
protected function _scope()
15+
{
16+
return 'forms';
17+
}
18+
19+
protected function _resource()
20+
{
21+
return 'form_contacts';
22+
}
23+
24+
// Get Lock
25+
public function action_post_index_collection()
26+
{
27+
28+
$this->_usecase = service('factory.usecase')
29+
->get($this->_resource(), 'create');
30+
$this->_usecase->setIdentifiers($this->request->param());
31+
$this->_usecase->setPayload($this->_request_payload);
32+
}
33+
34+
// Get Lock
35+
public function action_get_index_collection()
36+
{
37+
$this->_usecase = service('factory.usecase')
38+
->get($this->_resource(), 'search');
39+
$this->_usecase->setIdentifiers($this->request->param());
40+
$this->_usecase
41+
->setFormatter(service("formatter.entity.form.contactcollection"));
42+
}
43+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
<?php defined('SYSPATH') OR die('No direct access allowed.');
3+
/**
4+
* Ushahidi API Form Stats Controller
5+
*
6+
* @author Ushahidi Team <[email protected]>
7+
* @package Ushahidi\Application\Controllers
8+
* @copyright 2018 Ushahidi
9+
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
10+
*/
11+
class Controller_Api_Forms_Stats extends Ushahidi_Rest {
12+
13+
protected $_action_map = array
14+
(
15+
Http_Request::GET => 'get',
16+
Http_Request::OPTIONS => 'options'
17+
);
18+
protected function _scope()
19+
{
20+
return 'forms';
21+
}
22+
23+
protected function _resource()
24+
{
25+
return 'form_stats';
26+
}
27+
28+
// Get Lock
29+
public function action_get_index_collection()
30+
{
31+
$this->_usecase = service('factory.usecase')
32+
->get($this->_resource(), 'search');
33+
$this->_usecase->setIdentifiers($this->request->param());
34+
$this->_usecase
35+
->setFormatter(service("formatter.entity.form.stats"));
36+
}
37+
}

0 commit comments

Comments
 (0)