Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2018-09-10 15:24:46 +0300
committerRémy Coutable <remy@rymai.me>2018-09-10 15:24:46 +0300
commit4a5f4c657d3389affbbe17f2cc8e38365d1d51b2 (patch)
treede72df08a00789d6063755fca499bda928a933c6
parentd3ff9e9c6745839c2b26404a7e2c79a6ac8036b8 (diff)
parente39962b019dcdf675875e7cf7d62d375345b7c03 (diff)
Merge branch 'lock-unlock-quick-actions' into 'master'
Add /lock and /unlock quick actions Closes #39173 See merge request gitlab-org/gitlab-ce!15197
-rw-r--r--app/services/quick_actions/interpret_service.rb24
-rw-r--r--changelogs/unreleased/lock-unlock-quick-actions.yml5
-rw-r--r--doc/user/project/quick_actions.md2
-rw-r--r--spec/features/commits/user_uses_quick_actions_spec.rb (renamed from spec/features/commits/user_uses_slash_commands_spec.rb)0
-rw-r--r--spec/features/issues/user_uses_quick_actions_spec.rb (renamed from spec/features/issues/user_uses_slash_commands_spec.rb)0
-rw-r--r--spec/features/merge_request/user_uses_quick_actions_spec.rb (renamed from spec/features/merge_request/user_uses_slash_commands_spec.rb)0
-rw-r--r--spec/services/quick_actions/interpret_service_spec.rb52
-rw-r--r--spec/support/features/issuable_quick_actions_shared_examples.rb (renamed from spec/support/features/issuable_slash_commands_shared_examples.rb)84
8 files changed, 162 insertions, 5 deletions
diff --git a/app/services/quick_actions/interpret_service.rb b/app/services/quick_actions/interpret_service.rb
index a4c4c9e4812..be9d1e48435 100644
--- a/app/services/quick_actions/interpret_service.rb
+++ b/app/services/quick_actions/interpret_service.rb
@@ -489,6 +489,30 @@ module QuickActions
"#{comment} #{TABLEFLIP}"
end
+ desc "Lock the discussion"
+ explanation "Locks the discussion"
+ condition do
+ issuable.is_a?(Issuable) &&
+ issuable.persisted? &&
+ !issuable.discussion_locked? &&
+ current_user.can?(:"admin_#{issuable.to_ability_name}", issuable)
+ end
+ command :lock do
+ @updates[:discussion_locked] = true
+ end
+
+ desc "Unlock the discussion"
+ explanation "Unlocks the discussion"
+ condition do
+ issuable.is_a?(Issuable) &&
+ issuable.persisted? &&
+ issuable.discussion_locked? &&
+ current_user.can?(:"admin_#{issuable.to_ability_name}", issuable)
+ end
+ command :unlock do
+ @updates[:discussion_locked] = false
+ end
+
# This is a dummy command, so that it appears in the autocomplete commands
desc 'CC'
params '@user'
diff --git a/changelogs/unreleased/lock-unlock-quick-actions.yml b/changelogs/unreleased/lock-unlock-quick-actions.yml
new file mode 100644
index 00000000000..9322d60ba52
--- /dev/null
+++ b/changelogs/unreleased/lock-unlock-quick-actions.yml
@@ -0,0 +1,5 @@
+---
+title: Add /lock and /unlock quick actions
+merge_request: 15197
+author: Mehdi Lahmam (@mehlah)
+type: added
diff --git a/doc/user/project/quick_actions.md b/doc/user/project/quick_actions.md
index 8fdfd2a6f4d..9ad9155258f 100644
--- a/doc/user/project/quick_actions.md
+++ b/doc/user/project/quick_actions.md
@@ -44,3 +44,5 @@ do.
| `/shrug` | Append the comment with `¯\_(ツ)_/¯` |
| <code>/copy_metadata #issue &#124; !merge_request</code> | Copy labels and milestone from other issue or merge request |
| `/confidential` | Makes the issue confidential |
+| `/lock` | Lock the discussion |
+| `/unlock` | Unlock the discussion |
diff --git a/spec/features/commits/user_uses_slash_commands_spec.rb b/spec/features/commits/user_uses_quick_actions_spec.rb
index 9a4b7bd2444..9a4b7bd2444 100644
--- a/spec/features/commits/user_uses_slash_commands_spec.rb
+++ b/spec/features/commits/user_uses_quick_actions_spec.rb
diff --git a/spec/features/issues/user_uses_slash_commands_spec.rb b/spec/features/issues/user_uses_quick_actions_spec.rb
index 5926e442f24..5926e442f24 100644
--- a/spec/features/issues/user_uses_slash_commands_spec.rb
+++ b/spec/features/issues/user_uses_quick_actions_spec.rb
diff --git a/spec/features/merge_request/user_uses_slash_commands_spec.rb b/spec/features/merge_request/user_uses_quick_actions_spec.rb
index b81478a481f..b81478a481f 100644
--- a/spec/features/merge_request/user_uses_slash_commands_spec.rb
+++ b/spec/features/merge_request/user_uses_quick_actions_spec.rb
diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb
index bf1c157c4a2..06cad9c00d2 100644
--- a/spec/services/quick_actions/interpret_service_spec.rb
+++ b/spec/services/quick_actions/interpret_service_spec.rb
@@ -272,6 +272,28 @@ describe QuickActions::InterpretService do
end
end
+ shared_examples 'lock command' do
+ let(:issue) { create(:issue, project: project, discussion_locked: false) }
+ let(:merge_request) { create(:merge_request, source_project: project, discussion_locked: false) }
+
+ it 'returns discussion_locked: true if content contains /lock' do
+ _, updates = service.execute(content, issuable)
+
+ expect(updates).to eq(discussion_locked: true)
+ end
+ end
+
+ shared_examples 'unlock command' do
+ let(:issue) { create(:issue, project: project, discussion_locked: true) }
+ let(:merge_request) { create(:merge_request, source_project: project, discussion_locked: true) }
+
+ it 'returns discussion_locked: true if content contains /unlock' do
+ _, updates = service.execute(content, issuable)
+
+ expect(updates).to eq(discussion_locked: false)
+ end
+ end
+
shared_examples 'empty command' do
it 'populates {} if content contains an unsupported command' do
_, updates = service.execute(content, issuable)
@@ -786,6 +808,26 @@ describe QuickActions::InterpretService do
let(:issuable) { issue }
end
+ it_behaves_like 'lock command' do
+ let(:content) { '/lock' }
+ let(:issuable) { issue }
+ end
+
+ it_behaves_like 'lock command' do
+ let(:content) { '/lock' }
+ let(:issuable) { merge_request }
+ end
+
+ it_behaves_like 'unlock command' do
+ let(:content) { '/unlock' }
+ let(:issuable) { issue }
+ end
+
+ it_behaves_like 'unlock command' do
+ let(:content) { '/unlock' }
+ let(:issuable) { merge_request }
+ end
+
context '/todo' do
let(:content) { '/todo' }
@@ -961,6 +1003,16 @@ describe QuickActions::InterpretService do
let(:content) { '/duplicate #{issue.to_reference}' }
let(:issuable) { issue }
end
+
+ it_behaves_like 'empty command' do
+ let(:content) { '/lock' }
+ let(:issuable) { issue }
+ end
+
+ it_behaves_like 'empty command' do
+ let(:content) { '/unlock' }
+ let(:issuable) { issue }
+ end
end
context '/award command' do
diff --git a/spec/support/features/issuable_slash_commands_shared_examples.rb b/spec/support/features/issuable_quick_actions_shared_examples.rb
index 9b44c532ff6..846e697eb96 100644
--- a/spec/support/features/issuable_slash_commands_shared_examples.rb
+++ b/spec/support/features/issuable_quick_actions_shared_examples.rb
@@ -55,7 +55,7 @@ shared_examples 'issuable record that supports quick actions in its description
describe "note on #{issuable_type}", :js do
before do
- visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
+ visit public_send("project_#{issuable_type}_path", project, issuable)
end
context 'with a note containing commands' do
@@ -121,7 +121,7 @@ shared_examples 'issuable record that supports quick actions in its description
gitlab_sign_out
gitlab_sign_in(guest)
- visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
+ visit public_send("project_#{issuable_type}_path", project, issuable)
end
it "does not close the #{issuable_type}" do
@@ -158,7 +158,7 @@ shared_examples 'issuable record that supports quick actions in its description
gitlab_sign_out
gitlab_sign_in(guest)
- visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
+ visit public_send("project_#{issuable_type}_path", project, issuable)
end
it "does not reopen the #{issuable_type}" do
@@ -190,7 +190,7 @@ shared_examples 'issuable record that supports quick actions in its description
gitlab_sign_out
gitlab_sign_in(guest)
- visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
+ visit public_send("project_#{issuable_type}_path", project, issuable)
end
it "does not change the #{issuable_type} title" do
@@ -285,13 +285,87 @@ shared_examples 'issuable record that supports quick actions in its description
expect(issuable.reload.assignees).to eq [maintainer]
end
end
+
+ context "with a note locking the #{issuable_type} discussion" do
+ before do
+ issuable.update(discussion_locked: false)
+ expect(issuable).not_to be_discussion_locked
+ end
+
+ context "when current user can lock #{issuable_type} discussion" do
+ it "locks the #{issuable_type} discussion" do
+ add_note("/lock")
+
+ expect(page).not_to have_content '/lock'
+ expect(page).to have_content 'Commands applied'
+
+ expect(issuable.reload).to be_discussion_locked
+ end
+ end
+
+ context "when current user cannot lock #{issuable_type}" do
+ before do
+ guest = create(:user)
+ project.add_guest(guest)
+
+ gitlab_sign_out
+ sign_in(guest)
+ visit public_send("project_#{issuable_type}_path", project, issuable)
+ end
+
+ it "does not lock the #{issuable_type} discussion" do
+ add_note("/lock")
+
+ expect(page).not_to have_content 'Commands applied'
+
+ expect(issuable).not_to be_discussion_locked
+ end
+ end
+ end
+
+ context "with a note unlocking the #{issuable_type} discussion" do
+ before do
+ issuable.update(discussion_locked: true)
+ expect(issuable).to be_discussion_locked
+ end
+
+ context "when current user can unlock #{issuable_type} discussion" do
+ it "unlocks the #{issuable_type} discussion" do
+ add_note("/unlock")
+
+ expect(page).not_to have_content '/unlock'
+ expect(page).to have_content 'Commands applied'
+
+ expect(issuable.reload).not_to be_discussion_locked
+ end
+ end
+
+ context "when current user cannot unlock #{issuable_type}" do
+ before do
+ guest = create(:user)
+ project.add_guest(guest)
+
+ gitlab_sign_out
+ sign_in(guest)
+ visit public_send("project_#{issuable_type}_path", project, issuable)
+ end
+
+ it "does not unlock the #{issuable_type} discussion" do
+ add_note("/unlock")
+
+ expect(page).not_to have_content 'Commands applied'
+
+ expect(issuable).to be_discussion_locked
+ end
+ end
+ end
end
describe "preview of note on #{issuable_type}", :js do
it 'removes quick actions from note and explains them' do
create(:user, username: 'bob')
- visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
+ visit public_send("project_#{issuable_type}_path", project, issuable)
page.within('.js-main-target-form') do
fill_in 'note[note]', with: "Awesome!\n/assign @bob "