From d5fa3b7326b20293e358bdc21f66bc29d7f7a40f Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Thu, 21 Mar 2019 10:46:52 -0300 Subject: [PATCH] add can_delete flag to entities in the API --- .../endpoints/class-tainacan-rest-collections-controller.php | 2 ++ src/api/endpoints/class-tainacan-rest-filters-controller.php | 1 + .../endpoints/class-tainacan-rest-item-metadata-controller.php | 1 + src/api/endpoints/class-tainacan-rest-items-controller.php | 2 ++ src/api/endpoints/class-tainacan-rest-metadata-controller.php | 1 + src/api/endpoints/class-tainacan-rest-taxonomies-controller.php | 1 + src/api/endpoints/class-tainacan-rest-terms-controller.php | 1 + 7 files changed, 9 insertions(+) diff --git a/src/api/endpoints/class-tainacan-rest-collections-controller.php b/src/api/endpoints/class-tainacan-rest-collections-controller.php index 7798aecda..9571c4a7d 100644 --- a/src/api/endpoints/class-tainacan-rest-collections-controller.php +++ b/src/api/endpoints/class-tainacan-rest-collections-controller.php @@ -181,6 +181,7 @@ class REST_Collections_Controller extends REST_Controller { $item_arr['moderators'] = $moderators; $item_arr['current_user_can_edit'] = $item->can_edit(); + $item_arr['current_user_can_delete'] = $item->can_delete(); } unset($item_arr['moderators_ids']); @@ -200,6 +201,7 @@ class REST_Collections_Controller extends REST_Controller { if ( $request['context'] === 'edit' ) { $item_arr['current_user_can_edit'] = $item->can_edit(); + $item_arr['current_user_can_delete'] = $item->can_delete(); } $item_arr['url'] = get_permalink( $item_arr['id'] ); diff --git a/src/api/endpoints/class-tainacan-rest-filters-controller.php b/src/api/endpoints/class-tainacan-rest-filters-controller.php index 739abcc0a..702879823 100644 --- a/src/api/endpoints/class-tainacan-rest-filters-controller.php +++ b/src/api/endpoints/class-tainacan-rest-filters-controller.php @@ -326,6 +326,7 @@ class REST_Filters_Controller extends REST_Controller { if($request['context'] === 'edit'){ $item_arr['current_user_can_edit'] = $item->can_edit(); + $item_arr['current_user_can_delete'] = $item->can_delete(); $item_arr['enabled'] = $item->get_enabled_for_collection(); } diff --git a/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php b/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php index 8a8d30c01..ffd5a6860 100644 --- a/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php +++ b/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php @@ -100,6 +100,7 @@ class REST_Item_Metadata_Controller extends REST_Controller { if($request['context'] === 'edit'){ $item_arr['current_user_can_edit'] = $item->can_edit(); + $item_arr['current_user_can_delete'] = $item->can_delete(); } return $item_arr; diff --git a/src/api/endpoints/class-tainacan-rest-items-controller.php b/src/api/endpoints/class-tainacan-rest-items-controller.php index 98b53624b..4694a7d69 100644 --- a/src/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/api/endpoints/class-tainacan-rest-items-controller.php @@ -161,6 +161,7 @@ class REST_Items_Controller extends REST_Controller { if ( $request['context'] === 'edit' ) { $item_arr['current_user_can_edit'] = $item->can_edit(); + $item_arr['current_user_can_delete'] = $item->can_delete(); } $img_size = 'large'; @@ -206,6 +207,7 @@ class REST_Items_Controller extends REST_Controller { if ( $request['context'] === 'edit' ) { $item_arr['current_user_can_edit'] = $item->can_edit(); + $item_arr['current_user_can_delete'] = $item->can_delete(); } $item_arr['url'] = get_permalink( $item_arr['id'] ); diff --git a/src/api/endpoints/class-tainacan-rest-metadata-controller.php b/src/api/endpoints/class-tainacan-rest-metadata-controller.php index a832a4a9c..e26bfdfe8 100644 --- a/src/api/endpoints/class-tainacan-rest-metadata-controller.php +++ b/src/api/endpoints/class-tainacan-rest-metadata-controller.php @@ -295,6 +295,7 @@ class REST_Metadata_Controller extends REST_Controller { if($request['context'] === 'edit'){ $item_arr['current_user_can_edit'] = $item->can_edit(); + $item_arr['current_user_can_delete'] = $item->can_delete(); ob_start(); $item->get_metadata_type_object()->form(); $form = ob_get_clean(); diff --git a/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php b/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php index 1841a80f2..8c7730c92 100644 --- a/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php +++ b/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php @@ -100,6 +100,7 @@ class REST_Taxonomies_Controller extends REST_Controller { if ( $request['context'] === 'edit' ) { $item_arr['current_user_can_edit'] = $item->can_edit(); + $item_arr['current_user_can_delete'] = $item->can_delete(); $item_arr['collections'] = []; if ( is_array($tax_collections = $item->get_collections()) ) { foreach ($tax_collections as $tax_collection) { diff --git a/src/api/endpoints/class-tainacan-rest-terms-controller.php b/src/api/endpoints/class-tainacan-rest-terms-controller.php index 2049cb0f3..aab90ec76 100644 --- a/src/api/endpoints/class-tainacan-rest-terms-controller.php +++ b/src/api/endpoints/class-tainacan-rest-terms-controller.php @@ -261,6 +261,7 @@ class REST_Terms_Controller extends REST_Controller { if ( $request['context'] === 'edit' ) { $item_arr['current_user_can_edit'] = $item->can_edit(); + $item_arr['current_user_can_delete'] = $item->can_delete(); } $children = get_terms([