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:
authorJan Provaznik <jprovaznik@gitlab.com>2018-03-30 20:27:03 +0300
committerJan Provaznik <jprovaznik@gitlab.com>2018-04-05 14:29:57 +0300
commitc1946364707947f56048cc00caa6d67fe635f3c7 (patch)
tree107096b44758bf8872bd60d41ed1ab8ab4e86c14 /lib/banzai
parent166b4575a6353668c894fea0ba234d0b371dee03 (diff)
Better group support notes-related code
Updates notes-related services and rendering so this code can be easily used for group-scoped resources (specifically Epics). Related to gitlab-ee!5205
Diffstat (limited to 'lib/banzai')
-rw-r--r--lib/banzai/cross_project_reference.rb4
-rw-r--r--lib/banzai/filter/abstract_reference_filter.rb20
-rw-r--r--lib/banzai/filter/label_reference_filter.rb47
3 files changed, 51 insertions, 20 deletions
diff --git a/lib/banzai/cross_project_reference.rb b/lib/banzai/cross_project_reference.rb
index d8fb7705b2a..3f1e95d4cc0 100644
--- a/lib/banzai/cross_project_reference.rb
+++ b/lib/banzai/cross_project_reference.rb
@@ -4,7 +4,7 @@ module Banzai
module CrossProjectReference
# Given a cross-project reference string, get the Project record
#
- # Defaults to value of `context[:project]` if:
+ # Defaults to value of `context[:project]`, or `context[:group]` if:
# * No reference is given OR
# * Reference given doesn't exist
#
@@ -12,7 +12,7 @@ module Banzai
#
# Returns a Project, or nil if the reference can't be found
def parent_from_ref(ref)
- return context[:project] unless ref
+ return context[:project] || context[:group] unless ref
Project.find_by_full_path(ref)
end
diff --git a/lib/banzai/filter/abstract_reference_filter.rb b/lib/banzai/filter/abstract_reference_filter.rb
index c3a03f13306..6efaed7e624 100644
--- a/lib/banzai/filter/abstract_reference_filter.rb
+++ b/lib/banzai/filter/abstract_reference_filter.rb
@@ -196,13 +196,15 @@ module Banzai
end
end
- def data_attributes_for(text, project, object, link_content: false, link_reference: false)
+ def data_attributes_for(text, parent, object, link_content: false, link_reference: false)
+ object_parent_type = parent.is_a?(Group) ? :group : :project
+
data_attribute(
- original: text,
- link: link_content,
- link_reference: link_reference,
- project: project.id,
- object_sym => object.id
+ original: text,
+ link: link_content,
+ link_reference: link_reference,
+ object_parent_type => parent.id,
+ object_sym => object.id
)
end
@@ -337,6 +339,12 @@ module Banzai
def parent
parent_type == :project ? project : group
end
+
+ def full_group_path(group_ref)
+ return current_parent_path unless group_ref
+
+ group_ref
+ end
end
end
end
diff --git a/lib/banzai/filter/label_reference_filter.rb b/lib/banzai/filter/label_reference_filter.rb
index faa5b344e6f..1cbada818fb 100644
--- a/lib/banzai/filter/label_reference_filter.rb
+++ b/lib/banzai/filter/label_reference_filter.rb
@@ -32,16 +32,25 @@ module Banzai
end
end
- def find_label(project_ref, label_id, label_name)
- project = parent_from_ref(project_ref)
- return unless project
+ def find_label(parent_ref, label_id, label_name)
+ parent = parent_from_ref(parent_ref)
+ return unless parent
label_params = label_params(label_id, label_name)
- find_labels(project).find_by(label_params)
+ find_labels(parent).find_by(label_params)
end
- def find_labels(project)
- LabelsFinder.new(nil, project_id: project.id, include_ancestor_groups: true).execute(skip_authorization: true)
+ def find_labels(parent)
+ params = if parent.is_a?(Group)
+ { group_id: parent.id,
+ include_ancestor_groups: true,
+ only_group_labels: true }
+ else
+ { project_id: parent.id,
+ include_ancestor_groups: true }
+ end
+
+ LabelsFinder.new(nil, params).execute(skip_authorization: true)
end
# Parameters to pass to `Label.find_by` based on the given arguments
@@ -59,20 +68,34 @@ module Banzai
end
end
- def url_for_object(label, project)
+ def url_for_object(label, parent)
h = Gitlab::Routing.url_helpers
- h.project_issues_url(project, label_name: label.name, only_path: context[:only_path])
+
+ if parent.is_a?(Project)
+ h.project_issues_url(parent, label_name: label.name, only_path: context[:only_path])
+ elsif context[:label_url_method]
+ h.public_send(context[:label_url_method], parent, label_name: label.name, only_path: context[:only_path]) # rubocop:disable GitlabSecurity/PublicSend
+ end
end
def object_link_text(object, matches)
- project_path = full_project_path(matches[:namespace], matches[:project])
- project_from_ref = from_ref_cached(project_path)
- reference = project_from_ref.to_human_reference(project)
- label_suffix = " <i>in #{reference}</i>" if reference.present?
+ label_suffix = ''
+
+ if project || full_path_ref?(matches)
+ project_path = full_project_path(matches[:namespace], matches[:project])
+ parent_from_ref = from_ref_cached(project_path)
+ reference = parent_from_ref.to_human_reference(project || group)
+
+ label_suffix = " <i>in #{reference}</i>" if reference.present?
+ end
LabelsHelper.render_colored_label(object, label_suffix)
end
+ def full_path_ref?(matches)
+ matches[:namespace] && matches[:project]
+ end
+
def unescape_html_entities(text)
CGI.unescapeHTML(text.to_s)
end