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

Instance Method Summary collapse

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_objectsArray<Xolo::Server::Title>

A an array of all server titles as Title objects

Returns:



43
44
45
# File 'lib/xolo/server/helpers/titles.rb', line 43

def all_title_objects
  all_titles.map { |t| instantiate_title t }
end

#all_titlesArray<String>

A list of all known titles

Returns:

  • (Array<String>)


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

Parameters:

  • targets (Array<String>)

    a list of computers or usernames

  • users (Boolean)

    is the list usernames? if not, its computers

Returns:

  • (Array<String>)

    a list of computers to freeze or thaw



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/xolo/server/helpers/titles.rb', line 123

def expand_freeze_thaw_targets(targets:, users:)
  return targets unless users

  log_debug "Expanding user list to freeze or thaw: #{targets}"

  expanded_targets = []
  all_users = Jamf::User.all_names(cnx: jamf_cnx)
  targets.each do |user|
    next unless all_users.include? user

    expanded_targets += Jamf::User.fetch(name: user, cnx: jamf_cnx).computers.map { |c| c[:name] }
  end

  expanded_targets.uniq
end

#halt_on_existing_title(title) ⇒ void

This method returns an undefined value.

Halt 409 if a title already exists



97
98
99
100
101
102
103
# File 'lib/xolo/server/helpers/titles.rb', line 97

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



109
110
111
112
113
114
115
# File 'lib/xolo/server/helpers/titles.rb', line 109

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



85
86
87
88
89
90
91
# File 'lib/xolo/server/helpers/titles.rb', line 85

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)

Parameters:

  • data (Hash, String)

    hash to use with .new or name to use with .load

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/xolo/server/helpers/titles.rb', line 60

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'
      log_error msg

      halt 400, { status: 400, error: msg }
    end

  title.server_app_instance = self
  title
end