Class: RubyAem::Resources::User

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_aem/resources/user.rb

Overview

User class contains API calls related to managing an AEM user.

Instance Method Summary collapse

Constructor Details

#initialize(client, path, name) ⇒ Object

Initialise a user.

Parameters:

  • client

    RubyAem::Client

  • path

    the path to user node, e.g. /home/users/s/

  • name

    the username of the AEM user, e.g. someuser, admin, johncitizen



25
26
27
28
29
30
31
# File 'lib/ruby_aem/resources/user.rb', line 25

def initialize(client, path, name)
  @client = client
  @call_params = {
    path: path,
    name: name
  }
end

Instance Method Details

#add_to_group(group_path, group_name) ⇒ Object

Add user to a group.

Parameters:

  • group_path

    the path to group node, e.g. /home/groups/s/

  • group_name

    the name of the AEM group, e.g. somegroup

Returns:

  • RubyAem::Result



81
82
83
84
# File 'lib/ruby_aem/resources/user.rb', line 81

def add_to_group(group_path, group_name)
  group = RubyAem::Resources::Group.new(@client, group_path, group_name)
  group.add_member(@call_params[:name])
end

#change_password(old_password, new_password) ⇒ Object

Change the user’s password. This only works if the user whose password is to be changed, is also the same user that authenticates to AEM via SwaggerAemClient.

Parameters:

  • old_password

    the user’s old password to be changed from

  • new_password

    the user’s new password to be changed to

Returns:

  • RubyAem::Result



93
94
95
96
97
# File 'lib/ruby_aem/resources/user.rb', line 93

def change_password(old_password, new_password)
  @call_params[:old_password] = old_password
  @call_params[:new_password] = new_password
  @client.call(self.class, __callee__.to_s, @call_params)
end

#create(password) ⇒ Object

Create a new user.

Parameters:

  • password

    the password of the AEM user

Returns:

  • RubyAem::Result



37
38
39
40
41
# File 'lib/ruby_aem/resources/user.rb', line 37

def create(password)
  @call_params[:password] = password
  @call_params[:path] = "/#{@call_params[:path]}" unless @call_params[:path].start_with? '/'
  @client.call(self.class, __callee__.to_s, @call_params)
end

#deleteObject

Delete the user.

Returns:

  • RubyAem::Result



46
47
48
49
50
51
# File 'lib/ruby_aem/resources/user.rb', line 46

def delete
  result = find_authorizable_id
  @call_params[:authorizable_id] = result.data
  @call_params[:path] = RubyAem::Swagger.path(@call_params[:path])
  @client.call(self.class, __callee__.to_s, @call_params)
end

#existsObject

Check whether the user exists or not. If the user exists, this method returns a true result data, false otherwise.

Returns:

  • RubyAem::Result



58
59
60
61
62
63
# File 'lib/ruby_aem/resources/user.rb', line 58

def exists
  result = find_authorizable_id
  @call_params[:authorizable_id] = result.data
  @call_params[:path] = RubyAem::Swagger.path(@call_params[:path])
  @client.call(self.class, __callee__.to_s, @call_params)
end

#find_authorizable_idObject

Find the user’s authorizable ID. Return authorizable ID as result data, or nil if authorizable ID cannot be found.

Returns:

  • RubyAem::Result



104
105
106
107
# File 'lib/ruby_aem/resources/user.rb', line 104

def find_authorizable_id
  @call_params[:path] = "/#{@call_params[:path]}" unless @call_params[:path].start_with? '/'
  @client.call(self.class, __callee__.to_s, @call_params)
end

#set_permission(permission_path, permission_csv) ⇒ Object

Set the user’s permission.

Parameters:

  • permission_path

    the path that the user’s permission is to be set against, e.g. /etc/replication

  • permission_csv

    comma-separated-values of the user’s permission, e.g. read:true,modify:true

Returns:

  • RubyAem::Result



70
71
72
73
74
# File 'lib/ruby_aem/resources/user.rb', line 70

def set_permission(permission_path, permission_csv)
  @call_params[:permission_path] = permission_path
  @call_params[:permission_csv] = permission_csv
  @client.call(self.class, __callee__.to_s, @call_params)
end