Module: API::Helpers::BadgesHelpers

Includes:
MembersHelpers
Defined in:
lib/api/helpers/badges_helpers.rb

Instance Method Summary collapse

Methods included from MembersHelpers

#authorize_admin_source!, #create_member, #find_all_members, #find_all_members_for_group, #find_all_members_for_project, #find_source, #present_members, #retrieve_members

Instance Method Details

#badge_source_params(source) ⇒ Object


25
26
27
28
29
30
31
32
33
# File 'lib/api/helpers/badges_helpers.rb', line 25

def badge_source_params(source)
  project = if source.is_a?(Project)
              source
            else
              GroupProjectsFinder.new(group: source, current_user: current_user).execute.first
            end

  { project: project }
end

#find_badge(source) ⇒ Object


8
9
10
11
12
13
14
15
16
# File 'lib/api/helpers/badges_helpers.rb', line 8

def find_badge(source)
  badge_id = params[:badge_id]

  if source.is_a?(Project)
    source.project_badges.find(badge_id)
  else
    source.badges.find(badge_id)
  end
end

#present_badges(source, records, options = {}) ⇒ Object


18
19
20
21
22
23
# File 'lib/api/helpers/badges_helpers.rb', line 18

def present_badges(source, records, options = {})
  entity_type = options[:with] || Entities::Badge
  badge_params = badge_source_params(source).merge(with: entity_type)

  present records, badge_params
end