Repository navigation
Bug 2079840 - allow @username in the textarea like github #2776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dklawren
wants to merge
4
commits into
mozilla:master
Choose a base branch
from
dklawren:2079840
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a62bcad
feat: Bug 2079840 - Support GitHub-style @nickname mentions to needin…
dklawren d8b9968
feat: Bug 2079840 - Add misuse safeguards to @nickname mentions
dklawren 57c588d
fix: Bug 2079840 - Never let @mentions block a comment from saving
dklawren fae49e4
Potential fix for pull request finding 'Capture full fence length to …
dklawren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| #!/usr/bin/env perl | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| # | ||
| # This Source Code Form is "Incompatible With Secondary Licenses", as | ||
| # defined by the Mozilla Public License, v. 2.0. | ||
| use strict; | ||
| use warnings; | ||
| use lib qw( . lib local/lib/perl5 ); | ||
|
|
||
| BEGIN { | ||
| $ENV{LOG4PERL_CONFIG_FILE} = 'log4perl-t.conf'; | ||
| $ENV{BUGZILLA_DISABLE_HOSTAGE} = 1; | ||
| } | ||
|
|
||
| use Bugzilla::Test::MockDB; | ||
| use Bugzilla::Test::MockParams; | ||
|
|
||
| use Test2::V0; | ||
|
|
||
| use Bugzilla; | ||
| BEGIN { Bugzilla->extensions } | ||
|
|
||
| my $extract = \&Bugzilla::Extension::Needinfo::_extract_mentions; | ||
|
|
||
| is([$extract->(undef)], [], 'undef text'); | ||
| is([$extract->('no mentions here')], [], 'no mentions'); | ||
| is([$extract->('@alice can you look?')], ['alice'], 'leading mention'); | ||
| is([$extract->('thanks @alice, @bob and @carol.')], | ||
| ['alice', 'bob', 'carol'], 'multiple mentions with punctuation'); | ||
| is([$extract->('@alice and @Alice again @alice')], ['alice'], | ||
| 'duplicates collapsed case-insensitively'); | ||
| is([$extract->('(@dk.l_x-y)')], ['dk.l_x-y'], 'nick symbols, parens'); | ||
| is([$extract->('mail [email protected] or a/@b or x.@y')], [], | ||
| 'emails and embedded @ ignored'); | ||
| is([$extract->("> \@quoted said\n\@alice")], ['alice'], 'quoted lines ignored'); | ||
| is([$extract->('run `@decorator` @alice')], ['alice'], 'inline code ignored'); | ||
| is([$extract->('``@alice`` and `` a`@b ``')], [], 'double backtick code ignored'); | ||
| is([$extract->("it's a ` stray\n\n\@alice `x`")], | ||
| ['alice'], 'unclosed backtick does not span paragraphs'); | ||
| is([$extract->('@foo|bar and |@alice|')], ['foo|bar', 'alice'], | ||
| 'pipe allowed in nick, trailing pipe stripped'); | ||
| is( | ||
| [$extract->("```perl\n\@inside\n```\n\@after")], | ||
| ['after'], 'fenced code block ignored' | ||
| ); | ||
| is([$extract->("~~~\n\@unclosed\n\@more")], [], 'unclosed fence runs to end'); | ||
|
|
||
| # _process_mentions safeguards, using minimal stand-ins for users and bugs. | ||
| { | ||
|
|
||
| package FakeUser; | ||
| sub new { my ($class, %args) = @_; bless {%args}, $class } | ||
| sub id { $_[0]{id} } | ||
| sub nick { $_[0]{nick} } | ||
| sub login { "$_[0]{nick}\@example.com" } | ||
| sub in_group { $_[0]{editbugs} } | ||
| sub is_insider { $_[0]{insider} } | ||
| sub can_see_bug { $_[0]{sees_bug} // 1 } | ||
| sub needinfo_blocked { 0 } | ||
|
|
||
| package FakeBug; | ||
| sub new { | ||
| my ($class, $text, %type) = @_; | ||
| bless { | ||
| added_comments => [{thetext => $text}], | ||
| cc => [], | ||
| needinfo => [], | ||
| type => bless({flags => [], multiplicable => 1, %type}, 'FakeType'), | ||
| }, $class; | ||
| } | ||
| sub id {1} | ||
| sub product_id {1} | ||
| sub flag_types { [$_[0]{type}] } | ||
| sub check_can_change_field { {allowed => 1} } | ||
| sub add_cc { | ||
| my ($self, $user) = @_; | ||
| die "add_cc failed\n" if $user->{cc_fails}; | ||
| push @{$self->{cc}}, $user->nick; | ||
| } | ||
|
|
||
| # Like Bugzilla::Flag->set_flag, new flags are added to the type's list. | ||
| sub set_flags { | ||
| my ($self, undef, $new_flags) = @_; | ||
| foreach my $flag (@$new_flags) { | ||
| push @{$self->{needinfo}}, $flag->{requestee}; | ||
| push @{$self->{type}{flags}}, | ||
| bless({status => '?', requestee_id => 0}, 'FakeFlag'); | ||
| } | ||
| } | ||
|
|
||
| package FakeType; | ||
| sub name {'needinfo'} | ||
| sub id {1} | ||
| sub is_multiplicable { $_[0]{multiplicable} } | ||
|
|
||
| package FakeFlag; | ||
| sub status { $_[0]{status} } | ||
| sub requestee_id { $_[0]{requestee_id} } | ||
| } | ||
|
|
||
| my %users = map { $_->nick => $_ } ( | ||
| FakeUser->new(id => 2, nick => 'alice'), | ||
| FakeUser->new(id => 3, nick => 'bob'), | ||
| FakeUser->new(id => 4, nick => 'hidden', sees_bug => 0), | ||
| FakeUser->new(id => 6, nick => 'boom', cc_fails => 1), | ||
| map { FakeUser->new(id => 10 + $_, nick => "u$_") } 1 .. 12, | ||
| ); | ||
| my $commenter = FakeUser->new(id => 1, nick => 'me', editbugs => 1); | ||
| my @looked_up; | ||
|
|
||
| my $mock_bugzilla = mock 'Bugzilla' => (override => [user => sub {$commenter}]); | ||
| my $mock_ext = mock 'Bugzilla::Extension::Needinfo' => ( | ||
| override => [ | ||
| _users_for_mentions => sub { | ||
| @looked_up = @_; | ||
| return grep {defined} map { $users{$_} } @_; | ||
| }, | ||
| ], | ||
| ); | ||
|
|
||
| my $process = \&Bugzilla::Extension::Needinfo::_process_mentions; | ||
|
|
||
| my $bug = FakeBug->new('@alice and @bob please look, cc @me'); | ||
| $process->($bug); | ||
| is($bug->{cc}, ['alice', 'bob'], 'mentioned users CCd, self skipped'); | ||
| is($bug->{needinfo}, ['[email protected]', '[email protected]'], | ||
| 'mentioned users needinfod'); | ||
|
|
||
| $bug = FakeBug->new('@hidden @alice'); | ||
| $process->($bug); | ||
| is($bug->{cc}, ['alice'], 'user who cannot see the bug is not CCd'); | ||
| is($bug->{needinfo}, ['[email protected]'], '... nor needinfod'); | ||
|
|
||
| $bug = FakeBug->new(join ' ', map {"\@u$_"} 1 .. 12); | ||
| $process->($bug); | ||
| is(\@looked_up, [map {"u$_"} 1 .. 10], 'only the first 10 nicknames are looked up'); | ||
| is($bug->{cc}, [map {"u$_"} 1 .. 10], '... and only they are CCd'); | ||
|
|
||
| $bug = FakeBug->new('@alice @bob', multiplicable => 0); | ||
| $process->($bug); | ||
| is($bug->{cc}, ['alice', 'bob'], 'non-multiplicable type: everyone CCd'); | ||
| is($bug->{needinfo}, ['[email protected]'], '... but only one needinfo'); | ||
|
|
||
| $bug = FakeBug->new('@alice', multiplicable => 0); | ||
| push @{$bug->{type}{flags}}, bless({status => '?', requestee_id => 9}, 'FakeFlag'); | ||
| $process->($bug); | ||
| is($bug->{cc}, ['alice'], 'non-multiplicable with existing flag: CCd'); | ||
| is($bug->{needinfo}, [], '... and no needinfo, instead of an error'); | ||
|
|
||
| $bug = FakeBug->new('@alice'); | ||
| push @{$bug->{type}{flags}}, bless({status => '?', requestee_id => 2}, 'FakeFlag'); | ||
| $process->($bug); | ||
| is($bug->{needinfo}, [], 'no duplicate needinfo for a pending request'); | ||
|
|
||
| $bug = FakeBug->new('@boom @alice'); | ||
| ok(lives { $process->($bug) }, | ||
| 'a failing CC (e.g. strict_isolation) does not throw'); | ||
| is($bug->{cc}, ['alice'], '... that user is skipped'); | ||
| is($bug->{needinfo}, ['[email protected]'], '... others still processed'); | ||
|
|
||
| $commenter->{editbugs} = 0; | ||
| @looked_up = (); | ||
| $bug = FakeBug->new('@alice'); | ||
| $process->($bug); | ||
| is(\@looked_up, [], 'no lookup for commenters without editbugs'); | ||
| is($bug->{cc}, [], 'no CC for commenters without editbugs'); | ||
| is($bug->{needinfo}, [], 'no needinfo for commenters without editbugs'); | ||
|
|
||
| done_testing; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.