Commit 02a2422e authored by Ruben Davila's avatar Ruben Davila

Add ability to reset estimated time through the `remove_estimation` command.

parent a45fa017
...@@ -275,6 +275,15 @@ module SlashCommands ...@@ -275,6 +275,15 @@ module SlashCommands
end end
end end
desc 'Remove the estimated time'
condition do
issuable.persisted? &&
current_user.can?(:"admin_#{issuable.to_ability_name}", project)
end
command :remove_estimation do
@updates[:time_estimate] = 0
end
def find_label_ids(labels_param) def find_label_ids(labels_param)
label_ids_by_reference = extract_references(labels_param, :label).map(&:id) label_ids_by_reference = extract_references(labels_param, :label).map(&:id)
labels_ids_by_name = LabelsFinder.new(current_user, project_id: project.id, name: labels_param.split).execute.select(:id) labels_ids_by_name = LabelsFinder.new(current_user, project_id: project.id, name: labels_param.split).execute.select(:id)
......
...@@ -126,7 +126,11 @@ module SystemNoteService ...@@ -126,7 +126,11 @@ module SystemNoteService
def change_time_estimate(noteable, project, author) def change_time_estimate(noteable, project, author)
parsed_time = ChronicDuration.output(noteable.time_estimate, format: :short) parsed_time = ChronicDuration.output(noteable.time_estimate, format: :short)
body = "Changed time estimate of this #{noteable.human_class_name} to #{parsed_time}" body = if parsed_time
"Changed time estimate of this #{noteable.human_class_name} to #{parsed_time}"
else
"Removed time estimate on this #{noteable.human_class_name}"
end
create_note(noteable: noteable, project: project, author: author, note: body) create_note(noteable: noteable, project: project, author: author, note: body)
end end
......
...@@ -30,4 +30,5 @@ do. ...@@ -30,4 +30,5 @@ do.
| `/remove_due_date` | Remove due date | | `/remove_due_date` | Remove due date |
| `/wip` | Toggle the Work In Progress status | | `/wip` | Toggle the Work In Progress status |
| <code>/estimate &lt;1w 3d 2h 14m&gt;</code> | Set time estimate | | <code>/estimate &lt;1w 3d 2h 14m&gt;</code> | Set time estimate |
| `/remove_estimation` | Remove estimated time |
| <code>/spend &lt;1h 30m &#124; -1h 5m&gt;</code> | Add or substract spent time | | <code>/spend &lt;1h 30m &#124; -1h 5m&gt;</code> | Add or substract spent time |
...@@ -226,6 +226,14 @@ describe SlashCommands::InterpretService, services: true do ...@@ -226,6 +226,14 @@ describe SlashCommands::InterpretService, services: true do
end end
end end
shared_examples 'remove_estimation command' do
it 'populates time_estimate: "0" if content contains /remove_estimation' do
_, updates = service.execute(content, issuable)
expect(updates).to eq(time_estimate: 0)
end
end
shared_examples 'empty command' do shared_examples 'empty command' do
it 'populates {} if content contains an unsupported command' do it 'populates {} if content contains an unsupported command' do
_, updates = service.execute(content, issuable) _, updates = service.execute(content, issuable)
...@@ -497,6 +505,11 @@ describe SlashCommands::InterpretService, services: true do ...@@ -497,6 +505,11 @@ describe SlashCommands::InterpretService, services: true do
let(:issuable) { issue } let(:issuable) { issue }
end end
it_behaves_like 'remove_estimation command' do
let(:content) { '/remove_estimation' }
let(:issuable) { issue }
end
context 'when current_user cannot :admin_issue' do context 'when current_user cannot :admin_issue' do
let(:visitor) { create(:user) } let(:visitor) { create(:user) }
let(:issue) { create(:issue, project: project, author: visitor) } let(:issue) { create(:issue, project: project, author: visitor) }
......
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