View Issue Details

IDProjectCategoryView StatusLast Update
0024441mantisbttaggingpublic2019-08-25 12:36
Reporterintuity Assigned Todregad  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version2.14.0 
Target Version2.22.0Fixed in Version2.22.0 
Summary0024441: Report issue doesn't support multiple new tags
Description

When reporting an issue, if you provide multiple new tags within the tag field separated by commas the bug will be created but an error will be displayed and the tags won't be attached. However, if using the tag field in the bug view multiple tags can be added without issue.

This seems to come down to the fact that tags added retrospectively use the TagAttachCommand, whilst tags added during bug creation use code inline in the IssueAddCommand that is fair less capable. I would suggest updating IssueAddCommand at line 333 onwards to the following code:

# Add Tags
if( isset( $t_issue['tags'] ) && is_array( $t_issue['tags'] ) ) {
    $t_data = array(
        'query'   => array( 'issue_id' => $t_issue_id      ),
        'payload' => array( 'tags'     => $t_issue['tags'] )
    );
    $t_command = new TagAttachCommand( $t_data );
    $t_command->execute();
}

Other changes need to be made to support this. In bug_report.php the tags need to be either mapped to an existing ID OR passed by name to be created - from line 106 onwards:

$t_tags = tag_parse_string( $t_tag_string );
if( !empty( $t_tags ) ) {
    $t_issue['tags'] = array();
    foreach( $t_tags as $t_tag ) {
        if ( $t_tag['id'] == -1 ) {
            $t_issue['tags'][] = array( 'name' => $t_tag['name'] );
        } else  {
            $t_issue['tags'][] = array( 'id' => $t_tag['id'] );
        }
    }
}

And print_api.php needs to be updated to display the field separator - line 352 onwards:

function print_tag_attach_form( $p_bug_id, $p_string = '' ) {
?>
    <form method="post" action="tag_attach.php" class="form-inline">
    <?php echo form_security_field( 'tag_attach' )?>
    <input type="hidden" name="bug_id" value="<?php echo $p_bug_id?>" class="input-sm" />
    <?php print_tag_input( $p_bug_id, $p_string ); ?>
    <input type="submit" value="<?php echo lang_get( 'tag_attach' )?>" class="btn btn-primary btn-sm btn-white btn-round" />
    </form>
<?php
    return true;
}

/**
 * Print the separator comment, input box, and existing tag dropdown menu.
 * @param integer $p_bug_id A bug identifier.
 * @param string  $p_string Default contents of the input box.
 * @return void
 */
function print_tag_input( $p_bug_id = 0, $p_string = '' ) {
?>
    <label class="inline small"><?php echo sprintf( lang_get( 'tag_separate_by' ), config_get( 'tag_separator' ) )?></label>
    <input type="hidden" id="tag_separator" value="<?php echo config_get( 'tag_separator' )?>" />
    <input type="text" name="tag_string" id="tag_string" class="input-sm" size="40" value="<?php echo string_attribute( $p_string )?>" />
    <select class="input-sm" <?php echo helper_get_tab_index()?> name="tag_select" id="tag_select" class="input-sm">
        <?php print_tag_option_list( $p_bug_id );?>
    </select>
<?php
}

NOTE: Even though an error is displayed and no tags were attached, the issue is still created as the bug is created first - then tagged. Perhaps there needs to be some additional checking to ensure tags can be assigned before creating the issue.

Steps To Reproduce
  1. Create a new bug
  2. Add multiple new tags into the 'Attach Tags' field - e.g.: 'banana, apple, pineapple'
  3. Submit form

Bug is created, bug tag attachment fails, so error message displayed.

TagsNo tags attached.

Activities

dregad

dregad

2018-05-18 03:12

developer   ~0059847

@intuity thanks for the detailed bug report and proposed fix.

I noticed this is not the first time (0024437) that you suggest code changes via the bugtracker like this. To make it easier for us to review, test and merge such changes, would you consider submitting your patches as pull requests via Github instead ?

NOTE: Even though an error is displayed and no tags were attached, the issue is still created as the bug is created first - then tagged. Perhaps there needs to be some additional checking to ensure tags can be assigned before creating the issue.

You're absolutely right. For the record, the same problem exists also when adding attachments fails for any reason - see 0003759. As per the discussion there, the solution is not as simple as adding some checks.

intuity

intuity

2018-05-23 13:47

reporter   ~0059927

@dregad will do - I'll try to build a patch for the above and make a request on GitHub.

Related Changesets

MantisBT: master 38a067f2

2019-08-24 21:32:18

dregad

Details Diff
Print 'separate by' on tag attach form

Issue 0024441
Affected Issues
0024441
mod - core/print_api.php Diff File

MantisBT: master 1e5e25a8

2019-08-24 21:35:32

dregad

Details Diff
TODO: replace mci_tag_set_for_issue() with TagAttachCommand

As suggested in issue 0024441
Affected Issues
0024441
mod - core/commands/IssueAddCommand.php Diff File

MantisBT: master 6b774eac

2019-08-24 21:58:51

dregad

Details Diff
IssueAddCommand fixes

This addresses several issues with the Command and the REST API:

- 0025996 - Missing tag name in error message when creating issue via
REST API
- 0025997 - Invalid JSON response when creating issue with tag by name
via REST API
- 0026076 - Adding issue via REST API should fail if requested tags can't
be attached
- 0026077 - create tag specified by name if they do not exist

Additionally, this also fixes 0024441.

Merge PR https://github.com/mantisbt/mantisbt/pull/1542
Affected Issues
0024441
mod - api/soap/mc_tag_api.php Diff File
mod - bug_report.php Diff File
mod - core/commands/IssueAddCommand.php Diff File

Issue History

Date Modified Username Field Change
2018-05-17 11:21 intuity New Issue
2018-05-18 03:12 dregad Status new => acknowledged
2018-05-18 03:12 dregad Note Added: 0059847
2018-05-23 13:47 intuity Note Added: 0059927
2018-05-23 17:12 atrol Assigned To => community
2018-05-23 17:12 atrol Status acknowledged => assigned
2019-08-24 22:09 dregad Changeset attached => MantisBT master 1e5e25a8
2019-08-24 22:09 dregad Changeset attached => MantisBT master 6b774eac
2019-08-24 22:09 dregad Changeset attached => MantisBT master 38a067f2
2019-08-24 22:09 dregad Assigned To community => dregad
2019-08-24 22:09 dregad Status assigned => resolved
2019-08-24 22:09 dregad Resolution open => fixed
2019-08-24 22:09 dregad Fixed in Version => 2.22.0
2019-08-25 04:41 atrol Target Version => 2.22.0
2019-08-25 12:36 vboctor Status resolved => closed