fixing terms api permission checks

This commit is contained in:
Leo Germani 2018-01-29 17:30:01 -02:00
parent 0b10630a2d
commit 7d616c5cca
2 changed files with 21 additions and 6 deletions

View File

@ -130,7 +130,11 @@ class TAINACAN_REST_Terms_Controller extends WP_REST_Controller {
* @return bool|WP_Error
*/
public function create_item_permissions_check( $request ) {
return $this->terms_repository->can_edit($this->term);
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
if ($taxonomy instanceof Entities\Taxonomy) {
return $taxonomy->can_edit();
}
return false;
}
/**
@ -163,8 +167,11 @@ class TAINACAN_REST_Terms_Controller extends WP_REST_Controller {
* @return bool|WP_Error
*/
public function delete_item_permissions_check( $request ) {
$term = new Entities\Term($this->terms_repository->fetch($request['term_id']));
return $this->terms_repository->can_delete($term);
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
if ($taxonomy instanceof Entities\Taxonomy) {
return $taxonomy->can_edit();
}
return false;
}
/**
@ -209,8 +216,11 @@ class TAINACAN_REST_Terms_Controller extends WP_REST_Controller {
* @return bool|WP_Error
*/
public function update_item_permissions_check( $request ) {
$term = new Entities\Term($this->terms_repository->fetch($request['term_id']));
return $this->terms_repository->can_edit($term);
$taxonomy = $this->taxonomy_repository->fetch($request['taxonomy_id']);
if ($taxonomy instanceof Entities\Taxonomy) {
return $taxonomy->can_edit();
}
return false;
}
/**

View File

@ -162,7 +162,12 @@ class Taxonomies extends Repository {
// TODO: Pegar taxonomias registradas via código
if( is_numeric($args) ){
return new Entities\Taxonomy($args);
$existing_post = get_post($args);
if ($existing_post instanceof \WP_Post) {
return new Entities\Taxonomy($existing_post);
} else {
return [];
}
} elseif (is_array($args)) {
$args = array_merge([