Class: Confluence::User

Inherits:
RemoteDataObject show all
Defined in:
lib/confluence/user.rb

Defined Under Namespace

Classes: NoSuchUser

Instance Attribute Summary

Attributes inherited from RemoteDataObject

#attributes, #confluence, #encore

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RemoteDataObject

#==, #[], #[]=, #as_boolean, #as_datetime, #as_int, #as_string, confluence, connector, connector=, #destroy, encore, find, #initialize, #load_from_object, #method_missing, #reload, #save

Constructor Details

This class inherits a constructor from Confluence::RemoteDataObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Confluence::RemoteDataObject

Class Method Details

.find_allObject



95
96
97
98
99
# 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_usernamesObject



101
102
103
# File 'lib/confluence/user.rb', line 101

def self.find_all_usernames
  confluence.getActiveUsers(true)
end

.find_by_email(email) ⇒ Object



85
86
87
88
89
90
91
92
93
# 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) ⇒ Object

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



81
82
83
# File 'lib/confluence/user.rb', line 81

def self.find_by_name(username)
  find_by_username(username)
end

.find_by_username(username) ⇒ Object

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



76
77
78
# File 'lib/confluence/user.rb', line 76

def self.find_by_username(username)
  find(username)
end

Instance Method Details

#add_to_group(group) ⇒ Object



44
45
46
47
# File 'lib/confluence/user.rb', line 44

def add_to_group(group)
  @groups = nil # reset cached group list
  confluence.addUserToGroup(username, group)
end

#groupsObject



31
32
33
34
35
36
37
38
# 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) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
64
# 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

#idObject



15
16
17
# File 'lib/confluence/user.rb', line 15

def id
  self.username
end

#id=(new_id) ⇒ Object



19
20
21
# File 'lib/confluence/user.rb', line 19

def id=(new_id)
  self.username = new_id
end

#in_group?(group) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/confluence/user.rb', line 40

def in_group?(group)
  groups.include? group
end

#remove_from_group(group) ⇒ Object



49
50
51
52
# File 'lib/confluence/user.rb', line 49

def remove_from_group(group)
  @groups = nil # reset cached group list
  confluence.removeUserFromGroup(username, group)
end

#to_sObject



66
67
68
# File 'lib/confluence/user.rb', line 66

def to_s
  self.username
end

#to_wikiObject



70
71
72
# File 'lib/confluence/user.rb', line 70

def to_wiki
  "[~#{self.username}]"
end

#usernameObject



23
24
25
# File 'lib/confluence/user.rb', line 23

def username
  self.name
end

#username=(new_username) ⇒ Object



27
28
29
# File 'lib/confluence/user.rb', line 27

def username=(new_username)
  self.username=(new_username)
end