Skip to content
Snippets Groups Projects
Commit 632b880e authored by Iain Bryson's avatar Iain Bryson
Browse files

Add extra logging. Add extra logging and user list into redis.

parent 60a9e7b3
Branches
No related tags found
No related merge requests found
...@@ -58,6 +58,7 @@ module DTUAuth2 ...@@ -58,6 +58,7 @@ module DTUAuth2
am.users[user._id] = user am.users[user._id] = user
end end
$redis.set("users", am.users.keys.to_json)
am.users.keys.each { |user_id| $redis.set("user$" + user_id, am.users[user_id].to_json) } am.users.keys.each { |user_id| $redis.set("user$" + user_id, am.users[user_id].to_json) }
groups_by_user = {} groups_by_user = {}
...@@ -85,6 +86,10 @@ module DTUAuth2 ...@@ -85,6 +86,10 @@ module DTUAuth2
$redis.set("user_role_by_user$" + user_id, g.uniq.to_json) $redis.set("user_role_by_user$" + user_id, g.uniq.to_json)
end end
groups.each do |group_id, g|
$redis.set("user_role_by_course$" + group_id, g.uniq.to_json)
end
# Rails.logger.debug "Users #{am.users.ai}" # Rails.logger.debug "Users #{am.users.ai}"
# Rails.logger.debug "User Roles #{am.user_roles.ai}" # Rails.logger.debug "User Roles #{am.user_roles.ai}"
Rails.logger.info "Groups #{am.groups.ai}" Rails.logger.info "Groups #{am.groups.ai}"
...@@ -115,8 +120,12 @@ module DTUAuth2 ...@@ -115,8 +120,12 @@ module DTUAuth2
JSON.parse ($redis.get("courses") || "[]") JSON.parse ($redis.get("courses") || "[]")
end end
def self.user_list
JSON.parse ($redis.get("users") || "[]")
end
def self.system_user def self.system_user
User2.new({:_id => "dtu_quiz_sysem", :full_name => "DTU Quiz System", :email => "no@email.com"}) User2.new({:_id => "dtu_quiz_system", :full_name => "DTU Quiz System", :email => "no@email.com"})
end end
def self.groups_by_user_and_role(course_id, user_id, role) def self.groups_by_user_and_role(course_id, user_id, role)
......
File added
...@@ -6,7 +6,7 @@ require "dtu-core/version" ...@@ -6,7 +6,7 @@ require "dtu-core/version"
# Describe your gem and declare its dependencies: # Describe your gem and declare its dependencies:
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "dtu-core" s.name = "dtu-core"
s.version = "0.0.3" s.version = "0.0.4"
s.authors = ["Iain Bryson"] s.authors = ["Iain Bryson"]
s.email = ["iain@iain-bryson.ca"] s.email = ["iain@iain-bryson.ca"]
s.homepage = "https://github.com/dtu-compute/dtu-core.git" s.homepage = "https://github.com/dtu-compute/dtu-core.git"
......
...@@ -8,19 +8,19 @@ task :wait_for_population => [:to_stdout, :environment] do ...@@ -8,19 +8,19 @@ task :wait_for_population => [:to_stdout, :environment] do
DTUAuth2::CachedAuthorizationManager.wait DTUAuth2::CachedAuthorizationManager.wait
end end
desc "Flush the redis cache"
task :populate => [:to_stdout, :environment] do
Rails.logger.info "Flushing the redis cache"
$redis.flushall
end
desc "Populate the redis cache" desc "Populate the redis cache"
task :populate => [:to_stdout, :environment] do task :populate => [:to_stdout, :environment] do
Rails.logger.info Rails.configuration.dtu_data Rails.logger.info Rails.configuration.dtu_data
DTUAuth2::populate Rails.configuration.dtu_data[:root_path] DTUAuth2::populate Rails.configuration.dtu_data[:root_path]
DTUAuth2::CachedAuthorizationManager.course_by_id('00000')
ap DTUAuth2::CachedAuthorizationManager.course_list ap DTUAuth2::CachedAuthorizationManager.course_list
ap DTUAuth2::CachedAuthorizationManager.user_by_id 'iaibrys' ap DTUAuth2::CachedAuthorizationManager.user_list
ap DTUAuth2::CachedAuthorizationManager.groups_by_course '00000' DTUAuth2::CachedAuthorizationManager.user_list.each do |user|
puts "DTUAuth2::CachedAuthorizationManager.groups_by_user 'iaibrys'" ap DTUAuth2::CachedAuthorizationManager.groups_by_user user
ap DTUAuth2::CachedAuthorizationManager.groups_by_user 'iaibrys' end
ap DTUAuth2::CachedAuthorizationManager.groups_by_user_and_role('00000', 'iaibrys', 'administrator')
ap DTUAuth2::CachedAuthorizationManager.groups_by_user_and_role('00000', 'iajbrys', 'student')
ap DTUAuth2::CachedAuthorizationManager.groups_by_course('00000')
ap DTUAuth2::CachedAuthorizationManager.roles_by_user('00000', 'iaibrys')
ap DTUAuth2::CachedAuthorizationManager.roles_by_user_and_group('00000', 'iaibrys', 'B')
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment