@@ -12,9 +12,20 @@ class Models::UserSettings < Models::JsonSlice
1212 attribute :config_validation , Boolean , default : lambda { |us , _ | us . config_validation? }
1313 attribute :share_encrypted_env_with_forks , Boolean , default : false
1414 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
1524
1625 attr_reader :repo
1726
27+ attr_accessor :user , :change_source
28+
1829 def initialize ( repo , data )
1930 @repo = repo
2031 super ( data )
@@ -57,5 +68,24 @@ def cutoff_date
5768 def days_since_jan_15
5869 Date . today . mjd - JAN_15 . mjd + 1
5970 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
6090 end
6191end
0 commit comments