Class: JSS::Account

Inherits:
APIObject show all
Defined in:
lib/jss.rb,
lib/jss/api_object/account.rb

Overview

A User or group in the JSS.

TODO: Split this into 2 classes, with lots of custom code. Thanks Jamf!

See Also:

Constant Summary collapse

RSRC_BASE =

The base for REST resources of this class

'accounts'.freeze
RSRC_LIST_KEY =

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

:accounts
RSRC_OBJECT_KEY =

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

:account
OTHER_LOOKUP_KEYS =

these keys, as well as :id and :name, can be used to look up objects of this class in the JSS

{
  userid: { fetch_rsrc_key: :userid },
  username: { fetch_rsrc_key: :username },
  groupid: { fetch_rsrc_key: :groupid },
  groupname: { fetch_rsrc_key: :groupname }
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Account

See JSS::APIObject#initialize



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/jss/api_object/account.rb', line 154

def initialize(args = {})
  super args

  # check to see if a user has been specified, haven't built groups yet
  is_user = [:userid, :username].any? { |key| args.keys.include? key }

  return unless is_user
  @user_name = @init_data[:name]
  @full_name = @init_data[:full_name]
  @email = @init_data[:email]
  @access_level = @init_data[:access_level]
  @privilege_set = @init_data[:privilege_set]
  @privileges = @init_data[:privileges]

end

Instance Attribute Details

#access_levelString (readonly)

Returns The user's access level.

Returns:

  • (String)

    The user's access level



128
129
130
# File 'lib/jss/api_object/account.rb', line 128

def access_level
  @access_level
end

#emailString (readonly)

Returns The user's email address.

Returns:

  • (String)

    The user's email address



125
126
127
# File 'lib/jss/api_object/account.rb', line 125

def email
  @email
end

#full_nameString (readonly)

Returns The user's full name.

Returns:

  • (String)

    The user's full name



122
123
124
# File 'lib/jss/api_object/account.rb', line 122

def full_name
  @full_name
end

#privilege_setString (readonly)

Returns The user's privilege set.

Returns:

  • (String)

    The user's privilege set



131
132
133
# File 'lib/jss/api_object/account.rb', line 131

def privilege_set
  @privilege_set
end

#privilegesHash (readonly)

Info about the privileges assigned to the user

Note: these arrays may be empty, they always exist

The Hash keys are:

  • :jss_objects => An array of jss_object privileges

  • :jss_settings => An array of jss_settings privileges

  • :jss_actions => An array of jss_actions privileges

  • :recon => An array of Casper Recon privileges

  • :casper_admin => An array of Casper Admin privileges

  • :casper_remote => An array of Casper Remote privileges

  • :casper_imaging => An array of Casper Imaging privileges

Returns:



147
148
149
# File 'lib/jss/api_object/account.rb', line 147

def privileges
  @privileges
end

Class Method Details

.all_group_ids(refresh = false, api: JSS.api) ⇒ Array<Hash>

Returns all JSS account group ids.

Returns:

  • (Array<Hash>)

    all JSS account group ids



109
110
111
# File 'lib/jss/api_object/account.rb', line 109

def self.all_group_ids(refresh = false, api: JSS.api)
  all(refresh, api: api)[:groups].map { |i| i[:id] }
end

.all_group_names(refresh = false, api: JSS.api) ⇒ Array<Hash>

Returns all JSS account group names.

Returns:

  • (Array<Hash>)

    all JSS account group names



114
115
116
# File 'lib/jss/api_object/account.rb', line 114

def self.all_group_names(refresh = false, api: JSS.api)
  all(refresh, api: api)[:groups].map { |i| i[:name] }
end

.all_groups(refresh = false, api: JSS.api) ⇒ Array<Hash>

Returns all JSS account groups.

Returns:



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

def self.all_groups(refresh = false, api: JSS.api)
  all(refresh, api: api)[:groups]
end

.all_ids(_refresh = false, **_bunk) ⇒ Object

override auto-defined method



79
80
81
# File 'lib/jss/api_object/account.rb', line 79

def self.all_ids(_refresh = false, **_bunk)
  raise '.all_ids is not valid for JSS::Account, use .all_user_ids or .all_group_ids'
end

.all_names(_refresh = false, **_bunk) ⇒ Object

override auto-defined method



84
85
86
# File 'lib/jss/api_object/account.rb', line 84

def self.all_names(_refresh = false, **_bunk)
  raise '.all_names is not valid for JSS::Account, use .all_user_names or .all_group_names'
end

.all_user_ids(refresh = false, api: JSS.api) ⇒ Array<Hash>

Returns all JSS account user ids.

Returns:



94
95
96
# File 'lib/jss/api_object/account.rb', line 94

def self.all_user_ids(refresh = false, api: JSS.api)
  all(refresh, api: api)[:users].map { |i| i[:id] }
end

.all_user_names(refresh = false, api: JSS.api) ⇒ Array<Hash>

Returns all JSS account user names.

Returns:

  • (Array<Hash>)

    all JSS account user names



99
100
101
# File 'lib/jss/api_object/account.rb', line 99

def self.all_user_names(refresh = false, api: JSS.api)
  all(refresh, api: api)[:users].map { |i| i[:name] }
end

.all_users(refresh = false, api: JSS.api) ⇒ Array<Hash>

Returns all JSS account users.

Returns:



89
90
91
# File 'lib/jss/api_object/account.rb', line 89

def self.all_users(refresh = false, api: JSS.api)
  all(refresh, api: api)[:users]
end