forked from ushahidi/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/add review workflow toggle (ushahidi#1318)
* Add require_approval to Form entity * Add everyone_can_create to Form entity * Add form_roles table to record roles which can_create posts in a survey * Update post authorizer to honor who can create for each form * Update post validator to check status based on required approval settings * Add new tests * Architecture: Give validators access to full entity as well as changes. - Avoids nasty overrides in UpdatePost to pass needed info to validator * Add auto-publish for forms that don't require approval - Posts added to a form with `require_approval` set to false will be created with `status` = ‘published’. Refs ushahidi#1282
- Loading branch information
Showing
38 changed files
with
1,358 additions
and
276 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,51 @@ | ||
<?php defined('SYSPATH') OR die('No direct access allowed.'); | ||
|
||
/** | ||
* Ushahidi API Forms Roles 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_Roles extends Ushahidi_Rest { | ||
|
||
protected $_action_map = array | ||
( | ||
Http_Request::GET => 'get', | ||
Http_Request::PUT => 'put', // Typically Update.. | ||
Http_Request::OPTIONS => 'options' | ||
); | ||
|
||
protected function _scope() | ||
{ | ||
return 'forms'; | ||
} | ||
|
||
protected function _resource() | ||
{ | ||
return 'form_roles'; | ||
} | ||
|
||
// Ushahidi_Rest | ||
public function action_get_index_collection() | ||
{ | ||
parent::action_get_index_collection(); | ||
|
||
$this->_usecase->setIdentifiers($this->request->param()); | ||
$this->_usecase->setFilters($this->request->query() + [ | ||
'form_id' => $this->request->param('form_id') | ||
]); | ||
} | ||
|
||
// Ushahidi_Rest | ||
public function action_put_index_collection() | ||
{ | ||
$this->_usecase = service('factory.usecase') | ||
->get($this->_resource(), 'update_collection') | ||
->setIdentifiers($this->_identifiers()) | ||
->setPayload($this->_payload()); | ||
} | ||
|
||
} |
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,31 @@ | ||
<?php defined('SYSPATH') OR die('No direct access allowed.'); | ||
|
||
/** | ||
* Ushahidi API Formatter for Form Role | ||
* | ||
* @author Ushahidi Team <[email protected]> | ||
* @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_Form_Role extends Ushahidi_Formatter_API | ||
{ | ||
use FormatterAuthorizerMetadata; | ||
|
||
public function __invoke($entity) | ||
{ | ||
$data = [ | ||
'id' => $entity->id, | ||
'url' => URL::site('forms/' . $entity->form_id . '/roles/' . $entity->id, Request::current()), | ||
'form_id' => $entity->form_id, | ||
'role_id' => $entity->role_id, | ||
]; | ||
|
||
$data = $this->add_metadata($data, $entity); | ||
|
||
return $data; | ||
} | ||
} |
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,98 @@ | ||
<?php defined('SYSPATH') OR die('No direct access allowed.'); | ||
|
||
/** | ||
* Ushahidi Form Role Repository | ||
* | ||
* @author Ushahidi Team <[email protected]> | ||
* @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\Data; | ||
use Ushahidi\Core\Entity; | ||
use Ushahidi\Core\SearchData; | ||
use Ushahidi\Core\Entity\FormRole; | ||
use Ushahidi\Core\Entity\FormRoleRepository; | ||
|
||
class Ushahidi_Repository_Form_Role extends Ushahidi_Repository implements | ||
FormRoleRepository | ||
{ | ||
// Ushahidi_Repository | ||
protected function getTable() | ||
{ | ||
return 'form_roles'; | ||
} | ||
|
||
// CreateRepository | ||
// ReadRepository | ||
public function getEntity(Array $data = null) | ||
{ | ||
return new FormRole($data); | ||
} | ||
|
||
// SearchRepository | ||
public function getSearchFields() | ||
{ | ||
return ['form_id', 'roles']; | ||
} | ||
|
||
// Ushahidi_Repository | ||
protected function setSearchConditions(SearchData $search) | ||
{ | ||
$query = $this->search_query; | ||
|
||
if ($search->form_id) { | ||
$query->where('form_id', '=', $search->form_id); | ||
} | ||
|
||
if ($search->roles) { | ||
$query->where('role_id', 'in', $search->roles); | ||
} | ||
} | ||
|
||
// FormRoleRepository | ||
public function updateCollection(Array $entities) | ||
{ | ||
if (empty($entities)) { | ||
return; | ||
} | ||
|
||
// Delete all existing form roles records | ||
// Assuming all entites have the same form id | ||
$this->deleteAllForForm(current($entities)->form_id); | ||
|
||
$query = DB::insert($this->getTable()) | ||
->columns(array_keys(current($entities)->asArray())); | ||
|
||
foreach($entities as $entity) { | ||
$query->values($entity->asArray()); | ||
} | ||
|
||
$query->execute($this->db); | ||
|
||
return $entities; | ||
} | ||
|
||
// FormRoleRepository | ||
public function getByForm($form_id) | ||
{ | ||
$query = $this->selectQuery(compact($form_id)); | ||
$results = $query->execute($this->db); | ||
|
||
return $this->getCollection($results->as_array()); | ||
} | ||
|
||
// ValuesForFormRoleRepository | ||
public function deleteAllForForm($form_id) | ||
{ | ||
return $this->executeDelete(compact('form_id')); | ||
} | ||
|
||
// FormRoleRepository | ||
public function existsInFormRole($role_id, $form_id) | ||
{ | ||
return (bool) $this->selectCount(compact('role_id', 'form_id')); | ||
} | ||
|
||
} |
Oops, something went wrong.