Skip to content

Commit

Permalink
Handy banner method; allow for empty notice file
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Oct 3, 2024
1 parent 79a79ca commit d21a6cb
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/whimsy/asf/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,29 @@ def self.activeIP # intended for CLI testing
def self.notice
path = '/srv/whimsy/www/notice.txt'
if File.exist? path
File.open(path) do |fh|
return fh.readline.chomp, '/notice.txt'
begin
File.open(path) do |fh|
return fh.readline.chomp, '/notice.txt'
end
rescue EOFError
end
end
nil
end

# return message and href path suitable for page banner
# Returns: {text: message, href: link} where
# message and link are derived from updates_disallowed_reason,
# failing that, notice.txt
# If neither are set, returns nil
def self.banner
link = nil
msg = updates_disallowed_reason
return {msg: msg, href: nil} if msg
msg, link = notice
return {msg: msg, href: link} if msg
return nil
end
end

# for debugging purposes
Expand Down

0 comments on commit d21a6cb

Please sign in to comment.