Verify taxonomy visibility when saving metadatum #220

This commit is contained in:
leogermani 2019-04-08 12:49:43 -03:00
parent 4a7e0f1a9a
commit 512aed2017
5 changed files with 64 additions and 3 deletions

View File

@ -117,6 +117,16 @@ class Taxonomy extends Metadata_Type {
$Tainacan_Metadata = Metadata::get_instance();
// Check taxonomy visibility
$status = get_post_status( $this->get_option('taxonomy_id') );
$post_status_obj = get_post_status_object($status);
if ( ! $post_status_obj->public ) {
$meta_status_obj = get_post_status_object($metadatum->get_status());
if ( $meta_status_obj->public ) {
return ['taxonomy_id' => __('This metadatum can not be public because chosen taxonomy is not.', 'tainacan')];
}
}
$taxonomy_metadata = $Tainacan_Metadata->fetch([
'collection_id' => $metadatum->get_collection_id(),
'metadata_type' => 'Tainacan\\Metadata_Types\\Taxonomy'

View File

@ -161,7 +161,7 @@ class TAINACAN_REST_Visibilility_Controller extends TAINACAN_UnitApiTestCase {
'metadatum',
array(
'name' => 'metadata-private',
'status' => 'publish',
'status' => 'private',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'metadata_type_options' => [

View File

@ -62,7 +62,8 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
array(
'name' => 'genero',
'description' => 'tipos de musica',
'allow_insert' => 'yes'
'allow_insert' => 'yes',
'status' => 'publish'
),
true
);
@ -1214,7 +1215,8 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
array(
'name' => 'tax2',
'description' => 'tipos de musica',
'allow_insert' => 'yes'
'allow_insert' => 'yes',
'status' => 'publish'
),
true
);

View File

@ -35,6 +35,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
array(
'name' => 'tax_test',
'collections' => [$collection],
'status' => 'publish'
),
true
);
@ -556,6 +557,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
'taxonomy',
array(
'name' => 'tax_test',
'status' => 'publish'
),
true
);
@ -604,5 +606,51 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase {
}
function test_validate_private_taxonomy() {
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$Tainacan_ItemMetadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test',
),
true
);
$tax = $this->tainacan_entity_factory->create_entity(
'taxonomy',
array(
'name' => 'tax_test',
'status' => 'private'
),
true
);
$meta = new \Tainacan\Entities\Metadatum();
$meta->set_name('test meta');
$meta->set_status('publish');
$meta->set_metadata_type('Tainacan\Metadata_Types\Taxonomy');
$meta->set_collection($collection);
$meta->set_metadata_type_options([
'taxonomy_id' => $tax->get_id(),
'allow_new_terms' => true
]);
$this->assertFalse($meta->validate(), 'Metadatum should not validate because taxonomy is private');
$meta->set_status('private');
$this->assertTrue($meta->validate(), 'Metadatum should validate because it is private now');
}
}

View File

@ -335,6 +335,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
'taxonomy',
array(
'name' => 'genero',
'status' => 'publish'
),
true
);