-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reapply Terms of Service API (#1932)
This reverts commit b9966cf.
- Loading branch information
Showing
22 changed files
with
526 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Tos Controller | ||
* | ||
* @author Ushahidi Team <team@ushahidi.com> | ||
* @package Ushahidi\Application\Controllers | ||
* @copyright 2017 Ushahidi | ||
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) | ||
*/ | ||
|
||
class Controller_Api_Tos extends Ushahidi_Rest { | ||
|
||
protected function _scope() | ||
{ | ||
return 'tos'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php defined('SYSPATH') OR die('No direct access allowed.'); | ||
|
||
/** | ||
* Ushahidi API Formatter for CSV | ||
* | ||
* @author Ushahidi Team <team@ushahidi.com> | ||
* @package Ushahidi\Application | ||
* @copyright 2014 Ushahidi | ||
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) | ||
*/ | ||
|
||
use Ushahidi\Core\Traits\FormatterAuthorizerMetadata; | ||
|
||
class Ushahidi_Formatter_Tos extends Ushahidi_Formatter_API | ||
{ | ||
use FormatterAuthorizerMetadata; | ||
|
||
protected function format_agreement_date($value) | ||
{ | ||
return $value ? $value->format(DateTime::W3C) : NULL; | ||
} | ||
|
||
protected function format_tos_version_date($value) | ||
{ | ||
return $value ? $value->format(DateTime::W3C) : NULL; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php defined('SYSPATH') OR die('No direct access allowed.'); | ||
|
||
/** | ||
* Ushahidi Tos Repository | ||
* | ||
* @author Ushahidi Team <team@ushahidi.com> | ||
* @package Ushahidi\Application | ||
* @copyright 2017 Ushahidi | ||
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) | ||
*/ | ||
|
||
use Ushahidi\Core\Entity; | ||
use Ushahidi\Core\Entity\Tos; | ||
use Ushahidi\Core\Entity\TosRepository; | ||
use Ushahidi\Core\SearchData; | ||
use Ushahidi\Core\Traits\UserContext; | ||
|
||
|
||
|
||
class Ushahidi_Repository_Tos extends Ushahidi_Repository implements | ||
TosRepository | ||
{ | ||
use UserContext; | ||
|
||
|
||
// Ushahidi_Repository | ||
protected function getTable() | ||
{ | ||
return 'tos'; | ||
} | ||
|
||
|
||
// CreateRepository | ||
public function create(Entity $entity) | ||
{ | ||
$data = $entity->asArray(); | ||
|
||
// Save the agreement date to the current time and the user ID | ||
$data['agreement_date'] = time(); | ||
$data['user_id'] = $this->getUserId(); | ||
// Convert tos_version_date to timestamp | ||
$data['tos_version_date'] = $data['tos_version_date']->format("U"); | ||
|
||
return $this->executeInsert($this->removeNullValues($data)); | ||
} | ||
|
||
public function getEntity(Array $data = null) | ||
{ | ||
return new Tos($data); | ||
} | ||
|
||
// SearchRepository | ||
public function getSearchFields() | ||
{ | ||
return []; | ||
} | ||
|
||
protected function setSearchConditions(SearchData $search) | ||
{ | ||
|
||
$query = $this->search_query; | ||
|
||
$query->where('user_id', '=', $this->getUserId()); | ||
} | ||
|
||
public function getSearchResults() | ||
{ | ||
$query = $this->getSearchQuery(); | ||
$results = $query->distinct(TRUE)->execute($this->db); | ||
return $this->getCollection($results->as_array()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php defined('SYSPATH') OR die('No direct access allowed.'); | ||
|
||
/** | ||
* Ushahidi CSV Validator | ||
* | ||
* @author Ushahidi Team <team@ushahidi.com> | ||
* @package Ushahidi\Application | ||
* @copyright 2014 Ushahidi | ||
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) | ||
*/ | ||
|
||
use Ushahidi\Core\Tool\Validator; | ||
use Ushahidi\Core\Entity\UserRepository; | ||
|
||
|
||
class Ushahidi_Validator_Tos_Create extends Validator | ||
{ | ||
protected $user_repo; | ||
protected $default_error_source = 'tos'; | ||
|
||
public function __construct(UserRepository $user_repo) | ||
{ | ||
$this->user_repo = $user_repo; | ||
} | ||
|
||
protected function getRules() | ||
{ | ||
return [ | ||
'id' => [ | ||
['numeric'], | ||
], | ||
'user_id' => [ | ||
['numeric'], | ||
[[$this->user_repo, 'exists'], [':value']], | ||
], | ||
'agreement_date' => [ | ||
[[$this, 'validDate'], [':value']], | ||
], | ||
'tos_version_date' => [ | ||
[[$this, 'validDate'], [':value']], | ||
], | ||
|
||
]; | ||
} | ||
|
||
public function validDate($str) | ||
{ | ||
if ($str instanceof \DateTimeInterface) { | ||
return true; | ||
} | ||
return (strtotime($str) !== FALSE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class AddTosTable extends AbstractMigration | ||
{ | ||
/** | ||
* Migrate Up. | ||
*/ | ||
public function up() | ||
{ | ||
$this->table('tos') | ||
->addColumn('user_id', 'integer', ['null' => false]) | ||
->addColumn('agreement_date', 'integer', ['null' => false]) | ||
->addColumn('tos_version_date', 'integer', ['null' => false]) | ||
->addForeignKey('user_id', 'users', 'id', [ | ||
'delete' => 'CASCADE', | ||
'update' => 'CASCADE', | ||
]) | ||
->create(); | ||
} | ||
|
||
/** | ||
* Migrate Down. | ||
*/ | ||
public function down() | ||
{ | ||
$this->dropTable('tos'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class AddTosToScope extends AbstractMigration | ||
{ | ||
|
||
/** | ||
* Migrate Up. | ||
*/ | ||
public function up() | ||
{ | ||
$this->execute("INSERT INTO oauth_scopes (scope, name) VALUES ('tos', 'tos')"); | ||
} | ||
|
||
/** | ||
* Migrate Down. | ||
*/ | ||
public function down() | ||
{ | ||
$this->execute("DELETE FROM oauth_scopes WHERE scope = 'tos'"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
paths: | ||
migrations: ./migrations | ||
seeds: %%PHINX_CONFIG_DIR%%/db/seeds | ||
|
||
environments: | ||
default_migration_table: phinxlog | ||
default_database: development | ||
production: | ||
adapter: mysql | ||
host: localhost | ||
name: production_db | ||
user: root | ||
pass: '' | ||
port: 3306 | ||
charset: utf8 | ||
|
||
development: | ||
adapter: mysql | ||
host: 192.168.33.110 | ||
name: ushahidi | ||
user: homestead | ||
pass: 'secret' | ||
port: 3306 | ||
charset: utf8 | ||
|
||
testing: | ||
adapter: mysql | ||
host: localhost | ||
name: testing_db | ||
user: root | ||
pass: '' | ||
port: 3306 | ||
charset: utf8 | ||
|
||
version_order: creation |
Submodule platform-client
added at
2d9703
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/** | ||
* Ushahidi Tag | ||
* | ||
* @author Ushahidi Team <team@ushahidi.com> | ||
* @package Ushahidi\Platform | ||
* @copyright 2014 Ushahidi | ||
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) | ||
*/ | ||
|
||
namespace Ushahidi\Core\Entity; | ||
|
||
use Ushahidi\Core\StaticEntity; | ||
|
||
class Tos extends StaticEntity | ||
{ | ||
protected $id; | ||
protected $user_id; | ||
protected $agreement_date; | ||
protected $tos_version_date; | ||
|
||
protected function getDerived() | ||
{ | ||
// Foreign key alias | ||
return [ | ||
'user_id' => ['user', 'user.id'] | ||
]; | ||
} | ||
|
||
protected function getDefinition() | ||
{ | ||
return [ | ||
'id' => 'int', | ||
'user_id' => 'int', | ||
'agreement_date' => '*date', | ||
'tos_version_date' => '*date', | ||
]; | ||
} | ||
|
||
// Entity | ||
public function getResource() | ||
{ | ||
return 'tos'; | ||
} | ||
} |
Oops, something went wrong.