Repository navigation
Expand file tree
/
Copy pathcontent_view_history.rb
More file actions
84 lines (69 loc) · 2.86 KB
/
Copy pathcontent_view_history.rb
File metadata and controls
84 lines (69 loc) · 2.86 KB
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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
module Katello
class ContentViewHistory < Katello::Model
include Katello::Authorization::ContentViewHistory
belongs_to :environment, :class_name => "Katello::KTEnvironment", :inverse_of => :content_view_histories,
:foreign_key => :katello_environment_id
belongs_to :content_view_version, :class_name => "Katello::ContentViewVersion", :foreign_key => :katello_content_view_version_id, :inverse_of => :history
belongs_to :triggered_by, :class_name => "Katello::ContentViewVersion", :inverse_of => :triggered_histories
belongs_to :task, :class_name => "ForemanTasks::Task::DynflowTask"
IN_PROGRESS = 'in progress'.freeze
FAILED = 'failed'.freeze
SUCCESSFUL = 'successful'.freeze
STATUSES = [IN_PROGRESS, FAILED, SUCCESSFUL].freeze
validates_lengths_from_database
validates :status, :inclusion => {:in => STATUSES,
:allow_blank => false}
validates :action, presence: true
scope :active, -> { where(:status => IN_PROGRESS) }
scope :successful, -> { where(:status => SUCCESSFUL) }
alias_method :version, :content_view_version
alias_attribute :description, :notes
scoped_search :on => :id, :relation => :content_view_version, :rename => :content_view_version_id
scoped_search :on => :name, :relation => :environment, :rename => :environment, :complete_value => true
enum action: {
publish: 1,
promotion: 2,
removal: 3,
export: 4,
importing: 5,
}
def content_view
self.content_view_version.try(:content_view)
end
def self.in_organization(organization)
content_views = ContentView.where(:organization_id => organization.id)
self.joins(:content_view_version => :content_view).
where("#{ContentView.table_name}.id" => content_views).
order("#{self.table_name}.updated_at DESC")
end
def self.in_organizations(organizations)
content_views = ContentView.where(:organization_id => organizations)
self.joins(:content_view_version => :content_view).
where("#{ContentView.table_name}.id" => content_views).
order("#{self.table_name}.updated_at DESC")
end
def humanized_action
if export?
_("Exported version")
elsif publish?
_("Published new version")
elsif promotion?
_("Promoted to %{environment}") % { :environment => self.environment.try(:name) || _('Unknown') }
elsif removal?
_("Deleted from %{environment}") % { :environment => self.environment.try(:name) || _('Unknown')}
else
_("Unknown Action")
end
end
def humanized_status
case self.status
when ContentViewHistory::IN_PROGRESS
_("In Progress")
when ContentViewHistory::FAILED
_("Failed")
when ContentViewHistory::SUCCESSFUL
_("Success")
end
end
end
end