Commit 8a485723 authored by Stan Hu's avatar Stan Hu

Merge branch 'revert-prevent-groups-assign-quick-action' into 'master'

Revert prevent groups assign quick action

See merge request gitlab-org/gitlab!43809
parents 90187769 2bedf6c9
...@@ -35,7 +35,6 @@ export function membersBeforeSave(members) { ...@@ -35,7 +35,6 @@ export function membersBeforeSave(members) {
: ''; : '';
return { return {
type: member.type,
username: member.username, username: member.username,
avatarTag: autoCompleteAvatar.length === 1 ? txtAvatar : imgAvatar, avatarTag: autoCompleteAvatar.length === 1 ? txtAvatar : imgAvatar,
title: sanitize(title), title: sanitize(title),
...@@ -280,11 +279,7 @@ class GfmAutoComplete { ...@@ -280,11 +279,7 @@ class GfmAutoComplete {
if (command === MEMBER_COMMAND.ASSIGN) { if (command === MEMBER_COMMAND.ASSIGN) {
// Only include members which are not assigned to Issuable currently // Only include members which are not assigned to Issuable currently
return data.filter( return data.filter(member => !assignees.includes(member.search));
member => member.type === 'User' && !assignees.includes(member.search),
);
} else if (command === MEMBER_COMMAND.REASSIGN) {
return data.filter(member => member.type === 'User');
} else if (command === MEMBER_COMMAND.UNASSIGN) { } else if (command === MEMBER_COMMAND.UNASSIGN) {
// Only include members which are assigned to Issuable currently // Only include members which are assigned to Issuable currently
return data.filter(member => assignees.includes(member.search)); return data.filter(member => assignees.includes(member.search));
......
...@@ -66,12 +66,10 @@ const autoCompleteMap = { ...@@ -66,12 +66,10 @@ const autoCompleteMap = {
} }
if (doesCurrentLineStartWith('/assign', fullText, selectionStart)) { if (doesCurrentLineStartWith('/assign', fullText, selectionStart)) {
return this.members.filter( return this.members.filter(member => !this.assignees.includes(member.username));
member => member.type === 'User' && !this.assignees.includes(member.username), }
);
} else if (doesCurrentLineStartWith('/reassign', fullText, selectionStart)) { if (doesCurrentLineStartWith('/unassign', fullText, selectionStart)) {
return this.members.filter(member => member.type === 'User');
} else if (doesCurrentLineStartWith('/unassign', fullText, selectionStart)) {
return this.members.filter(member => this.assignees.includes(member.username)); return this.members.filter(member => this.assignees.includes(member.username));
} }
......
...@@ -69,7 +69,7 @@ module QuickActions ...@@ -69,7 +69,7 @@ module QuickActions
def extract_users(params) def extract_users(params)
return [] if params.nil? return [] if params.nil?
users = extract_references(params, :mentioned_user) users = extract_references(params, :user)
if users.empty? if users.empty?
users = users =
......
---
title: Prevent assignment of groups using quick actions
merge_request: 42810
author:
type: fixed
...@@ -3,49 +3,30 @@ ...@@ -3,49 +3,30 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'GFM autocomplete EE', :js do RSpec.describe 'GFM autocomplete EE', :js do
let_it_be(:user) { create(:user, name: '💃speciąl someone💃', username: 'someone.special') } let(:user) { create(:user, name: '💃speciąl someone💃', username: 'someone.special') }
let_it_be(:another_user) { create(:user, name: 'another user', username: 'another.user') } let(:another_user) { create(:user, name: 'another user', username: 'another.user') }
let_it_be(:project) { create(:project) } let(:project) { create(:project) }
let_it_be(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
let_it_be(:group) { create(:group) } before do
before_all do
project.add_maintainer(user) project.add_maintainer(user)
project.add_developer(another_user)
group.add_developer(user)
end end
context 'assignees' do context 'assignees' do
let(:issue_assignee) { create(:issue, project: project, assignees: [user]) } let(:issue_assignee) { create(:issue, project: project) }
describe 'when tribute_autocomplete feature flag is off' do describe 'when tribute_autocomplete feature flag is off' do
before do before do
stub_feature_flags(tribute_autocomplete: false) stub_feature_flags(tribute_autocomplete: false)
issue_assignee.update!(assignees: [user])
sign_in(user) sign_in(user)
visit project_issue_path(project, issue_assignee) visit project_issue_path(project, issue_assignee)
wait_for_requests wait_for_requests
end end
it 'excludes groups when using /reassign' do
note = find('#note-body')
page.within '.timeline-content-form' do
note.native.send_keys('/reas')
end
find('.atwho-view li', text: '/reassign')
note.native.send_keys(:tab)
wait_for_requests
expect(find('#at-view-users .atwho-view-ul')).not_to have_content(group.name)
expect(find('#at-view-users .atwho-view-ul')).to have_content(user.username)
expect(find('#at-view-users .atwho-view-ul')).to have_content(another_user.username)
end
it 'only lists users who are currently assigned to the issue when using /unassign' do it 'only lists users who are currently assigned to the issue when using /unassign' do
note = find('#note-body') note = find('#note-body')
page.within '.timeline-content-form' do page.within '.timeline-content-form' do
...@@ -67,29 +48,14 @@ RSpec.describe 'GFM autocomplete EE', :js do ...@@ -67,29 +48,14 @@ RSpec.describe 'GFM autocomplete EE', :js do
before do before do
stub_feature_flags(tribute_autocomplete: true) stub_feature_flags(tribute_autocomplete: true)
issue_assignee.update!(assignees: [user])
sign_in(user) sign_in(user)
visit project_issue_path(project, issue_assignee) visit project_issue_path(project, issue_assignee)
wait_for_requests wait_for_requests
end end
it 'excludes groups when using /reassign' do
note = find('#note-body')
page.within '.timeline-content-form' do
note.native.send_keys('/reas')
end
find('.atwho-view li', text: '/reassign')
note.native.send_keys(:tab)
note.native.send_keys(:right)
wait_for_requests
expect(find('.tribute-container ul', visible: true)).not_to have_content(group.name)
expect(find('.tribute-container ul', visible: true)).to have_content(user.username)
expect(find('.tribute-container ul', visible: true)).to have_content(another_user.username)
end
it 'only lists users who are currently assigned to the issue when using /unassign' do it 'only lists users who are currently assigned to the issue when using /unassign' do
note = find('#note-body') note = find('#note-body')
page.within '.timeline-content-form' do page.within '.timeline-content-form' do
......
...@@ -297,21 +297,18 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -297,21 +297,18 @@ RSpec.describe 'GFM autocomplete', :js do
end end
context 'assignees' do context 'assignees' do
let_it_be(:issue_assignee) { create(:issue, project: project, assignees: [user]) } let(:issue_assignee) { create(:issue, project: project) }
let_it_be(:unassigned_user) { create(:user) } let(:unassigned_user) { create(:user) }
let_it_be(:group) { create(:group) } before do
issue_assignee.update(assignees: [user])
before_all do
project.add_maintainer(unassigned_user) project.add_maintainer(unassigned_user)
group.add_developer(user)
end end
it 'lists users who are currently not assigned to the issue when using /assign' do it 'lists users who are currently not assigned to the issue when using /assign' do
visit project_issue_path(project, issue_assignee) visit project_issue_path(project, issue_assignee)
wait_for_requests
note = find('#note-body') note = find('#note-body')
page.within '.timeline-content-form' do page.within '.timeline-content-form' do
note.native.send_keys('/as') note.native.send_keys('/as')
...@@ -323,7 +320,6 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -323,7 +320,6 @@ RSpec.describe 'GFM autocomplete', :js do
wait_for_requests wait_for_requests
expect(find('#at-view-users .atwho-view-ul')).not_to have_content(user.username) expect(find('#at-view-users .atwho-view-ul')).not_to have_content(user.username)
expect(find('#at-view-users .atwho-view-ul')).not_to have_content(group.name)
expect(find('#at-view-users .atwho-view-ul')).to have_content(unassigned_user.username) expect(find('#at-view-users .atwho-view-ul')).to have_content(unassigned_user.username)
end end
...@@ -336,7 +332,6 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -336,7 +332,6 @@ RSpec.describe 'GFM autocomplete', :js do
textarea.native.send_keys(:tab) textarea.native.send_keys(:tab)
expect(find('#at-view-users .atwho-view-ul')).to have_content(unassigned_user.username) expect(find('#at-view-users .atwho-view-ul')).to have_content(unassigned_user.username)
expect(find('#at-view-users .atwho-view-ul')).not_to have_content(group.name)
expect(find('#at-view-users .atwho-view-ul')).to have_content(user.username) expect(find('#at-view-users .atwho-view-ul')).to have_content(user.username)
end end
end end
...@@ -669,21 +664,18 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -669,21 +664,18 @@ RSpec.describe 'GFM autocomplete', :js do
end end
context 'assignees' do context 'assignees' do
let_it_be(:issue_assignee) { create(:issue, project: project, assignees: [user]) } let(:issue_assignee) { create(:issue, project: project) }
let_it_be(:unassigned_user) { create(:user) } let(:unassigned_user) { create(:user) }
let_it_be(:group) { create(:group) } before do
issue_assignee.update(assignees: [user])
before_all do
project.add_maintainer(unassigned_user) project.add_maintainer(unassigned_user)
group.add_developer(user)
end end
it 'lists users who are currently not assigned to the issue when using /assign' do it 'lists users who are currently not assigned to the issue when using /assign' do
visit project_issue_path(project, issue_assignee) visit project_issue_path(project, issue_assignee)
wait_for_requests
note = find('#note-body') note = find('#note-body')
page.within '.timeline-content-form' do page.within '.timeline-content-form' do
note.native.send_keys('/as') note.native.send_keys('/as')
...@@ -696,15 +688,12 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -696,15 +688,12 @@ RSpec.describe 'GFM autocomplete', :js do
wait_for_requests wait_for_requests
expect(find('.tribute-container ul', visible: true)).not_to have_content(user.username) expect(find('.tribute-container ul', visible: true)).not_to have_content(user.username)
expect(find('.tribute-container ul', visible: true)).not_to have_content(group.name)
expect(find('.tribute-container ul', visible: true)).to have_content(unassigned_user.username) expect(find('.tribute-container ul', visible: true)).to have_content(unassigned_user.username)
end end
it 'lists users who are currently not assigned to the issue when using /assign on the second line' do it 'lists users who are currently not assigned to the issue when using /assign on the second line' do
visit project_issue_path(project, issue_assignee) visit project_issue_path(project, issue_assignee)
wait_for_requests
note = find('#note-body') note = find('#note-body')
page.within '.timeline-content-form' do page.within '.timeline-content-form' do
note.native.send_keys('/assign @user2') note.native.send_keys('/assign @user2')
......
...@@ -491,7 +491,6 @@ describe('GfmAutoComplete', () => { ...@@ -491,7 +491,6 @@ describe('GfmAutoComplete', () => {
it('should set the text avatar if avatar_url is null', () => { it('should set the text avatar if avatar_url is null', () => {
expect(membersBeforeSave([{ ...mockGroup, avatar_url: null }])).toEqual([ expect(membersBeforeSave([{ ...mockGroup, avatar_url: null }])).toEqual([
{ {
type: 'Group',
username: 'my-group', username: 'my-group',
avatarTag: '<div class="avatar rect-avatar center avatar-inline s26">M</div>', avatarTag: '<div class="avatar rect-avatar center avatar-inline s26">M</div>',
title: 'My Group (2)', title: 'My Group (2)',
...@@ -504,7 +503,6 @@ describe('GfmAutoComplete', () => { ...@@ -504,7 +503,6 @@ describe('GfmAutoComplete', () => {
it('should set the image avatar if avatar_url is given', () => { it('should set the image avatar if avatar_url is given', () => {
expect(membersBeforeSave([mockGroup])).toEqual([ expect(membersBeforeSave([mockGroup])).toEqual([
{ {
type: 'Group',
username: 'my-group', username: 'my-group',
avatarTag: avatarTag:
'<img src="./group.jpg" alt="my-group" class="avatar rect-avatar avatar-inline center s26"/>', '<img src="./group.jpg" alt="my-group" class="avatar rect-avatar avatar-inline center s26"/>',
...@@ -518,7 +516,6 @@ describe('GfmAutoComplete', () => { ...@@ -518,7 +516,6 @@ describe('GfmAutoComplete', () => {
it('should set mentions disabled icon if mentionsDisabled is set', () => { it('should set mentions disabled icon if mentionsDisabled is set', () => {
expect(membersBeforeSave([{ ...mockGroup, mentionsDisabled: true }])).toEqual([ expect(membersBeforeSave([{ ...mockGroup, mentionsDisabled: true }])).toEqual([
{ {
type: 'Group',
username: 'my-group', username: 'my-group',
avatarTag: avatarTag:
'<img src="./group.jpg" alt="my-group" class="avatar rect-avatar avatar-inline center s26"/>', '<img src="./group.jpg" alt="my-group" class="avatar rect-avatar avatar-inline center s26"/>',
...@@ -537,7 +534,6 @@ describe('GfmAutoComplete', () => { ...@@ -537,7 +534,6 @@ describe('GfmAutoComplete', () => {
]), ]),
).toEqual([ ).toEqual([
{ {
type: 'User',
username: 'my-user', username: 'my-user',
avatarTag: avatarTag:
'<img src="./users.jpg" alt="my-user" class="avatar avatar-inline center s26"/>', '<img src="./users.jpg" alt="my-user" class="avatar avatar-inline center s26"/>',
......
...@@ -834,19 +834,6 @@ RSpec.describe QuickActions::InterpretService do ...@@ -834,19 +834,6 @@ RSpec.describe QuickActions::InterpretService do
let(:issuable) { issue } let(:issuable) { issue }
end end
context 'assigning to a group' do
let_it_be(:group) { create(:group, :public) }
before_all do
group.add_developer(create(:user))
end
it_behaves_like 'empty command', "Failed to assign a user because no user was found." do
let(:content) { "/assign #{group.to_reference}" }
let(:issuable) { issue }
end
end
context 'unassign command' do context 'unassign command' do
let(:content) { '/unassign' } let(:content) { '/unassign' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment