Class: SakaiInfo::AuthzRealmMembership

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_id, user_id, role) ⇒ AuthzRealmMembership

Returns a new instance of AuthzRealmMembership.



453
454
455
456
457
# File 'lib/sakai-info/authz.rb', line 453

def initialize(realm_id, user_id, role)
  @realm = AuthzRealm.find(realm_id)
  @user = User.find(user_id)
  @role = AuthzRole.find(role)
end

Instance Attribute Details

#realmObject (readonly)

Returns the value of attribute realm.



451
452
453
# File 'lib/sakai-info/authz.rb', line 451

def realm
  @realm
end

#roleObject (readonly)

Returns the value of attribute role.



451
452
453
# File 'lib/sakai-info/authz.rb', line 451

def role
  @role
end

#userObject (readonly)

Returns the value of attribute user.



451
452
453
# File 'lib/sakai-info/authz.rb', line 451

def user
  @user
end

Class Method Details

.count_by_realm_id(realm_id) ⇒ Object



471
472
473
# File 'lib/sakai-info/authz.rb', line 471

def self.count_by_realm_id(realm_id)
  DB.connect[:sakai_realm_rl_gr].where(:realm_key => realm_id).count
end

.find_by_realm_id(realm_id) ⇒ Object



459
460
461
462
463
464
465
466
467
468
469
# File 'lib/sakai-info/authz.rb', line 459

def self.find_by_realm_id(realm_id)
  results = []
  DB.connect.fetch("select srrg.user_id as user_id, " +
                   "srr.role_name as role_name " +
                   "from sakai_realm_rl_gr srrg, sakai_realm_role srr " +
                   "where srrg.role_key = srr.role_key " +
                   "and srrg.realm_key = ?", realm_id) do |row|
    results << AuthzRealmMembership.new(realm_id, row[:user_id], row[:role_name])
  end
  results
end

.find_by_user_id(user_id) ⇒ Object



475
476
477
478
479
480
481
482
483
484
485
486
# File 'lib/sakai-info/authz.rb', line 475

def self.find_by_user_id(user_id)
  results = []
  DB.connect.fetch("select sr.realm_id as realm_id, " +
                   "srr.role_name as role_name " +
                   "from sakai_realm_rl_gr srrg, sakai_realm_role srr, sakai_realm sr " +
                   "where srrg.role_key = srr.role_key " +
                   "and srrg.realm_key = sr.realm_key " +
                   "and srrg.user_id = ?", user_id) do |row|
    results << AuthzRealmMembership.new(row[:realm_id], user_id, row[:role_name])
  end
  results
end

Instance Method Details

#default_serializationObject



488
489
490
491
492
493
494
# File 'lib/sakai-info/authz.rb', line 488

def default_serialization
  {
    "realm" => self.realm.serialize(:summary),
    "user" => self.user.serialize(:summary),
    "role" => self.role.serialize(:summary),
  }
end

#realm_summary_serializationObject



504
505
506
507
508
509
# File 'lib/sakai-info/authz.rb', line 504

def realm_summary_serialization
  {
    "user" => self.user.eid,
    "role" => self.role.name,
  }
end

#summary_serializationObject



496
497
498
499
500
501
502
# File 'lib/sakai-info/authz.rb', line 496

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