Class: JSS::User

Inherits:
APIObject show all
Includes:
Creatable, Extendable, Updatable
Defined in:
lib/jss/api_object/user.rb,
lib/jss.rb

Overview

A User in the JSS.

See Also:

Constant Summary collapse

RSRC_BASE =

The base for REST resources of this class

"users"
RSRC_LIST_KEY =

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

:users
RSRC_OBJECT_KEY =

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

:user
VALID_DATA_KEYS =

these keys, as well as :id and :name, are present in valid API JSON data for this class

[:position, :full_name, :email]
SEARCH_CLASS =

This class lets us seach for users

JSS::AdvancedUserSearch
EXT_ATTRIB_CLASS =

This is the class for relevant Extension Attributes

JSS::UserExtensionAttribute
OBJECT_HISTORY_OBJECT_TYPE =

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

53

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ User

See JSS::APIObject#initialize



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/jss/api_object/user.rb', line 166

def initialize (args = {})
  super

  @full_name = @init_data[:full_name]
  @email = @init_data[:email]
  @phone_number = @init_data[:phone_number]
  @position = @init_data[:position]
  @ldap_server = JSS::APIObject.get_name @init_data[:ldap_server]
  @sites = @init_data[:sites] ? @init_data[:sites]  : []

  if @init_data[:links]
    @computers = @init_data[:links][:computers]
    @peripherals = @init_data[:links][:peripherals]
    @mobile_devices = @init_data[:links][:mobile_devices]
    @vpp_assignments = @init_data[:links][:vpp_assignments]
    @total_vpp_code_count = @init_data[:links][:total_vpp_code_count]
  end

end

Instance Attribute Details

#computersArray<Hash> (readonly)

The computers associated with this user

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

Returns:



126
127
128
# File 'lib/jss/api_object/user.rb', line 126

def computers
  @computers
end

#emailString

Returns The user's email address

Returns:

  • (String)

    The user's email address



95
96
97
# File 'lib/jss/api_object/user.rb', line 95

def email
  @email
end

#ext_attrsHash (readonly) Originally defined in module Extendable

Returns A mapping of Ext Attrib names to their values

Returns:

  • (Hash)

    A mapping of Ext Attrib names to their values

#extension_attributesArray<Hash> (readonly) Originally defined in module Extendable

Returns The extension attribute values for the object

Returns:

  • (Array<Hash>)

    The extension attribute values for the object

#full_nameString

Returns The user's full name

Returns:

  • (String)

    The user's full name



92
93
94
# File 'lib/jss/api_object/user.rb', line 92

def full_name
  @full_name
end

#ldap_serverString

Returns The name of the user's LDAP server

Returns:

  • (String)

    The name of the user's LDAP server



104
105
106
# File 'lib/jss/api_object/user.rb', line 104

def ldap_server
  @ldap_server
end

#mobile_devicesArray<Hash> (readonly)

Note:

This data is currently broken - the JSON output of the API only

The mobile devices associated with this user

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

returns one mobile device, and it isn't formatted in a standard way.

Returns:



146
147
148
# File 'lib/jss/api_object/user.rb', line 146

def mobile_devices
  @mobile_devices
end

#need_to_updateBoolean (readonly) Originally defined in module Updatable

Returns do we have unsaved changes?

Returns:

  • (Boolean)

    do we have unsaved changes?

#peripheralsArray<Hash> (readonly)

The peripherals associated with this user

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

Returns:



135
136
137
# File 'lib/jss/api_object/user.rb', line 135

def peripherals
  @peripherals
end

#phone_numberString

Returns The user's phone number

Returns:

  • (String)

    The user's phone number



98
99
100
# File 'lib/jss/api_object/user.rb', line 98

def phone_number
  @phone_number
end

#positionString

Returns The user's position / job title

Returns:

  • (String)

    The user's position / job title



101
102
103
# File 'lib/jss/api_object/user.rb', line 101

def position
  @position
end

#sitesArray<Hash> (readonly)

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

Returns:



117
118
119
# File 'lib/jss/api_object/user.rb', line 117

def sites
  @sites
end

#total_vpp_code_countInteger (readonly)

Returns the total number of vpp codes assigned to this user

Returns:

  • (Integer)

    the total number of vpp codes assigned to this user



157
158
159
# File 'lib/jss/api_object/user.rb', line 157

def total_vpp_code_count
  @total_vpp_code_count
end

#vpp_assignmentsArray<Hash> (readonly)

The vpp assignments associated with this user

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

Returns:



154
155
156
# File 'lib/jss/api_object/user.rb', line 154

def vpp_assignments
  @vpp_assignments
end

Instance Method Details

#add_site(site) ⇒ void

This method returns an undefined value.

Add this user to a site

Parameters:

  • site (String)

    the name of the site

Raises:



233
234
235
236
237
238
# File 'lib/jss/api_object/user.rb', line 233

def add_site (site)
  return nil if @sites.map{|s| s[:name]}.include? site
  raise JSS::InvalidDataError, "No site in the JSS named #{site}" unless JSS::Site.all_names(api: @api).include? site
  @sites << {:name => site}
  @need_to_update = true
end

#clone(new_name, api: nil) ⇒ APIObject Originally defined in module Creatable

make a clone of this API object, with a new name. The class must be creatable

Parameters:

  • name (String)

    the name for the new object

  • api (JSS::APIConnection)

    the API in which to create the object Defaults to the API used to instantiate this object

Returns:

  • (APIObject)

    An uncreated clone of this APIObject with the given name

Raises:

#create(api: nil) ⇒ Integer Originally defined in module Creatable

Create a new object in the JSS.

Parameters:

  • api (JSS::APIConnection)

    the API in which to create the object Defaults to the API used to instantiate this object

Returns:

  • (Integer)

    the jss ID of the newly created object

Raises:

#ext_attr_xmlREXML::Element Originally defined in module Extendable

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: make this (and all XML amending) method take the in-progress XML doc and add (or not) the EA xml to it. See how Sitable#add_site_to_xml works, as called from Computer.rest_xml

Returns:

  • (REXML::Element)

    An <extension_attribute> element to be included in the rest_xml of objects that mix-in this module.

#name=(newname) ⇒ void Originally defined in module Updatable

This method returns an undefined value.

Change the name of this item Remember to #update to push changes to the server.

Parameters:

  • newname (String)

    the new name

Raises:

#parse_ext_attrsvoid Originally defined in module Extendable

This method returns an undefined value.

Populate @extension_attributes (the Array of Hashes that comes from the API) and @ext_attr_names, which is a Hash mapping the EA names to their values. This is called during initialization for all objects that mix in this module

#remove_site(site) ⇒ void

This method returns an undefined value.

Remove this user from a site

Parameters:

  • site (String)

    the name of the site



247
248
249
250
251
# File 'lib/jss/api_object/user.rb', line 247

def remove_site (site)
  return nil unless @sites.map{|s| s[:name]}.include? site
  @sites.reject!{|s| s[:name] == site}
  @need_to_update = true
end

#set_ext_attr(name, value) ⇒ void Originally defined in module Extendable

This method returns an undefined value.

Set the value of an extension attribute

If the extension attribute is defined as a popup menu, the value must be one of the defined popup choices, or an empty string

If the ext. attrib. is defined with a data type of Integer, the value must be an Integer.

If the ext. attrib. is defined with a data type of Date, the value will be converted to a Time

Note that while the Jamf Pro Web interface does not allow editing the values of Extension Attributes populated by Scripts or LDAP, the API does allow it. Bear in mind however that those values will be reset again at the next recon.

Parameters:

  • name (String)

    the name of the extension attribute to set

  • value (String, Time, Time, Integer)

    the new value for the extension attribute for this user

#unsaved_eas?Boolean Originally defined in module Extendable

are there any changes in the EAs needing to be saved?

Returns:

  • (Boolean)

#updateBoolean Originally defined in module Updatable

Save changes to the JSS

Returns:

  • (Boolean)

    success

Raises: