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



28
29
30
31
32
33
34
# File 'lib/ruby_aem/resources/user.rb', line 28

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



86
87
88
89
# File 'lib/ruby_aem/resources/user.rb', line 86

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.

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



96
97
98
99
100
# File 'lib/ruby_aem/resources/user.rb', line 96

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



40
41
42
43
44
45
46
# File 'lib/ruby_aem/resources/user.rb', line 40

def create(password)
  @call_params[:password] = password
  if !@call_params[:path].match(/^\//)
    @call_params[:path] = "/#{@call_params[:path]}"
  end
  @client.call(self.class, __callee__.to_s, @call_params)
end

#deleteObject

Delete the user.

Returns:

  • RubyAem::Result



51
52
53
54
55
56
# File 'lib/ruby_aem/resources/user.rb', line 51

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



63
64
65
66
67
68
# File 'lib/ruby_aem/resources/user.rb', line 63

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



107
108
109
# File 'lib/ruby_aem/resources/user.rb', line 107

def find_authorizable_id()
  @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



75
76
77
78
79
# File 'lib/ruby_aem/resources/user.rb', line 75

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