class RubyAem::Resources::User

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

Public Class Methods

new(client, path, name) click to toggle source

Initialise a user.

@param client RubyAem::Client @param path the path to user node, e.g. /home/users/s/ @param name the username of the AEM user, e.g. someuser, admin, johncitizen @return new RubyAem::Resources::User instance

# File lib/ruby_aem/resources/user.rb, line 25
def initialize(client, path, name)
  @client = client
  @call_params = {
    path: path,
    name: name
  }
end

Public Instance Methods

add_to_group(group_path, group_name) click to toggle source

Add user to a group.

@param group_path the path to group node, e.g. /home/groups/s/ @param group_name the name of the AEM group, e.g. somegroup @return RubyAem::Result

# 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) click to toggle source

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.

@param old_password the user's old password to be changed from @param new_password the user's new password to be changed to @return RubyAem::Result

# 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) click to toggle source

Create a new user.

@param password the password of the AEM user @return RubyAem::Result

# 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
delete() click to toggle source

Delete the user.

@return RubyAem::Result

# 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
exists() click to toggle source

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

@return RubyAem::Result

# 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_id() click to toggle source

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

@return RubyAem::Result

# 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) click to toggle source

Set the user's permission.

@param permission_path the path that the user's permission is to be set against, e.g. /etc/replication @param permission_csv comma-separated-values of the user's permission, e.g. read:true,modify:true @return RubyAem::Result

# 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