class Jamf::User

A User in the JSS.

@see Jamf::APIObject

Constants

EXT_ATTRIB_CLASS

This is the class for relevant Extension Attributes

OBJECT_HISTORY_OBJECT_TYPE

the object type for this object in the object history table. See {APIObject#add_object_history_entry}

RSRC_BASE

The base for REST resources of this class

RSRC_LIST_KEY

the hash key used for the JSON list output of all objects in the JSS

RSRC_OBJECT_KEY

The hash key used for the JSON object output. It’s also used in various error messages

SEARCH_CLASS

An AdvancedUserSearch in the JSS

@see Jamf::AdvancedSearch

@see Jamf::APIObject

Attributes

computers[R]

@return [Array<Hash>]

The computers associated with this user

Each Hash has then :id and :name for one computer

email[R]

@return [String] The user’s email address

full_name[R]

@return [String] The user’s full name

ldap_server[R]

@return [String] The name of the user’s LDAP server

ldap_sever_id[R]
mobile_devices[R]

@return [Array<Hash>]

The mobile devices associated with this user

Each Hash has then :id and :name for one device

@note This data is currently broken - the JSON output of the API only returns one mobile device, and it isn’t formatted in a standard way.

peripherals[R]

@return [Array<Hash>]

The peripherals associated with this user

Each Hash has then :id and :name for one peripheral

phone_number[R]

@return [String] The user’s phone number

position[R]

@return [String] The user’s position / job title

sites[R]

@return [Array<Hash>]

Unlike every other Sitable object, Users can be in multiple sites, so we don’t use the Sitable mixin module. Instead we’ll we’ll store them in this Array, as they come from the API.

Each Hash has the :id and :name for one site

total_vpp_code_count[R]

@return [Integer] the total number of vpp codes assigned to this user

vpp_assignments[R]

@return [Array<Hash>]

The user-based vpp assignments associated with this user

Each Hash has then :id and :name for one assignment

Public Class Methods

new(**args) click to toggle source

See Jamf::APIObject#initialize

Calls superclass method Jamf::APIObject::new
    # File lib/jamf/api/classic/api_objects/user.rb
163 def initialize(**args)
164   super
165 
166   @full_name = @init_data[:full_name]
167   @email = @init_data[:email]
168   @phone_number = @init_data[:phone_number]
169   @position = @init_data[:position]
170   @ldap_server = Jamf::APIObject.get_name @init_data[:ldap_server]
171   @ldap_server_id = @init_data[:ldap_server][:id] unless @init_data[:ldap_server].nil?
172   @sites = @init_data[:sites] ? @init_data[:sites]  : []
173 
174   if @init_data[:links]
175     @computers = @init_data[:links][:computers]
176     @peripherals = @init_data[:links][:peripherals]
177     @mobile_devices = @init_data[:links][:mobile_devices]
178     @vpp_assignments = @init_data[:links][:vpp_assignments]
179     @total_vpp_code_count = @init_data[:links][:total_vpp_code_count]
180   end
181 
182 end

Private Instance Methods

add_site(site) click to toggle source

Add this user to a site

@param site the name of the site

@return [void]

    # File lib/jamf/api/classic/api_objects/user.rb
232 def add_site (site)
233   return nil if @sites.map{|s| s[:name]}.include? site
234   raise Jamf::InvalidDataError, "No site in the JSS named #{site}" unless Jamf::Site.all_names(cnx: @cnx).include? site
235   @sites << {:name => site}
236   @need_to_update = true
237 end
email=(new_val) click to toggle source
    # File lib/jamf/api/classic/api_objects/user.rb
200 def email= (new_val)
201   @email = new_val
202   @need_to_update = true
203 end
full_name=(new_val) click to toggle source
    # File lib/jamf/api/classic/api_objects/user.rb
194 def full_name= (new_val)
195   @full_name = new_val
196   @need_to_update = true
197 end
ldap_server=(new_val) click to toggle source
    # File lib/jamf/api/classic/api_objects/user.rb
218 def ldap_server= (new_val)
219   raise Jamf::InvalidDataError, "No LDAP server in the JSS named #{new_val}" unless Jamf::LdapServer.all_names(cnx: @cnx).include? new_val
220   @ldap_server = new_val
221   @ldap_server_id = Jamf::LdapServer.valid_id @ldap_server
222   @need_to_update = true
223 end
phone_number=(new_val) click to toggle source
    # File lib/jamf/api/classic/api_objects/user.rb
206 def phone_number= (new_val)
207   @phone_number = new_val
208   @need_to_update = true
209 end
position=(new_val) click to toggle source
    # File lib/jamf/api/classic/api_objects/user.rb
212 def position= (new_val)
213   @position = new_val
214   @need_to_update = true
215 end
remove_site(site) click to toggle source

Remove this user from a site

@param site the name of the site

@return [void]

    # File lib/jamf/api/classic/api_objects/user.rb
246 def remove_site (site)
247   return nil unless @sites.map{|s| s[:name]}.include? site
248   @sites.reject!{|s| s[:name] == site}
249   @need_to_update = true
250 end
rest_xml() click to toggle source

Private Instance Methods

    # File lib/jamf/api/classic/api_objects/user.rb
299 def rest_xml
300   doc = REXML::Document.new Jamf::Connection::XML_HEADER
301   user = doc.add_element self.class::RSRC_OBJECT_KEY.to_s
302 
303   user.add_element('name').text = @name
304   user.add_element('full_name').text = @full_name
305   user.add_element('email').text = @email
306   user.add_element('phone_number').text = @phone_number
307   user.add_element('position').text = @position
308 
309   ldap = user.add_element('ldap_server')
310   ldap.add_element('id').text = @ldap_server_id
311 
312   user << Jamf::Site.xml_list(@sites)
313 
314   user << ext_attr_xml if unsaved_eas?
315 
316   return doc.to_s
317 end
user_groups(refresh = false) click to toggle source

Workaround for the recurring Jamf Classic API Bug where JSON is missing data that should come in an array of hashes, but only comes as a hash with a single hash inside, with data for only the last item in the XML array.

When needed, we fetch and parse the XML, which has the desired data. Use any truthy parameter to re-fetch the XML data, otherwise the data last fetched is used.

In this case, the user group data is fetched as XML and returned as an Array of Hashes, one per group the user is a member of. Each hash containing three Symbol keys:

id: Integer, the group id
name: String, the group name
is_smart: Boolean, is it a smart group or a static group?

@param refresh Re-fetch the group data from the API

@return [Array<Hash>] The groups the user is a member of.

    # File lib/jamf/api/classic/api_objects/user.rb
273 def user_groups(refresh = false)
274   @grp_array = nil if refresh
275   return @grp_array if @grp_array
276 
277   @grp_array = []
278   raw_xml = @cnx.c_get "/users/id/#{@id}", :xml
279   xmlroot = REXML::Document.new(raw_xml).root
280   xml_grps = xmlroot.elements['user_groups']
281 
282   xml_grps.each do |xml_grp|
283     next if xml_grp.name == 'size'
284 
285     gid = xml_grp.elements['id'].text.to_i
286     gname = xml_grp.elements['name'].text
287     smart = xml_grp.elements['is_smart'].text == 'true'
288     @grp_array << { id: gid, name: gname, is_smart: smart }
289   end # groups.each
290 
291   @grp_array
292 end