Welcome to mirror list, hosted at ThFree Co, Russian Federation.

users_helpers.rb « helpers « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f97071d9a9767145201ef8d01a6f0df4af33a9a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

module API
  module Helpers
    module UsersHelpers
      extend ActiveSupport::Concern
      extend Grape::API::Helpers

      params :optional_params_ee do
      end

      params :optional_index_params_ee do
      end

      def model_errors(model)
        super.tap do |errors|
          # Remapping errors from nested associations.
          next unless errors.has_key?(:"user_detail.bio")

          errors.delete(:"user_detail.bio").each do |message|
            errors.add(:bio, message)
          end
        end
      end

      # rubocop: disable CodeReuse/ActiveRecord
      def find_user_by_id(params)
        id = params[:user_id] || params[:id]
        User.find_by(id: id) || not_found!('User')
      end
      # rubocop: enable CodeReuse/ActiveRecord
    end
  end
end

API::Helpers::UsersHelpers.prepend_mod_with('API::Helpers::UsersHelpers')