Permalink
Browse files

Support new tags when creating new issues

Fixes #24774
  • Loading branch information...
vboctor committed Sep 30, 2018
1 parent 25eec2c commit 6219ca31821ec9cb6a1433a343ee10c7694d9149
Showing with 43 additions and 4 deletions.
  1. +1 −1 bug_report.php
  2. +20 −1 core/commands/IssueAddCommand.php
  3. +22 −2 core/tag_api.php
@@ -106,7 +106,7 @@
if( !empty( $t_tags ) ) {
$t_issue['tags'] = array();
foreach( $t_tags as $t_tag ) {
$t_issue['tags'][] = array( 'id' => $t_tag['id'] );
$t_issue['tags'][] = array( 'id' => $t_tag['id'], 'name' => $t_tag['name'] );
}
}
@@ -217,6 +217,16 @@ function validate() {
}
}
if( isset( $t_issue['tags'] ) && is_array( $t_issue['tags'] ) && !tag_can_create( $this->user_id ) ) {
foreach( $t_issue['tags'] as $t_tag ) {
if( $t_tag['id'] === -1 ) {
throw new ClientException(
sprintf( "User '%d' can't create tag '%s'.", $this->user_id, $t_new_tag ),
ERROR_TAG_NOT_FOUND );
}
}
}
$t_category = isset( $t_issue['category'] ) ? $t_issue['category'] : null;
$t_category_id = mci_get_category_id( $t_category, $t_project_id );
@@ -332,7 +342,16 @@ protected function process() {
# Add Tags
if( isset( $t_issue['tags'] ) && is_array( $t_issue['tags'] ) ) {
mci_tag_set_for_issue( $t_issue_id, $t_issue['tags'], $this->user_id );
$t_tags = array();
foreach( $t_issue['tags'] as $t_tag ) {
if( $t_tag['id'] === -1 ) {
$t_tag['id'] = tag_create( $t_tag['name'], $this->user_id );
}
$t_tags[] = $t_tag;
}
mci_tag_set_for_issue( $t_issue_id, $t_tags, $this->user_id );
}
# Handle the file upload
@@ -327,7 +327,7 @@ function tag_attach_many( $p_bug_id, $p_tag_string, $p_tag_id = 0 ) {
access_ensure_bug_level( config_get( 'tag_attach_threshold' ), $p_bug_id );
$t_tags = tag_parse_string( $p_tag_string );
$t_can_create = access_has_global_level( config_get( 'tag_create_threshold' ) );
$t_can_create = tag_can_create();
$t_tags_create = array();
$t_tags_attach = array();
@@ -529,6 +529,26 @@ function tag_get_field( $p_tag_id, $p_field_name ) {
}
}
/**
* Can the specified user create a tag?
*
* @param integer $p_user_id The id of the user to check access rights for.
* @return bool true: can create, false: otherwise.
*/
function tag_can_create( $p_user_id = null ) {
return access_has_global_level( config_get( 'tag_create_threshold' ), $p_user_id );
}
/**
* Ensure specified user can create tags.
*
* @param integer $p_user_id The id of the user to check access rights for.
* @return void
*/
function tag_ensure_can_create( $p_user_id = null ) {
access_ensure_global_level( config_get( 'tag_create_threshold' ), $p_user_id );
}
/**
* Create a tag with the given name, creator, and description.
* Defaults to the currently logged in user, and a blank description.
@@ -538,7 +558,7 @@ function tag_get_field( $p_tag_id, $p_field_name ) {
* @return int Tag ID
*/
function tag_create( $p_name, $p_user_id = null, $p_description = '' ) {
access_ensure_global_level( config_get( 'tag_create_threshold' ) );
tag_ensure_can_create( $p_user_id );
tag_ensure_name_is_valid( $p_name );
tag_ensure_unique( $p_name );

0 comments on commit 6219ca3

Please sign in to comment.