Class: Actions::Katello::ContentView::Remove

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/katello/content_view/remove.rb

Instance Method Summary collapse

Instance Method Details

#activation_key_cve(options) ⇒ Object



117
118
119
120
121
# File 'app/lib/actions/katello/content_view/remove.rb', line 117

def activation_key_cve(options)
  ::Katello::ContentViewEnvironment.where(:environment_id => options[:key_environment_id],
                                          :content_view_id => options[:key_content_view_id]
                              ).first
end

#check_version_deletion(versions, cv_envs) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'app/lib/actions/katello/content_view/remove.rb', line 68

def check_version_deletion(versions, cv_envs)
  versions.each do |version|
    version.environments.each do |env|
      if cv_envs.none? { |cv_env| cv_env.content_view_version == version && cv_env.environment == env }
        fail _("Cannot delete version while it is in environment %s") % env.name
      end
    end
  end
end

#combined_cv_envs(cv_envs, versions) ⇒ Object



107
108
109
# File 'app/lib/actions/katello/content_view/remove.rb', line 107

def combined_cv_envs(cv_envs, versions)
  (cv_envs + versions.flat_map(&:content_view_environments)).uniq
end

#finalizeObject



82
83
84
85
86
87
88
89
90
# File 'app/lib/actions/katello/content_view/remove.rb', line 82

def finalize
  input[:content_view_history_ids].each do |history_id|
    history = ::Katello::ContentViewHistory.find_by(:id => history_id)
    if history
      history.status = ::Katello::ContentViewHistory::SUCCESSFUL
      history.save!
    end
  end
end

#humanized_nameObject



78
79
80
# File 'app/lib/actions/katello/content_view/remove.rb', line 78

def humanized_name
  _("Remove Versions and Associations")
end

#plan(content_view, options) ⇒ Object

Options: (note that all are optional) content_view_environments - content view environments to delete content_view_versions - view versions to delete system_content_view_id - content view to reassociate systems with system_environment_id - environment to reassociate systems with key_content_view_id - content view to reassociate actvation keys with key_environment_id - environment to reassociate activation keys with’ organization_destroy rubocop:disable MethodLength



16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
65
66
# File 'app/lib/actions/katello/content_view/remove.rb', line 16

def plan(content_view, options)
  cv_envs = options.fetch(:content_view_environments, [])
  versions = options.fetch(:content_view_versions, [])
  organization_destroy = options.fetch(:organization_destroy, false)
  skip_repo_destroy = options.fetch(:skip_repo_destroy, false)
  action_subject(content_view)
  validate_options(content_view, cv_envs, versions, options) unless organization_destroy

  all_cv_envs = combined_cv_envs(cv_envs, versions)
  check_version_deletion(versions, cv_envs)

  sequence do
    unless organization_destroy
      concurrence do
        all_cv_envs.each do |cv_env|
          if cv_env.systems.any? || cv_env.activation_keys.any?
            plan_action(ContentViewEnvironment::ReassignObjects, cv_env, options)
          end
        end
      end
    end

    cv_histories = []
    all_cv_envs.each do |cve|
      cv_histories << ::Katello::ContentViewHistory.create!(:content_view_version => cve.content_view_version,
                                                            :user => ::User.current.,
                                                            :environment => cve.environment,
                                                            :status => ::Katello::ContentViewHistory::IN_PROGRESS,
                                                            :task => self.task)
      plan_action(ContentViewEnvironment::Destroy,
                  cve,
                  :skip_repo_destroy => skip_repo_destroy,
                  :organization_destroy => organization_destroy)
    end

    versions.each do |version|
      ::Katello::ContentViewHistory.create!(:content_view_version => version,
                                            :user => ::User.current.,
                                            :status => ::Katello::ContentViewHistory::IN_PROGRESS, :task => self.task)
      plan_action(ContentViewVersion::Destroy, version,
                  :skip_environment_check => true,
                  :skip_destroy_env_content => true)
    end

    plan_self(content_view_id: content_view.id,
              environment_ids: cv_envs.map(&:environment_id),
              environment_names: cv_envs.map { |cve| cve.environment.name },
              version_ids: versions.map(&:id),
              content_view_history_ids: cv_histories.map { |history| history.id })
  end
end

#system_cve(options) ⇒ Object



111
112
113
114
115
# File 'app/lib/actions/katello/content_view/remove.rb', line 111

def system_cve(options)
  ::Katello::ContentViewEnvironment.where(:environment_id => options[:system_environment_id],
                                          :content_view_id => options[:system_content_view_id]
                              ).first
end

#validate_options(_content_view, cv_envs, versions, options) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/lib/actions/katello/content_view/remove.rb', line 92

def validate_options(_content_view, cv_envs, versions, options)
  if cv_envs.empty? && versions.empty?
    fail _("Either environments or versions must be specified.")
  end
  all_cv_envs = combined_cv_envs(cv_envs, versions)

  if all_cv_envs.flat_map(&:systems).any? && system_cve(options).nil?
    fail _("Unable to reassign systems. Please check system_content_view_id and system_environment_id.")
  end

  if all_cv_envs.flat_map(&:activation_keys).any? && activation_key_cve(options).nil?
    fail _("Unable to reassign activation_keys. Please check activation_key_content_view_id and activation_key_environment_id.")
  end
end