@@ -12,9 +12,20 @@ class Models::UserSettings < Models::JsonSlice
12
12
attribute :config_validation , Boolean , default : lambda { |us , _ | us . config_validation? }
13
13
attribute :share_encrypted_env_with_forks , Boolean , default : false
14
14
attribute :share_ssh_keys_with_forks , Boolean , default : lambda { |us , _ | us . share_ssh_keys_with_forks? }
15
+ attribute :job_log_time_based_limit , Boolean , default : lambda { |s , _ | s . job_log_access_permissions [ :time_based_limit ] }
16
+ attribute :job_log_access_based_limit , Boolean , default : lambda { |s , _ | s . job_log_access_permissions [ :access_based_limit ] }
17
+ attribute :job_log_access_older_than_days , Integer , default : lambda { |s , _ | s . job_log_access_permissions [ :older_than_days ] }
18
+
19
+ validates :job_log_access_older_than_days , numericality : true
20
+
21
+ validate :job_log_access_older_than_days_restriction
22
+
23
+ set_callback :after_save , :after , :save_audit
15
24
16
25
attr_reader :repo
17
26
27
+ attr_accessor :user , :change_source
28
+
18
29
def initialize ( repo , data )
19
30
@repo = repo
20
31
super ( data )
@@ -57,5 +68,24 @@ def cutoff_date
57
68
def days_since_jan_15
58
69
Date . today . mjd - JAN_15 . mjd + 1
59
70
end
71
+
72
+ def job_log_access_permissions
73
+ Travis . config . to_h . fetch ( :job_log_access_permissions ) { { } }
74
+ end
75
+
76
+ def job_log_access_older_than_days_restriction
77
+ if job_log_access_older_than_days . to_i > job_log_access_permissions [ :max_days_value ] ||
78
+ job_log_access_older_than_days . to_i < job_log_access_permissions [ :min_days_value ]
79
+ errors . add ( :job_log_access_older_than_days , "is outside the bounds" )
80
+ end
81
+ end
82
+
83
+ private
84
+
85
+ def save_audit
86
+ if self . change_source
87
+ Travis ::API ::V3 ::Models ::Audit . create! ( owner : self . user , change_source : self . change_source , source : self . repo , source_changes : { settings : self . changes } )
88
+ end
89
+ end
60
90
end
61
91
end
0 commit comments