Class: SakaiInfo::AuthzRealm

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

Direct Known Subclasses

MissingAuthzRealm

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModProps

included

Methods inherited from SakaiObject

#dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml

Constructor Details

#initialize(row) ⇒ AuthzRealm

Returns a new instance of AuthzRealm.



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

def initialize(row)
  @dbrow = row

  @id = @dbrow[:realm_key].to_i
  @name = @dbrow[:realm_id]
  if @dbrow[:provider_id].nil?
    @providers = nil
  else
    @providers = @dbrow[:provider_id].split("+")
  end
  if @dbrow[:maintain_role].nil? or @dbrow[:maintain_role] == ""
    @maintain_role = nil
  else
    @maintain_role = AuthzRole.find_by_id(@dbrow[:maintain_role])
  end
end

Instance Attribute Details

#maintain_roleObject (readonly)

Returns the value of attribute maintain_role.



184
185
186
# File 'lib/sakai-info/authz.rb', line 184

def maintain_role
  @maintain_role
end

#nameObject (readonly)

Returns the value of attribute name.



184
185
186
# File 'lib/sakai-info/authz.rb', line 184

def name
  @name
end

#providersObject (readonly)

Returns the value of attribute providers.



184
185
186
# File 'lib/sakai-info/authz.rb', line 184

def providers
  @providers
end

Class Method Details

.all_serializationsObject



324
325
326
327
328
329
330
331
# File 'lib/sakai-info/authz.rb', line 324

def self.all_serializations
  [
   :default,
   :mod,
   :roles,
   :users,
  ]
end

.clear_cacheObject



192
193
194
# File 'lib/sakai-info/authz.rb', line 192

def self.clear_cache
  @@cache = {}
end

.find(id_or_name) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/sakai-info/authz.rb', line 255

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!(id_or_name) ⇒ Object



270
271
272
273
274
275
276
277
278
279
# File 'lib/sakai-info/authz.rb', line 270

def self.find!(id_or_name)
  begin
    realm = AuthzRealm.find(id_or_name)
  rescue ObjectNotFoundException => e
    if e.classname == AuthzRealm.name
      realm = MissingAuthzRealm.find(id_or_name)
    end
  end
  realm
end

.find_by_id(id) ⇒ Object



230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/sakai-info/authz.rb', line 230

def self.find_by_id(id)
  id = id.to_s
  if @@cache[id].nil?
    row = DB.connect[:sakai_realm].where(:realm_key => id.to_i).first
    if row.nil?
      raise ObjectNotFoundException.new(AuthzRealm, id)
    end
    @@cache[id] = AuthzRealm.new(row)
    @@cache[@@cache[id].name] = @@cache[id]
  end
  @@cache[id]
end

.find_by_name(name) ⇒ Object



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

def self.find_by_name(name)
  if @@cache[name].nil?
    row = DB.connect[:sakai_realm].where(:realm_id => name).first
    if row.nil?
      raise ObjectNotFoundException.new(AuthzRealm, name)
    end
    @@cache[name] = AuthzRealm.new(row)
    @@cache[@@cache[name].id] = @@cache[name]
  end
  @@cache[name]
end

.find_by_site_id(site_id) ⇒ Object



282
283
284
# File 'lib/sakai-info/authz.rb', line 282

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



286
287
288
# File 'lib/sakai-info/authz.rb', line 286

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

#default_serializationObject



290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/sakai-info/authz.rb', line 290

def default_serialization
  result = {
    "id" => self.id,
    "name" => self.name,
    "user_count" => self.user_count,
  }
  if not self.providers.nil?
    result["providers"] = self.providers
  end
  if not self.maintain_role.nil?
    result["maintain_role"] = self.maintain_role.name
  end
  result
end

#realm_rolesObject



214
215
216
# File 'lib/sakai-info/authz.rb', line 214

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

#roles_serializationObject



312
313
314
315
316
# File 'lib/sakai-info/authz.rb', line 312

def roles_serialization
  {
    "roles" => self.realm_roles.collect { |rr| rr.serialize(:realm_summary) }
  }
end

#summary_serializationObject



305
306
307
308
309
310
# File 'lib/sakai-info/authz.rb', line 305

def summary_serialization
  {
    "id" => self.id,
    "name" => self.name,
  }
end

#to_sObject



218
219
220
# File 'lib/sakai-info/authz.rb', line 218

def to_s
  name
end

#user_countObject



222
223
224
# File 'lib/sakai-info/authz.rb', line 222

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

#usersObject



226
227
228
# File 'lib/sakai-info/authz.rb', line 226

def users
  @users ||= AuthzRealmMembership.find_by_realm_id(self.id)
end

#users_serializationObject



318
319
320
321
322
# File 'lib/sakai-info/authz.rb', line 318

def users_serialization
  {
    "users" => self.users.collect { |u| u.serialize(:realm_summary) }
  }
end