Use parent instead of project
Add support for group entities to quick actions
This commit is contained in:
parent
0c1d6be13c
commit
c4d18b0584
4 changed files with 47 additions and 15 deletions
|
@ -456,6 +456,10 @@ class Note < ActiveRecord::Base
|
|||
Upload.find_by(model: self, path: paths)
|
||||
end
|
||||
|
||||
def parent
|
||||
project
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def keep_around_commit
|
||||
|
|
|
@ -31,7 +31,7 @@ module Notes
|
|||
return if command_params.empty?
|
||||
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
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
module QuickActions
|
||||
class InterpretService < BaseService
|
||||
include Gitlab::Utils::StrongMemoize
|
||||
include Gitlab::QuickActions::Dsl
|
||||
|
||||
attr_reader :issuable
|
||||
|
@ -210,15 +211,9 @@ module QuickActions
|
|||
end
|
||||
params '~label1 ~"label 2"'
|
||||
condition do
|
||||
if project
|
||||
available_labels = LabelsFinder
|
||||
.new(current_user, project_id: project.id, include_ancestor_groups: true)
|
||||
.execute
|
||||
end
|
||||
|
||||
project &&
|
||||
current_user.can?(:"admin_#{issuable.to_ability_name}", project) &&
|
||||
available_labels.any?
|
||||
parent &&
|
||||
current_user.can?(:"admin_#{issuable.to_ability_name}", parent) &&
|
||||
find_labels.any?
|
||||
end
|
||||
command :label do |labels_param|
|
||||
label_ids = find_label_ids(labels_param)
|
||||
|
@ -245,7 +240,7 @@ module QuickActions
|
|||
issuable.is_a?(Issuable) &&
|
||||
issuable.persisted? &&
|
||||
issuable.labels.any? &&
|
||||
current_user.can?(:"admin_#{issuable.to_ability_name}", project)
|
||||
current_user.can?(:"admin_#{issuable.to_ability_name}", parent)
|
||||
end
|
||||
command :unlabel do |labels_param = nil|
|
||||
if labels_param.present?
|
||||
|
@ -674,9 +669,25 @@ module QuickActions
|
|||
MilestonesFinder.new(params.merge(project_ids: [project.id], group_ids: [project.group&.id])).execute
|
||||
end
|
||||
|
||||
def find_labels(labels_param)
|
||||
extract_references(labels_param, :label) |
|
||||
LabelsFinder.new(current_user, project_id: project.id, name: labels_param.split, include_ancestor_groups: true).execute
|
||||
def parent
|
||||
project || group
|
||||
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
|
||||
|
||||
def find_label_references(labels_param)
|
||||
|
@ -707,9 +718,11 @@ module QuickActions
|
|||
|
||||
# rubocop: disable CodeReuse/ActiveRecord
|
||||
def extract_references(arg, type)
|
||||
return [] unless arg
|
||||
|
||||
ext = Gitlab::ReferenceExtractor.new(project, current_user)
|
||||
|
||||
ext.analyze(arg, author: current_user)
|
||||
ext.analyze(arg, author: current_user, group: group)
|
||||
|
||||
ext.references(type)
|
||||
end
|
||||
|
|
|
@ -890,4 +890,19 @@ describe Note do
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue