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

Constructor Details

#initialize(realm, role) ⇒ AuthzRealmRole

Returns a new instance of AuthzRealmRole.



269
270
271
272
# File 'lib/sakai-info/authz.rb', line 269

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

Instance Attribute Details

#realmObject (readonly)

Returns the value of attribute realm.



267
268
269
# File 'lib/sakai-info/authz.rb', line 267

def realm
  @realm
end

#roleObject (readonly)

Returns the value of attribute role.



267
268
269
# File 'lib/sakai-info/authz.rb', line 267

def role
  @role
end

Class Method Details

.find_by_realm_id(realm_id) ⇒ Object



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

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



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

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



274
275
276
# File 'lib/sakai-info/authz.rb', line 274

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

#functionsObject



278
279
280
# File 'lib/sakai-info/authz.rb', line 278

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

#summary_serializationObject



314
315
316
317
318
319
320
# File 'lib/sakai-info/authz.rb', line 314

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

#user_countObject



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

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

#usersObject



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

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