Class: SakaiInfo::AuthzRealm

Inherits:
SakaiObject show all
Defined in:
lib/sakai-info/authz.rb

Constant Summary collapse

@@cache =
{}

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SakaiObject

all_serializations, #dbrow_only_serialization, #dbrow_serialization, #default_serialization, #object_type_serialization, #serialize, #to_json, #to_yaml

Constructor Details

#initialize(id, name, providers, maintain_role) ⇒ AuthzRealm

Returns a new instance of AuthzRealm.



167
168
169
170
171
172
173
174
175
176
# File 'lib/sakai-info/authz.rb', line 167

def initialize(id, name, providers, maintain_role)
  @id = id
  @name = name
  if providers.nil?
    @providers = nil
  else
    @providers = providers.split("+")
  end
  @maintain_role = maintain_role
end

Instance Attribute Details

#maintain_roleObject (readonly)

Returns the value of attribute maintain_role.



165
166
167
# File 'lib/sakai-info/authz.rb', line 165

def maintain_role
  @maintain_role
end

#nameObject (readonly)

Returns the value of attribute name.



165
166
167
# File 'lib/sakai-info/authz.rb', line 165

def name
  @name
end

#providersObject (readonly)

Returns the value of attribute providers.



165
166
167
# File 'lib/sakai-info/authz.rb', line 165

def providers
  @providers
end

Class Method Details

.find(id_or_name) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/sakai-info/authz.rb', line 242

def self.find(id_or_name)
  id_or_name = id_or_name.to_s
  realm = nil
  begin
    realm = AuthzRealm.find_by_name(id_or_name)
  rescue ObjectNotFoundException
    # just in case
    realm = AuthzRealm.find_by_id(id_or_name)
  end
  if realm.nil?
    raise ObjectNotFoundException.new(AuthzRealm, id_or_name)
  end
  realm
end

.find_by_id(id) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/sakai-info/authz.rb', line 195

def self.find_by_id(id)
  id = id.to_s
  if @@cache[id].nil?
    row = DB.connect.fetch("select realm_id, provider_id, maintain_role " +
                           "from sakai_realm " +
                           "where realm_key = ?", id.to_i).first
    if row.nil?
      raise ObjectNotFoundException.new(AuthzRealm, id)
    end

    name = row[:realm_id]
    providers = row[:provider_id]
    maintain_role = nil
    if row[:maintain_role].nil? or row[:maintain_role] == ""
      maintain_role = nil
    else
      maintain_role = AuthzRole.find_by_id(row[:maintain_role].to_i)
    end
    @@cache[id] = AuthzRealm.new(id, name, providers, maintain_role)
    @@cache[name] = @@cache[id]
  end
  @@cache[id]
end

.find_by_name(name) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/sakai-info/authz.rb', line 219

def self.find_by_name(name)
  if @@cache[name].nil?
    row = DB.connect.fetch("select realm_key, provider_id, maintain_role " +
                           "from sakai_realm " +
                           "where realm_id = ?", name).first
    if row.nil?
      raise ObjectNotFoundException.new(AuthzRealm, name)
    end

    id = row[:realm_key].to_i.to_s
    providers = row[:provider_id]
    maintain_role = nil
    if row[:maintain_role].nil? or row[:maintain_role] == ""
      maintain_role = nil
    else
      maintain_role = AuthzRole.find_by_id(row[:maintain_role].to_i)
    end
    @@cache[name] = AuthzRealm.new(id, name, providers, maintain_role)
    @@cache[id] = @@cache[name]
  end
  @@cache[name]
end

.find_by_site_id(site_id) ⇒ Object



257
258
259
# File 'lib/sakai-info/authz.rb', line 257

def self.find_by_site_id(site_id)
  AuthzRealm.find_by_name("/site/#{site_id}")
end

.find_by_site_id_and_group_id(site_id, group_id) ⇒ Object



261
262
263
# File 'lib/sakai-info/authz.rb', line 261

def self.find_by_site_id_and_group_id(site_id, group_id)
  AuthzRealm.find_by_name("/site/#{site_id}/group/#{group_id}")
end

Instance Method Details

#membershipObject



190
191
192
# File 'lib/sakai-info/authz.rb', line 190

def membership
  @membership ||= AuthzRealmMembership.find_by_realm_id(@id)
end

#realm_rolesObject



178
179
180
# File 'lib/sakai-info/authz.rb', line 178

def realm_roles
  @realm_roles ||= AuthzRealmRole.find_by_realm_id(@id)
end

#to_sObject



182
183
184
# File 'lib/sakai-info/authz.rb', line 182

def to_s
  name
end

#user_countObject



186
187
188
# File 'lib/sakai-info/authz.rb', line 186

def user_count
  @user_count ||= AuthzRealmMembership.count_by_realm_id(@id)
end