From cd3b8b4813c1a2a1e1b5467011436306bc678668 Mon Sep 17 00:00:00 2001 From: Koosha KM Date: Thu, 16 Oct 2014 17:14:07 +0000 Subject: Bug 1080840: Update WebServices to include Markdown feature r=dkl,a=glob --- Bugzilla/WebService/Bug.pm | 126 ++++++++++++++++++++---- Bugzilla/WebService/Constants.pm | 1 + template/en/default/global/user-error.html.tmpl | 3 + 3 files changed, 112 insertions(+), 18 deletions(-) diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index 6525b4694..f50bb6aee 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -352,15 +352,16 @@ sub _translate_comment { : undef; my $comment_hash = { - id => $self->type('int', $comment->id), - bug_id => $self->type('int', $comment->bug_id), - creator => $self->type('email', $comment->author->login), - time => $self->type('dateTime', $comment->creation_ts), + id => $self->type('int', $comment->id), + bug_id => $self->type('int', $comment->bug_id), + creator => $self->type('email', $comment->author->login), + time => $self->type('dateTime', $comment->creation_ts), creation_time => $self->type('dateTime', $comment->creation_ts), - is_private => $self->type('boolean', $comment->is_private), - text => $self->type('string', $comment->body_full), + is_private => $self->type('boolean', $comment->is_private), + is_markdown => $self->type('boolean', $comment->is_markdown), + text => $self->type('string', $comment->body_full), attachment_id => $self->type('int', $attach_id), - count => $self->type('int', $comment->count), + count => $self->type('int', $comment->count), }; # Don't load comment tags unless enabled @@ -824,10 +825,20 @@ sub add_attachment { $attachment->update($timestamp); my $comment = $params->{comment} || ''; - $attachment->bug->add_comment($comment, - { isprivate => $attachment->isprivate, - type => CMT_ATTACHMENT_CREATED, - extra_data => $attachment->id }); + + my $is_markdown = 0; + if (ref $params->{comment} eq 'HASH') { + $is_markdown = $params->{comment}->{is_markdown}; + $comment = $params->{comment}->{body}; + } + + ThrowUserError('markdown_disabled') if $is_markdown && !_is_markdown_enabled(); + + $attachment->bug->add_comment($comment, + { is_markdown => $is_markdown, + isprivate => $attachment->isprivate, + type => CMT_ATTACHMENT_CREATED, + extra_data => $attachment->id }); push(@created, $attachment); } $_->bug->update($timestamp) foreach @created; @@ -873,6 +884,14 @@ sub update_attachment { my $flags = delete $params->{flags}; my $comment = delete $params->{comment}; + my $is_markdown = 0; + + if (ref $comment eq 'HASH') { + $is_markdown = $comment->{is_markdown}; + $comment = $comment->{body}; + } + + ThrowUserError('markdown_disabled') if $is_markdown && !_is_markdown_enabled(); # Update the values foreach my $attachment (@attachments) { @@ -892,9 +911,10 @@ sub update_attachment { if ($comment = trim($comment)) { $attachment->bug->add_comment($comment, - { isprivate => $attachment->isprivate, - type => CMT_ATTACHMENT_UPDATED, - extra_data => $attachment->id }); + { is_markdown => $is_markdown, + isprivate => $attachment->isprivate, + type => CMT_ATTACHMENT_UPDATED, + extra_data => $attachment->id }); } $changes = translate($changes, ATTACHMENT_MAPPED_RETURNS); @@ -951,9 +971,13 @@ sub add_comment { if (defined $params->{private}) { $params->{is_private} = delete $params->{private}; } + + ThrowUserError('markdown_disabled') if $params->{is_markdown} && !_is_markdown_enabled(); + # Append comment - $bug->add_comment($comment, { isprivate => $params->{is_private}, - work_time => $params->{work_time} }); + $bug->add_comment($comment, { isprivate => $params->{is_private}, + is_markdown => $params->{is_markdown}, + work_time => $params->{work_time} }); # Capture the call to bug->update (which creates the new comment) in # a transaction so we're sure to get the correct comment_id. @@ -1401,6 +1425,14 @@ sub _add_update_tokens { } } +sub _is_markdown_enabled { + my $user = Bugzilla->user; + + return Bugzilla->feature('markdown') + && $user->settings->{use_markdown}->{is_enabled} + && $user->setting('use_markdown') eq 'on'; +} + 1; __END__ @@ -2078,6 +2110,10 @@ may be deprecated and removed in a future release. C True if this comment is private (only visible to a certain group called the "insidergroup"), False otherwise. +=item is_markdown + +C True if this comment needs Markdown processing, false otherwise. + =back =item B @@ -3095,6 +3131,9 @@ don't want it to be assigned to the component owner. =item C (boolean) - If set to true, the description is private, otherwise it is assumed to be public. +=item C (boolean) - If set to true, the description +has Markdown structures, otherwise it is a normal text. + =item C (array) - An array of group names to put this bug into. You can see valid group names on the Permissions tab of the Preferences screen, or, if you are an administrator, @@ -3250,6 +3289,8 @@ Bugzilla B<4.4>. =item REST API call added in Bugzilla B<5.0>. +=item C option added in Bugzilla B<5.0>. + =back =back @@ -3309,7 +3350,21 @@ C or C. =item C -C A comment to add along with this attachment. +C or hash. A comment to add along with this attachment. If C +is a hash, it has the following keys: + +=over + +=item C + +C The body of the comment. + +=item C + +C If set to true, the comment has Markdown structures; otherwise, it +is an ordinary text. + +=back =item C @@ -3387,6 +3442,10 @@ the type id value to update or add a flag. The flag type is inactive and cannot be used to create new flags. +=item 140 (Markdown Disabled) + +You tried to set the C flag of the comment to true but the Markdown feature is not enabled. + =item 600 (Attachment Too Large) You tried to attach a file that was larger than Bugzilla will accept. @@ -3422,6 +3481,8 @@ You set the "data" field to an empty string. =item REST API call added in Bugzilla B<5.0>. +=item C added in Bugzilla B<5.0>. + =back =back @@ -3468,7 +3529,21 @@ attachment. =item C -C An optional comment to add to the attachment's bug. +C or hash: An optional comment to add to the attachment's bug. If C is +a hash, it has the following keys: + +=over + +=item C + +C The body of the comment to be added. + +=item C + +C If set to true, the comment has Markdown structures; otherwise it is a normal +text. + +=back =item C @@ -3617,6 +3692,11 @@ the type id value to update or add a flag. The flag type is inactive and cannot be used to create new flags. +=item 140 (Markdown Disabled) + +You tried to set the C flag of the C to true but Markdown feature is +not enabled. + =item 601 (Invalid MIME Type) You specified a C argument that was blank, not a valid @@ -3677,6 +3757,9 @@ you did not set the C parameter. =item C (boolean) - If set to true, the comment is private, otherwise it is assumed to be public. +=item C (boolean) - If set to true, the comment has Markdown +structures, otherwise it is a normal text. + =item C (double) - Adds this many hours to the "Hours Worked" on the bug. If you are not in the time tracking group, this value will be ignored. @@ -3718,6 +3801,11 @@ You tried to add a private comment, but don't have the necessary rights. You tried to add a comment longer than the maximum allowed length (65,535 characters). +=item 140 (Markdown Disabled) + +You tried to set the C flag to true but the Markdown feature +is not enabled. + =back =item B @@ -3740,6 +3828,8 @@ code of 32000. =item REST API call added in Bugzilla B<5.0>. +=item C option added in Bugzilla B<5.0>. + =back =back diff --git a/Bugzilla/WebService/Constants.pm b/Bugzilla/WebService/Constants.pm index d612ebc75..db50611cb 100644 --- a/Bugzilla/WebService/Constants.pm +++ b/Bugzilla/WebService/Constants.pm @@ -101,6 +101,7 @@ use constant WS_ERROR_CODE => { comment_id_invalid => 111, comment_too_long => 114, comment_invalid_isprivate => 117, + markdown_disabled => 140, # Comment tagging comment_tag_disabled => 125, comment_tag_invalid => 126, diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl index 055bde3d4..55e1bc3f7 100644 --- a/template/en/default/global/user-error.html.tmpl +++ b/template/en/default/global/user-error.html.tmpl @@ -1186,6 +1186,9 @@ [%# Used for non-web-based LOGIN_REQUIRED situations. %] You must log in before using this part of [% terms.Bugzilla %]. + [% ELSIF error == "markdown_disabled" %] + Markdown feature is not enabled. + [% ELSIF error == "migrate_config_created" %] The file [% file FILTER html %] contains configuration variables that must be set before continuing with the migration. -- cgit v1.2.3-24-g4f1b