Class: GoodData::LCM2::EnsureTechnicalUsersProject

Inherits:
BaseAction show all
Defined in:
lib/gooddata/lcm/actions/ensure_technical_users_project.rb

Constant Summary collapse

DESCRIPTION =
'Ensure Technical Users in Project'
PARAMS =
define_params(self) do
  description 'Client Used for Connecting to GD'
  param :gdc_gd_client, instance_of(Type::GdClientType), required: true
end
RESULT_HEADER =
[
  :project,
  :pid,
  :login,
  :role,
  :result,
  :message,
  :url
]

Constants included from Dsl::Dsl

Dsl::Dsl::DEFAULT_OPTS, Dsl::Dsl::TYPES

Class Method Summary collapse

Methods inherited from BaseAction

check_params

Methods included from Dsl::Dsl

#define_params, #define_type, #process

Class Method Details

.call(params) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gooddata/lcm/actions/ensure_technical_users_project.rb', line 30

def call(params)
  # Check if all required parameters were passed
  BaseAction.check_params(PARAMS, params)

  client = params.gdc_gd_client

  technical_users = params.technical_user || []
  new_users = technical_users.map do |technical_user|
    {
      login: technical_user,
      role: 'admin'
    }
  end

  results = params.synchronize.map do |synchronize_info|
    synchronize_info[:to].map do |entry|
      project = client.projects(entry[:pid])
      res = project.create_users(new_users)

      new_users.zip(res).map do |f, s|
        {
          project: project.title,
          pid: project.pid,
          login: f[:login],
          role: f[:role],
          result: s[:type],
          message: s[:message],
          url: s[:user]
        }
      end
    end
  end

  results.flatten
end