Module: Xolo::Server::Helpers::Titles
- Defined in:
- lib/xolo/server/helpers/titles.rb
Overview
constants and methods for working with Xolo Titles on the server
Class Method Summary collapse
-
.included(includer) ⇒ Object
when this module is included.
Instance Method Summary collapse
-
#all_title_objects(refresh: false) ⇒ Array<Xolo::Server::Title>
A an array of all server titles as Title objects.
-
#all_titles ⇒ Array<String>
A list of all known titles.
-
#expand_freeze_thaw_targets(targets:, users:) ⇒ Array<String>
when freezing or thawing, are we dealing with a list of computers or a list of users, for whom we need to get all their assigned computers.
-
#halt_on_existing_title(title) ⇒ void
Halt 409 if a title already exists.
-
#halt_on_locked_title(title) ⇒ void
Halt 409 if a title is locked.
-
#halt_on_missing_title(title) ⇒ void
Halt 404 if a title doesn’t exist.
-
#instantiate_title(data) ⇒ Xolo::Server::Title
Instantiate a Server::Title with access to the Sinatra app instance,.
-
#managed_title_objects(refresh: false) ⇒ Array<Xolo::Server::Title>
A an array of server titles as Title objects, only for managed titles.
-
#subscribed_title_objects(refresh: false) ⇒ Array<Xolo::Server::Title>
A an array of server titles as Title objects, only for subscribed titles.
Class Method Details
.included(includer) ⇒ Object
when this module is included
25 26 27 |
# File 'lib/xolo/server/helpers/titles.rb', line 25 def self.included(includer) Xolo.verbose_include includer, self end |
Instance Method Details
#all_title_objects(refresh: false) ⇒ Array<Xolo::Server::Title>
A an array of all server titles as Title objects
43 44 45 46 47 48 49 50 51 |
# File 'lib/xolo/server/helpers/titles.rb', line 43 def all_title_objects(refresh: false) @all_title_objects = nil if refresh return @all_title_objects if @all_title_objects log_debug 'Instantiating all titles...' @all_title_objects = all_titles.map { |t| instantiate_title t } log_debug "Instantiated #{@all_title_objects.length} titles." @all_title_objects end |
#all_titles ⇒ Array<String>
A list of all known titles
36 37 38 |
# File 'lib/xolo/server/helpers/titles.rb', line 36 def all_titles Xolo::Server::Title.all_titles end |
#expand_freeze_thaw_targets(targets:, users:) ⇒ Array<String>
when freezing or thawing, are we dealing with a list of computers or a list of users, for whom we need to get all their assigned computers
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/xolo/server/helpers/titles.rb', line 147 def (targets:, users:) return targets unless users log_debug "Expanding user list to freeze or thaw: #{targets}" = [] all_users = Jamf::User.all_names(cnx: jamf_cnx) targets.each do |user| next unless all_users.include? user += Jamf::User.fetch(name: user, cnx: jamf_cnx).computers.map { |c| c[:name] } end .uniq end |
#halt_on_existing_title(title) ⇒ void
This method returns an undefined value.
Halt 409 if a title already exists
121 122 123 124 125 126 127 |
# File 'lib/xolo/server/helpers/titles.rb', line 121 def halt_on_existing_title(title) return unless all_titles.include? title msg = "Title '#{title}' already exists." log_debug "ERROR: #{msg}" halt 409, { status: 409, error: msg } end |
#halt_on_locked_title(title) ⇒ void
This method returns an undefined value.
Halt 409 if a title is locked
133 134 135 136 137 138 139 |
# File 'lib/xolo/server/helpers/titles.rb', line 133 def halt_on_locked_title(title) return unless Xolo::Server::Title.locked? title msg = "Title '#{title}' is being modified by another admin. Try again later." log_debug "ERROR: #{msg}" halt 409, { status: 409, error: msg } end |
#halt_on_missing_title(title) ⇒ void
This method returns an undefined value.
Halt 404 if a title doesn’t exist
109 110 111 112 113 114 115 |
# File 'lib/xolo/server/helpers/titles.rb', line 109 def halt_on_missing_title(title) return if all_titles.include? title msg = "Title '#{title}' does not exist." log_debug "ERROR: #{msg}" halt 404, { status: 404, error: msg } end |
#instantiate_title(data) ⇒ Xolo::Server::Title
Instantiate a Server::Title with access to the Sinatra app instance,
If given a string, use it with .load to read the title from disk
If given a Hash, use it with .new to instantiate fresh
In all cases, set the session, to use for logging (the reason this method exists)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/xolo/server/helpers/titles.rb', line 84 def instantiate_title(data) title = case data when Hash Xolo::Server::Title.new data when String halt_on_missing_title data Xolo::Server::Title.load data else msg = "Invalid data to instantiate a Xolo::Server::Title: #{data.class}:#{data} " log_error msg halt 400, { status: 400, error: msg } end title.server_app_instance = self title end |
#managed_title_objects(refresh: false) ⇒ Array<Xolo::Server::Title>
A an array of server titles as Title objects, only for managed titles
64 65 66 67 68 69 |
# File 'lib/xolo/server/helpers/titles.rb', line 64 def managed_title_objects(refresh: false) @managed_title_objects = nil if refresh return @managed_title_objects if @managed_title_objects @managed_title_objects = all_title_objects(refresh: refresh).select { |t| t.managed? } end |
#subscribed_title_objects(refresh: false) ⇒ Array<Xolo::Server::Title>
A an array of server titles as Title objects, only for subscribed titles
55 56 57 58 59 60 |
# File 'lib/xolo/server/helpers/titles.rb', line 55 def subscribed_title_objects(refresh: false) @subscribed_title_objects = nil if refresh return @subscribed_title_objects if @subscribed_title_objects @subscribed_title_objects = all_title_objects(refresh: refresh).select { |t| t.subscribed? } end |