Class: SakaiInfo::AuthzRealmRole

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

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, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml

Constructor Details

#initialize(realm, role) ⇒ AuthzRealmRole

Returns a new instance of AuthzRealmRole.



385
386
387
388
# File 'lib/sakai-info/authz.rb', line 385

def initialize(realm, role)
  @realm = realm
  @role = role
end

Instance Attribute Details

#realmObject (readonly)

Returns the value of attribute realm.



383
384
385
# File 'lib/sakai-info/authz.rb', line 383

def realm
  @realm
end

#roleObject (readonly)

Returns the value of attribute role.



383
384
385
# File 'lib/sakai-info/authz.rb', line 383

def role
  @role
end

Class Method Details

.find_by_realm_id(realm_id) ⇒ Object



410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/sakai-info/authz.rb', line 410

def self.find_by_realm_id(realm_id)
  realm_roles = []
  realm = AuthzRealm.find_by_id(realm_id)
  DB.connect.fetch("select distinct role_key from " +
                   "sakai_realm_rl_fn where " +
                   "realm_key = ?", realm_id) do |row|
    begin
      role = AuthzRole.find_by_id(row[:role_key].to_i)
      realm_roles << AuthzRealmRole.new(realm, role)
    rescue AuthzRoleNotFoundException
    end
  end
  realm_roles
end

Instance Method Details

#default_serializationObject



425
426
427
428
429
430
431
432
# File 'lib/sakai-info/authz.rb', line 425

def default_serialization
  {
    "realm_name" => self.realm.name,
    "role_name" => self.role.name,
    "user_count" => self.user_count,
    "function_count" => self.function_count,
  }
end

#function_countObject



390
391
392
393
# File 'lib/sakai-info/authz.rb', line 390

def function_count
  @function_count ||=
    AuthzFunction.count_by_realm_id_and_role_id(self.realm.id, self.role.id)
end

#functionsObject



395
396
397
398
# File 'lib/sakai-info/authz.rb', line 395

def functions
  @functions ||=
    AuthzFunction.find_by_realm_id_and_role_id(self.realm.id, self.role.id)
end

#realm_summary_serializationObject



441
442
443
444
445
446
447
# File 'lib/sakai-info/authz.rb', line 441

def realm_summary_serialization
  {
    "role" => self.role.name,
    "user_count" => self.user_count,
    "function_count" => self.function_count,
  }
end

#summary_serializationObject



434
435
436
437
438
439
# File 'lib/sakai-info/authz.rb', line 434

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

#user_countObject



400
401
402
403
# File 'lib/sakai-info/authz.rb', line 400

def user_count
  @user_count ||=
    User.count_by_realm_id_and_role_id(self.realm.id, self.role.id)
end

#usersObject



405
406
407
408
# File 'lib/sakai-info/authz.rb', line 405

def users
  @users ||=
    User.find_by_realm_id_and_role_id(self.realm.id, self.role.id)
end