class Confluence::User

Public Class Methods

find_all() click to toggle source
# File lib/confluence/user.rb, line 95
def self.find_all
  # FIXME: this is really slow... we should probably just look in the confluence database instead
  usernames = find_all_usernames
  usernames.collect{|u| find_by_username(u)}
end
find_all_usernames() click to toggle source
# File lib/confluence/user.rb, line 101
def self.find_all_usernames
  confluence.getActiveUsers(true)
end
find_by_email(email) click to toggle source
# File lib/confluence/user.rb, line 85
def self.find_by_email(email)
  usernames = confluence.getActiveUsers(true)
  usernames.each do |username|
    user = find_by_username(username)
    return user if user.email == email
  end
  
  return nil
end
find_by_name(username) click to toggle source

DEPRECATED: this method is confusing since it could be taken as meaning “find by first/last name”

# File lib/confluence/user.rb, line 81
def self.find_by_name(username)
  find_by_username(username)
end
find_by_username(username) click to toggle source

class methods #########################################################

# File lib/confluence/user.rb, line 76
def self.find_by_username(username)
  find(username)
end

Public Instance Methods

add_to_group(group) click to toggle source
# File lib/confluence/user.rb, line 44
def add_to_group(group)
  @groups = nil # reset cached group list
  confluence.addUserToGroup(username, group)
end
groups() click to toggle source
# File lib/confluence/user.rb, line 31
def groups
  # groups are cached for the lifetime of the user object or until a group-modifying method is called
  # FIXME: This is probably a bad idea, since the user's groups may be changed outside of the user object
  #         ... currently it's not a serious problem, since this is unlikely to happen within the object's
  #         short lifetime, but it may be problematic if start storing the user object in a cache or in the
  #         session.
  @groups ||= confluence.getUserGroups(username)
end
has_permission?(permtype, page) click to toggle source
# File lib/confluence/user.rb, line 54
def has_permission?(permtype, page)
  if permtype == :edit
    group_or_name = page.edit_group
  else
    group_or_name = page.view_group
  end
      
  return true if group_or_name.nil?
  return true if group_or_name == username
  return in_group?(group_or_name)
end
id() click to toggle source
# File lib/confluence/user.rb, line 15
def id
  self.username
end
id=(new_id) click to toggle source
# File lib/confluence/user.rb, line 19
def id=(new_id)
  self.username = new_id
end
in_group?(group) click to toggle source
# File lib/confluence/user.rb, line 40
def in_group?(group)
  groups.include? group
end
remove_from_group(group) click to toggle source
# File lib/confluence/user.rb, line 49
def remove_from_group(group)
  @groups = nil # reset cached group list
  confluence.removeUserFromGroup(username, group)
end
to_s() click to toggle source
# File lib/confluence/user.rb, line 66
def to_s
  self.username
end
to_wiki() click to toggle source
# File lib/confluence/user.rb, line 70
def to_wiki
  "[~#{self.username}]"
end
username() click to toggle source
# File lib/confluence/user.rb, line 23
def username
  self.name
end
username=(new_username) click to toggle source
# File lib/confluence/user.rb, line 27
def username=(new_username)
  self.username=(new_username)
end