verify permission on taxonomy importer #274

This commit is contained in:
leogermani 2019-12-06 16:29:06 -03:00
parent 3175d7e8d8
commit 58621f3538
1 changed files with 29 additions and 19 deletions

View File

@ -127,6 +127,13 @@ class Term_Importer extends Importer {
$last_term = $this->get_transient('last_term') == null ? 0: $this->get_transient('last_term');
$id_taxonomy= $this->get_transient('new_taxonomy');
$taxonomy = \tainacan_taxonomies()->fetch( (int) $id_taxonomy );
if ( $taxonomy instanceof Entities\Taxonomy && ! $taxonomy->can_edit() ) {
$this->add_error_log("You don't have permission to add terms to this taxonomy");
$this->abort();
return false;
}
$position_file = $this->get_in_step_count();
fseek($file, $position_file);
if (($values = fgetcsv($file, 0, $this->get_option('delimiter'), '"')) !== FALSE) {
@ -191,7 +198,10 @@ class Term_Importer extends Importer {
$tax1->set_allow_insert('yes');
$tax1->set_status('publish');
if ($tax1->validate()) {
if ( ! $tax1->get_capabilities()->edit_posts ) {
$this->add_error_log('Error creating taxonomy. Permission denied');
$this->abort();
} elseif ($tax1->validate()) {
$tax_repo = \Tainacan\Repositories\Taxonomies::get_instance();
$tax1 = $tax_repo->insert($tax1);
$name = $tax1->get_name();