diff options
Diffstat (limited to 'lib/api/helpers')
-rw-r--r-- | lib/api/helpers/discussions_helpers.rb | 9 | ||||
-rw-r--r-- | lib/api/helpers/issues_helpers.rb | 3 | ||||
-rw-r--r-- | lib/api/helpers/label_helpers.rb | 12 | ||||
-rw-r--r-- | lib/api/helpers/members_helpers.rb | 17 | ||||
-rw-r--r-- | lib/api/helpers/notes_helpers.rb | 10 | ||||
-rw-r--r-- | lib/api/helpers/packages/npm.rb | 62 | ||||
-rw-r--r-- | lib/api/helpers/resource_label_events_helpers.rb | 7 |
7 files changed, 105 insertions, 15 deletions
diff --git a/lib/api/helpers/discussions_helpers.rb b/lib/api/helpers/discussions_helpers.rb index 799d5582b38..3c0db1d0ea9 100644 --- a/lib/api/helpers/discussions_helpers.rb +++ b/lib/api/helpers/discussions_helpers.rb @@ -3,10 +3,15 @@ module API module Helpers module DiscussionsHelpers - def self.noteable_types + def self.feature_category_per_noteable_type # This is a method instead of a constant, allowing EE to more easily # extend it. - [Issue, Snippet, MergeRequest, Commit] + { + Issue => :issue_tracking, + Snippet => :snippets, + MergeRequest => :code_review, + Commit => :code_review + } end end end diff --git a/lib/api/helpers/issues_helpers.rb b/lib/api/helpers/issues_helpers.rb index 638b31cc7ba..b303f1f845d 100644 --- a/lib/api/helpers/issues_helpers.rb +++ b/lib/api/helpers/issues_helpers.rb @@ -5,6 +5,9 @@ module API module IssuesHelpers extend Grape::API::Helpers + params :negatable_issue_filter_params_ee do + end + params :optional_issue_params_ee do end diff --git a/lib/api/helpers/label_helpers.rb b/lib/api/helpers/label_helpers.rb index 2fb2d9b79cf..4018f2dec21 100644 --- a/lib/api/helpers/label_helpers.rb +++ b/lib/api/helpers/label_helpers.rb @@ -28,23 +28,23 @@ module API at_least_one_of :new_name, :color, :description end - def find_label(parent, id_or_title, include_ancestor_groups: true) - labels = available_labels_for(parent, include_ancestor_groups: include_ancestor_groups) + def find_label(parent, id_or_title, params = { include_ancestor_groups: true }) + labels = available_labels_for(parent, params) label = labels.find_by_id(id_or_title) || labels.find_by_title(id_or_title) label || not_found!('Label') end - def get_labels(parent, entity, include_ancestor_groups: true) - present paginate(available_labels_for(parent, include_ancestor_groups: include_ancestor_groups)), + def get_labels(parent, entity, params = {}) + present paginate(available_labels_for(parent, params)), with: entity, current_user: current_user, parent: parent, with_counts: params[:with_counts] end - def get_label(parent, entity, include_ancestor_groups: true) - label = find_label(parent, params_id_or_title, include_ancestor_groups: include_ancestor_groups) + def get_label(parent, entity, params = {}) + label = find_label(parent, params_id_or_title, params) present label, with: entity, current_user: current_user, parent: parent end diff --git a/lib/api/helpers/members_helpers.rb b/lib/api/helpers/members_helpers.rb index 5cc435e6801..431001c227d 100644 --- a/lib/api/helpers/members_helpers.rb +++ b/lib/api/helpers/members_helpers.rb @@ -20,12 +20,23 @@ module API # rubocop: disable CodeReuse/ActiveRecord def retrieve_members(source, params:, deep: false) - members = deep ? find_all_members(source) : source.members.where.not(user_id: nil) + members = deep ? find_all_members(source) : source_members(source).where.not(user_id: nil) members = members.includes(:user) members = members.references(:user).merge(User.search(params[:query])) if params[:query].present? members = members.where(user_id: params[:user_ids]) if params[:user_ids].present? members end + + def retrieve_member_invitations(source, query = nil) + members = source_members(source).where.not(invite_token: nil) + members = members.includes(:user) + members = members.where(invite_email: query) if query.present? + members + end + + def source_members(source) + source.members + end # rubocop: enable CodeReuse/ActiveRecord def find_all_members(source) @@ -48,6 +59,10 @@ module API def present_members(members) present members, with: Entities::Member, current_user: current_user, show_seat_info: params[:show_seat_info] end + + def present_member_invitations(invitations) + present invitations, with: Entities::Invitation, current_user: current_user + end end end end diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb index f61bcfe963e..6798c4d284b 100644 --- a/lib/api/helpers/notes_helpers.rb +++ b/lib/api/helpers/notes_helpers.rb @@ -5,10 +5,12 @@ module API module NotesHelpers include ::RendersNotes - def self.noteable_types - # This is a method instead of a constant, allowing EE to more easily - # extend it. - [Issue, MergeRequest, Snippet] + def self.feature_category_per_noteable_type + { + Issue => :issue_tracking, + MergeRequest => :code_review, + Snippet => :snippets + } end def update_note(noteable, note_id) diff --git a/lib/api/helpers/packages/npm.rb b/lib/api/helpers/packages/npm.rb new file mode 100644 index 00000000000..c1f6a001201 --- /dev/null +++ b/lib/api/helpers/packages/npm.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +module API + module Helpers + module Packages + module Npm + include Gitlab::Utils::StrongMemoize + include ::API::Helpers::PackagesHelpers + + NPM_ENDPOINT_REQUIREMENTS = { + package_name: API::NO_SLASH_URL_PART_REGEX + }.freeze + + def endpoint_scope + params[:id].present? ? :project : :instance + end + + def project + strong_memoize(:project) do + case endpoint_scope + when :project + user_project + when :instance + # Simulate the same behavior as #user_project by re-using #find_project! + # but take care if the project_id is nil as #find_project! is not designed + # to handle it. + project_id = project_id_or_nil + + not_found!('Project') unless project_id + + find_project!(project_id) + end + end + end + + def project_or_nil + # mainly used by the metadata endpoint where we need to get a project + # and return nil if not found (no errors should be raised) + strong_memoize(:project_or_nil) do + next unless project_id_or_nil + + find_project(project_id_or_nil) + end + end + + def project_id_or_nil + strong_memoize(:project_id_or_nil) do + case endpoint_scope + when :project + params[:id] + when :instance + ::Packages::Package.npm + .with_name(params[:package_name]) + .first + &.project_id + end + end + end + end + end + end +end diff --git a/lib/api/helpers/resource_label_events_helpers.rb b/lib/api/helpers/resource_label_events_helpers.rb index 423bd4e704b..ad2733baffc 100644 --- a/lib/api/helpers/resource_label_events_helpers.rb +++ b/lib/api/helpers/resource_label_events_helpers.rb @@ -3,10 +3,13 @@ module API module Helpers module ResourceLabelEventsHelpers - def self.eventable_types + def self.feature_category_per_eventable_type # This is a method instead of a constant, allowing EE to more easily # extend it. - [Issue, MergeRequest] + { + Issue => :issue_tracking, + MergeRequest => :code_review + } end end end |