Skip to content

Commit

Permalink
Support new tags when creating new issues
Browse files Browse the repository at this point in the history
Fixes #24774
  • Loading branch information
vboctor committed Oct 8, 2018
1 parent 25eec2c commit 6219ca3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bug_report.php
Expand Up @@ -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'] );
}
}

Expand Down
21 changes: 20 additions & 1 deletion core/commands/IssueAddCommand.php
Expand Up @@ -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 );

Expand Down Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions core/tag_api.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand All @@ -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 );
Expand Down

0 comments on commit 6219ca3

Please sign in to comment.