Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
60bf5545
Commit
60bf5545
authored
Nov 05, 2017
by
Mehdi Lahmam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add /lock and /unlock quick actions
Closes #39173
parent
05100749
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
157 additions
and
0 deletions
+157
-0
app/services/quick_actions/interpret_service.rb
app/services/quick_actions/interpret_service.rb
+24
-0
changelogs/unreleased/lock-unlock-quick-actions.yml
changelogs/unreleased/lock-unlock-quick-actions.yml
+5
-0
doc/user/project/quick_actions.md
doc/user/project/quick_actions.md
+2
-0
spec/services/quick_actions/interpret_service_spec.rb
spec/services/quick_actions/interpret_service_spec.rb
+52
-0
spec/support/features/issuable_slash_commands_shared_examples.rb
...pport/features/issuable_slash_commands_shared_examples.rb
+74
-0
No files found.
app/services/quick_actions/interpret_service.rb
View file @
60bf5545
...
...
@@ -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'
...
...
changelogs/unreleased/lock-unlock-quick-actions.yml
0 → 100644
View file @
60bf5545
---
title
:
Add /lock and /unlock quick actions
merge_request
:
15197
author
:
Mehdi Lahmam (@mehlah)
type
:
added
doc/user/project/quick_actions.md
View file @
60bf5545
...
...
@@ -44,3 +44,5 @@ do.
|
`/shrug`
| Append the comment with
`¯\_(ツ)_/¯`
|
|
<code>
/copy_metadata #issue
|
!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 |
spec/services/quick_actions/interpret_service_spec.rb
View file @
60bf5545
...
...
@@ -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
...
...
spec/support/features/issuable_slash_commands_shared_examples.rb
View file @
60bf5545
...
...
@@ -285,6 +285,80 @@ 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
gitlab_sign_in
(
guest
)
visit
public_send
(
"namespace_project_
#{
issuable_type
}
_path"
,
project
.
namespace
,
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
gitlab_sign_in
(
guest
)
visit
public_send
(
"namespace_project_
#{
issuable_type
}
_path"
,
project
.
namespace
,
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment