Commit d3a100ab authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'ce-7407-label-quick-epics' into 'master'

CE port: Use parent instead of project for quick actions

See merge request gitlab-org/gitlab-ce!24124
parents 329725c2 c4d18b05
...@@ -456,6 +456,10 @@ class Note < ActiveRecord::Base ...@@ -456,6 +456,10 @@ class Note < ActiveRecord::Base
Upload.find_by(model: self, path: paths) Upload.find_by(model: self, path: paths)
end end
def parent
project
end
private private
def keep_around_commit def keep_around_commit
......
...@@ -31,7 +31,7 @@ module Notes ...@@ -31,7 +31,7 @@ module Notes
return if command_params.empty? return if command_params.empty?
return unless supported?(note) return unless supported?(note)
self.class.noteable_update_service(note).new(project, current_user, command_params).execute(note.noteable) self.class.noteable_update_service(note).new(note.parent, current_user, command_params).execute(note.noteable)
end end
end end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
module QuickActions module QuickActions
class InterpretService < BaseService class InterpretService < BaseService
include Gitlab::Utils::StrongMemoize
include Gitlab::QuickActions::Dsl include Gitlab::QuickActions::Dsl
attr_reader :issuable attr_reader :issuable
...@@ -210,15 +211,9 @@ module QuickActions ...@@ -210,15 +211,9 @@ module QuickActions
end end
params '~label1 ~"label 2"' params '~label1 ~"label 2"'
condition do condition do
if project parent &&
available_labels = LabelsFinder current_user.can?(:"admin_#{issuable.to_ability_name}", parent) &&
.new(current_user, project_id: project.id, include_ancestor_groups: true) find_labels.any?
.execute
end
project &&
current_user.can?(:"admin_#{issuable.to_ability_name}", project) &&
available_labels.any?
end end
command :label do |labels_param| command :label do |labels_param|
label_ids = find_label_ids(labels_param) label_ids = find_label_ids(labels_param)
...@@ -245,7 +240,7 @@ module QuickActions ...@@ -245,7 +240,7 @@ module QuickActions
issuable.is_a?(Issuable) && issuable.is_a?(Issuable) &&
issuable.persisted? && issuable.persisted? &&
issuable.labels.any? && issuable.labels.any? &&
current_user.can?(:"admin_#{issuable.to_ability_name}", project) current_user.can?(:"admin_#{issuable.to_ability_name}", parent)
end end
command :unlabel do |labels_param = nil| command :unlabel do |labels_param = nil|
if labels_param.present? if labels_param.present?
...@@ -674,9 +669,25 @@ module QuickActions ...@@ -674,9 +669,25 @@ module QuickActions
MilestonesFinder.new(params.merge(project_ids: [project.id], group_ids: [project.group&.id])).execute MilestonesFinder.new(params.merge(project_ids: [project.id], group_ids: [project.group&.id])).execute
end end
def find_labels(labels_param) def parent
extract_references(labels_param, :label) | project || group
LabelsFinder.new(current_user, project_id: project.id, name: labels_param.split, include_ancestor_groups: true).execute end
def group
strong_memoize(:group) do
issuable.group if issuable.respond_to?(:group)
end
end
def find_labels(labels_params = nil)
finder_params = { include_ancestor_groups: true }
finder_params[:project_id] = project.id if project
finder_params[:group_id] = group.id if group
finder_params[:name] = labels_params.split if labels_params
result = LabelsFinder.new(current_user, finder_params).execute
extract_references(labels_params, :label) | result
end end
def find_label_references(labels_param) def find_label_references(labels_param)
...@@ -707,9 +718,11 @@ module QuickActions ...@@ -707,9 +718,11 @@ module QuickActions
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def extract_references(arg, type) def extract_references(arg, type)
return [] unless arg
ext = Gitlab::ReferenceExtractor.new(project, current_user) ext = Gitlab::ReferenceExtractor.new(project, current_user)
ext.analyze(arg, author: current_user) ext.analyze(arg, author: current_user, group: group)
ext.references(type) ext.references(type)
end end
......
...@@ -890,4 +890,19 @@ describe Note do ...@@ -890,4 +890,19 @@ describe Note do
end end
end end
end end
describe '#parent' do
it 'returns project for project notes' do
project = create(:project)
note = create(:note_on_issue, project: project)
expect(note.parent).to eq(project)
end
it 'returns nil for personal snippet note' do
note = create(:note_on_personal_snippet)
expect(note.parent).to be_nil
end
end
end end
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