Allow insert draft Items

This commit is contained in:
weryques 2018-01-29 11:09:44 -02:00
parent f8d7393e2f
commit cf5cb62d21
6 changed files with 46 additions and 15 deletions

View File

@ -166,8 +166,9 @@ class Entity {
$this->reset_errors();
foreach ($map as $prop => $mapped) {
if (!$this->validate_prop($prop))
$is_valid = false;
if (!$this->validate_prop($prop)) {
$is_valid = false;
}
}
$this->set_validated($is_valid);
@ -204,11 +205,20 @@ class Entity {
}
}
} else {
if (!$validation->validate($prop_value)) {
$status = $this->get_mapped_property('status');
$this->add_error('invalid', $message);
if ( !$validation->validate($prop_value)
&& ( $prop !== 'title' || $prop !== 'name' )
&& ( strpos($status, 'draft') || empty($status) ) ) {
$this->add_error('invalid', $message);
$is_valid = false;
}
elseif(!$validation->validate($prop_value) && (strpos($status, 'draft') === false)){
$this->add_error('invalid', $message);
$is_valid = false;
}
}
}

View File

@ -26,8 +26,15 @@ class Collections extends Repository {
'title' => __('Name', 'tainacan'),
'type' => 'string',
'description' => __('Name of the collection', 'tainacan'),
'validation' => v::stringType(),
'validation' => v::stringType()->notEmpty(),
],
'status' => [
'map' => 'post_status',
'title' => __('Status', 'tainacan'),
'type' => 'string',
'default' => '',
'description' => __('The posts status', 'tainacan')
],
'author_id' => [
'map' => 'post_author',
'title' => __('Author', 'tainacan'),

View File

@ -16,8 +16,15 @@ class Items extends Repository {
'type' => 'string',
'description'=> __('Title of the item', 'tainacan'),
'on_error' => __('The title should be a text value and not empty', 'tainacan'),
'validation' => v::stringType()->notEmpty()
'validation' => v::stringType()->notEmpty(),
],
'status' => [
'map' => 'post_status',
'title' => __('Status', 'tainacan'),
'type' => 'string',
'default' => 'draft',
'description' => __('The posts status', 'tainacan')
],
'description' => [
'map' => 'post_content',
'title' => __('Description', 'tainacan'),
@ -121,7 +128,7 @@ class Items extends Repository {
// save post and geet its ID
$item->WP_Post->post_type = $cpt;
$item->WP_Post->post_status = 'publish';
//$item->WP_Post->post_status = 'publish';
$id = wp_insert_post($item->WP_Post);
$item->WP_Post = get_post($id);

View File

@ -12,7 +12,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_UnitApiTestCase {
'collection',
array(
'name' => 'Javascript Frameworks',
'description' => 'The best framework to javascript'
'description' => 'The best framework to javascript',
),
true
);
@ -49,7 +49,8 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_UnitApiTestCase {
array(
'title' => 'Lean Startup',
'description' => 'Um processo ágil de criação de novos negócios.',
'collection' => $collection
'collection' => $collection,
'status' => 'publish'
),
true
);
@ -59,7 +60,8 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_UnitApiTestCase {
array(
'title' => 'SCRUM',
'description' => 'Um framework ágil para gerenciamento de tarefas.',
'collection' => $collection
'collection' => $collection,
'status' => 'publish'
),
true
);

View File

@ -157,7 +157,8 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
array(
'title' => 'item teste',
'description' => 'adasdasdsa',
'collection' => $collection
'collection' => $collection,
'status' => 'publish'
),
true
);

View File

@ -101,7 +101,8 @@ class Items extends TAINACAN_UnitTestCase {
'collection' => $collection,
'add_metadata' => [
[$metadata, 'value_1']
]
],
'status' => 'publish'
),
true
);
@ -121,7 +122,8 @@ class Items extends TAINACAN_UnitTestCase {
'add_metadata' => [
[$metadata2, 'value_2'],
[$metadata3, 'value_2']
]
],
'status' => 'publish'
),
true
);
@ -135,7 +137,8 @@ class Items extends TAINACAN_UnitTestCase {
[$metadata2, 'value_2'],
[$metadata2, 'value_3'],
[$metadata3, 'value_3']
]
],
'status' => 'publish'
),
true
);
@ -148,7 +151,8 @@ class Items extends TAINACAN_UnitTestCase {
'add_metadata' => [
[$metadata2, 'value_3'],
[$metadata3, 'value_6']
]
],
'status' => 'publish'
),
true
);