Class: SlingUsers::Group

Inherits:
Principal show all
Defined in:
lib/nakamura/users.rb

Instance Attribute Summary

Attributes inherited from Principal

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Principal

#initialize, #message_path_for, #private_path_for, #public_path_for

Constructor Details

This class inherits a constructor from SlingUsers::Principal

Class Method Details

.url_for(name) ⇒ Object



145
146
147
# File 'lib/nakamura/users.rb', line 145

def self.url_for(name)
  return "#{$USERMANAGER_URI}group/#{name}"
end

Instance Method Details

#add_manager(sling, principal) ⇒ Object



69
70
71
72
# File 'lib/nakamura/users.rb', line 69

def add_manager(sling, principal)
  return sling.execute_post(sling.url_for("#{group_url}.update.html"),
          { ":manager" => principal })
end

#add_member(sling, principal, type) ⇒ Object



50
51
52
53
54
# File 'lib/nakamura/users.rb', line 50

def add_member(sling, principal, type)
  principal_path = "/#{$USERMANAGER_URI}#{type}/#{principal}"
  return sling.execute_post(sling.url_for("#{group_url}.update.html"),
          { ":member" => principal_path })
end

#add_member_viewer(sling, principal) ⇒ Object



103
104
105
106
# File 'lib/nakamura/users.rb', line 103

def add_member_viewer(sling, principal)
  return sling.execute_post(sling.url_for("#{group_url}.update.html"),
          { ":member" => principal, ":viewer" => principal })
end

#add_members(sling, principals) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/nakamura/users.rb', line 56

def add_members(sling, principals)
  principal_paths = principals.collect do |principal|
    if principal.index("g-") == 0
      type = "group"
    else
      type = "user"
    end
    "/#{$USERMANAGER_URI}#{type}/#{principal}"
  end
  return sling.execute_post(sling.url_for("#{group_url}.update.html"),
          { ":member" => principal_paths })
end

#add_viewer(sling, principal) ⇒ Object



74
75
76
77
# File 'lib/nakamura/users.rb', line 74

def add_viewer(sling, principal)
  return sling.execute_post(sling.url_for("#{group_url}.update.html"),
          { ":viewer" => principal })
end

#details(sling) ⇒ Object



79
80
81
# File 'lib/nakamura/users.rb', line 79

def details(sling)
  return sling.get_node_props(group_url)
end

#has_member(sling, principal) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/nakamura/users.rb', line 89

def has_member(sling, principal)
  detail = self.details(sling)
  members = detail["members"]
  if (members == nil)
    return false
  end
  return members.include?(principal)
end

#home_path_for(sling) ⇒ Object

Get the home folder of a group.



141
142
143
# File 'lib/nakamura/users.rb', line 141

def home_path_for(sling)
  return "/~#{@name}"
end

#members(sling) ⇒ Object



135
136
137
138
# File 'lib/nakamura/users.rb', line 135

def members(sling)
  props = sling.get_node_props(group_url)
  return props["members"]
end

#remove_manager(sling, principal) ⇒ Object



108
109
110
111
# File 'lib/nakamura/users.rb', line 108

def remove_manager(sling, principal)
  return sling.execute_post(sling.url_for("#{group_url}.update.html"),
          { ":manager@Delete" => principal })
end

#remove_member(sling, principal, type) ⇒ Object



83
84
85
86
87
# File 'lib/nakamura/users.rb', line 83

def remove_member(sling, principal, type)
  principal_path = "/#{$USERMANAGER_URI}#{type}/#{principal}"
  return sling.execute_post(sling.url_for("#{group_url}.update.html"),
          { ":member@Delete" => principal_path })
end

#remove_member_viewer(sling, principal) ⇒ Object



98
99
100
101
# File 'lib/nakamura/users.rb', line 98

def remove_member_viewer(sling, principal)
  return sling.execute_post(sling.url_for("#{group_url}.update.html"),
          { ":member@Delete" => principal, ":viewer@Delete" => principal })
end

#remove_members(sling, principals) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/nakamura/users.rb', line 118

def remove_members(sling, principals)
  principal_paths = principals.collect do |principal|
    if principal.index("g-") == 0
      type = "group"
    else
      type = "user"
    end
    "/#{$USERMANAGER_URI}#{type}/#{principal}"
  end
  return sling.execute_post(sling.url_for("#{group_url}.update.html"),
          { ":member@Delete" => principal_paths })
end

#remove_viewer(sling, principal) ⇒ Object



113
114
115
116
# File 'lib/nakamura/users.rb', line 113

def remove_viewer(sling, principal)
  return sling.execute_post(sling.url_for("#{group_url}.update.html"),
          { ":viewer@Delete" => principal })
end

#set_joinable(sling, joinable) ⇒ Object



131
132
133
# File 'lib/nakamura/users.rb', line 131

def set_joinable(sling, joinable)
  return sling.execute_post(sling.url_for("#{group_url}.update.html"), "sakai:joinable" => joinable)
end

#to_sObject



42
43
44
# File 'lib/nakamura/users.rb', line 42

def to_s
  return "Group: #{@name}"
end

#update_properties(sling, props) ⇒ Object



46
47
48
# File 'lib/nakamura/users.rb', line 46

def update_properties(sling, props)
  return sling.execute_post(sling.url_for("#{group_url}.update.html"), props)
end