sakai-info 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +12 -0
- data/LICENSE +8 -0
- data/README.md +148 -0
- data/ROADMAP.md +37 -0
- data/bin/sakai-info +79 -0
- data/lib/sakai-info.rb +62 -0
- data/lib/sakai-info/announcement.rb +170 -0
- data/lib/sakai-info/assignment.rb +281 -0
- data/lib/sakai-info/authz.rb +378 -0
- data/lib/sakai-info/cli.rb +35 -0
- data/lib/sakai-info/cli/help.rb +103 -0
- data/lib/sakai-info/configuration.rb +288 -0
- data/lib/sakai-info/content.rb +300 -0
- data/lib/sakai-info/db.rb +19 -0
- data/lib/sakai-info/gradebook.rb +176 -0
- data/lib/sakai-info/group.rb +119 -0
- data/lib/sakai-info/instance.rb +122 -0
- data/lib/sakai-info/message.rb +122 -0
- data/lib/sakai-info/sakai_object.rb +58 -0
- data/lib/sakai-info/sakai_xml_entity.rb +126 -0
- data/lib/sakai-info/samigo.rb +219 -0
- data/lib/sakai-info/site.rb +752 -0
- data/lib/sakai-info/user.rb +220 -0
- data/lib/sakai-info/version.rb +3 -0
- metadata +90 -0
@@ -0,0 +1,220 @@
|
|
1
|
+
# sakai-info/user.rb
|
2
|
+
# SakaiInfo::User library
|
3
|
+
#
|
4
|
+
# Created 2012-02-17 daveadams@gmail.com
|
5
|
+
# Last updated 2012-02-17 daveadams@gmail.com
|
6
|
+
#
|
7
|
+
# https://github.com/daveadams/sakai-info
|
8
|
+
#
|
9
|
+
# This software is public domain.
|
10
|
+
#
|
11
|
+
|
12
|
+
module SakaiInfo
|
13
|
+
class User < SakaiObject
|
14
|
+
attr_reader :eid, :name, :type
|
15
|
+
attr_reader :created_by, :created_at, :modified_by, :modified_at
|
16
|
+
|
17
|
+
@@cache = {}
|
18
|
+
def self.find(id)
|
19
|
+
if @@cache[id].nil?
|
20
|
+
user_id = eid = nil
|
21
|
+
DB.connect.exec("select user_id, eid from sakai_user_id_map " +
|
22
|
+
"where user_id=:user_id or eid=:eid", id, id) do |row|
|
23
|
+
user_id = row[0]
|
24
|
+
eid = row[1]
|
25
|
+
end
|
26
|
+
if user_id.nil? or eid.nil?
|
27
|
+
raise ObjectNotFoundException.new(User, id)
|
28
|
+
end
|
29
|
+
|
30
|
+
DB.connect.exec("select first_name, last_name, type, " +
|
31
|
+
"to_char(createdon,'YYYY-MM-DD HH24:MI:SS'), " +
|
32
|
+
"to_char(modifiedon,'YYYY-MM-DD HH24:MI:SS') " +
|
33
|
+
"from sakai_user where user_id=:userid", user_id) do |row|
|
34
|
+
first_name, last_name, type, created_at, modified_at = *row
|
35
|
+
first_name ||= ""
|
36
|
+
last_name ||= ""
|
37
|
+
@@cache[eid] =
|
38
|
+
@@cache[user_id] =
|
39
|
+
User.new(user_id, eid, (first_name+' '+last_name), type, created_at, modified_at)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@@cache[id]
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(id, eid, name, type, created_at, modified_at)
|
46
|
+
@id = id
|
47
|
+
@eid = eid
|
48
|
+
@name = name
|
49
|
+
@type = type
|
50
|
+
@created_at = created_at
|
51
|
+
@modified_at = modified_at
|
52
|
+
@properties = nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def properties
|
56
|
+
@properties ||= UserProperty.find_by_user_id(@id)
|
57
|
+
end
|
58
|
+
|
59
|
+
def workspace
|
60
|
+
@workspace ||= Site.find("~" + @id)
|
61
|
+
end
|
62
|
+
|
63
|
+
def question_pools
|
64
|
+
@question_pools ||= QuestionPool.find_by_user_id(@id)
|
65
|
+
end
|
66
|
+
|
67
|
+
def question_pool_count
|
68
|
+
if @question_pools.nil?
|
69
|
+
QuestionPool.count_by_user_id(@id)
|
70
|
+
else
|
71
|
+
@question_pools.length
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def assignment_submissions
|
76
|
+
@assignment_submissions ||= AssignmentSubmission.find_by_user_id(@id)
|
77
|
+
end
|
78
|
+
|
79
|
+
def assignment_submission_count
|
80
|
+
@assignment_submission_count ||= AssignmentSubmission.count_by_user_id(@id)
|
81
|
+
end
|
82
|
+
|
83
|
+
def assignment_contents
|
84
|
+
@assignment_contents ||= AssignmentContent.find_by_user_id(@id)
|
85
|
+
end
|
86
|
+
|
87
|
+
def assignment_content_count
|
88
|
+
@assignment_content_count ||= AssignmentContent.count_by_user_id(@id)
|
89
|
+
end
|
90
|
+
|
91
|
+
def membership
|
92
|
+
@membership ||= SiteMembership.find_by_user_id(@id)
|
93
|
+
end
|
94
|
+
|
95
|
+
def site_count
|
96
|
+
if @membership.nil?
|
97
|
+
Site.count_by_user_id(@id)
|
98
|
+
else
|
99
|
+
@membership.length
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def preferences_xml
|
104
|
+
if @preferences_xml.nil?
|
105
|
+
db = DB.connect
|
106
|
+
@preferences_xml = ""
|
107
|
+
db.exec("select xml from sakai_preferences " +
|
108
|
+
"where preferences_id=:userid", @user_id) do |row|
|
109
|
+
REXML::Document.new(row[0].read).write(@preferences_xml, 2)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
@preferences_xml
|
113
|
+
end
|
114
|
+
|
115
|
+
# finders/counters
|
116
|
+
@@total_user_count = nil
|
117
|
+
def self.count
|
118
|
+
if @@total_user_count.nil?
|
119
|
+
@@total_user_count = 0
|
120
|
+
DB.connect.exec("select count(*) from sakai_user") do |row|
|
121
|
+
@@total_user_count = row[0].to_i
|
122
|
+
end
|
123
|
+
end
|
124
|
+
@@total_user_count
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.count_by_realm_id_and_role_id(realm_id, role_id)
|
128
|
+
count = 0
|
129
|
+
DB.connect.exec("select count(*) from sakai_realm_rl_gr " +
|
130
|
+
"where realm_key = :realm_id " +
|
131
|
+
"and role_key = :role_id", realm_id, role_id) do |row|
|
132
|
+
count = row[0].to_i
|
133
|
+
end
|
134
|
+
count
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.find_by_realm_id_and_role_id(realm_id, role_id)
|
138
|
+
users = []
|
139
|
+
DB.connect.exec("select first_name, last_name, type, " +
|
140
|
+
"to_char(createdon,'YYYY-MM-DD HH24:MI:SS'), " +
|
141
|
+
"to_char(modifiedon,'YYYY-MM-DD HH24:MI:SS') " +
|
142
|
+
"from sakai_user where user_id in " +
|
143
|
+
"(select user_id from sakai_realm_rl_gr " +
|
144
|
+
"where realm_key = :realm_id " +
|
145
|
+
"and role_key = :role_id)", realm_id, role_id) do |row|
|
146
|
+
first_name, last_name, type, created_at, modified_at = *row
|
147
|
+
first_name ||= ""
|
148
|
+
last_name ||= ""
|
149
|
+
@@cache[eid] =
|
150
|
+
@@cache[user_id] =
|
151
|
+
User.new(user_id, eid, (first_name+' '+last_name), type, created_at, modified_at)
|
152
|
+
users << @@cache[eid]
|
153
|
+
end
|
154
|
+
users
|
155
|
+
end
|
156
|
+
|
157
|
+
# yaml/json serialization
|
158
|
+
def default_serialization
|
159
|
+
{
|
160
|
+
"id" => self.id,
|
161
|
+
"name" => self.name,
|
162
|
+
"eid" => self.eid,
|
163
|
+
"type" => self.type,
|
164
|
+
"created_at" => self.created_at,
|
165
|
+
"user_properties" => UserProperty.find_by_user_id(self.id),
|
166
|
+
"site_count" => self.site_count,
|
167
|
+
"question_pool_count" => self.question_pool_count
|
168
|
+
}
|
169
|
+
end
|
170
|
+
|
171
|
+
def summary_serialization
|
172
|
+
{
|
173
|
+
"id" => self.id,
|
174
|
+
"eid" => self.eid,
|
175
|
+
"name" => self.name,
|
176
|
+
"type" => self.type
|
177
|
+
}
|
178
|
+
end
|
179
|
+
|
180
|
+
def membership_serialization
|
181
|
+
{
|
182
|
+
"sites" => self.membership.collect { |sm| sm.serialize(:user_summary) }
|
183
|
+
}
|
184
|
+
end
|
185
|
+
|
186
|
+
def question_pools_serialization
|
187
|
+
if self.question_pool_count > 0
|
188
|
+
{
|
189
|
+
"question_pools" => self.question_pools.collect { |qp| qp.serialize(:user_summary) }
|
190
|
+
}
|
191
|
+
else
|
192
|
+
{}
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
class UserProperty
|
198
|
+
def self.get(user_id, property_name)
|
199
|
+
db = DB.connect
|
200
|
+
value = nil
|
201
|
+
db.exec("select value from sakai_user_property " +
|
202
|
+
"where user_id=:user_id and name=:name", user_id, property_name) do |row|
|
203
|
+
value = row[0].read
|
204
|
+
end
|
205
|
+
return value
|
206
|
+
end
|
207
|
+
|
208
|
+
def self.find_by_user_id(user_id)
|
209
|
+
db = DB.connect
|
210
|
+
properties = {}
|
211
|
+
db.exec("select name, value from sakai_user_property " +
|
212
|
+
"where user_id=:user_id", user_id) do |row|
|
213
|
+
name = row[0]
|
214
|
+
value = row[1].read
|
215
|
+
properties[name] = value
|
216
|
+
end
|
217
|
+
return properties
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sakai-info
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- David Adams
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-19 00:00:00 -06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: A command line tool and a suite of libraries for representing the objects and relationships defined by a Sakai CLE database.
|
23
|
+
email: daveadams@gmail.com
|
24
|
+
executables:
|
25
|
+
- sakai-info
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/sakai-info.rb
|
32
|
+
- lib/sakai-info/group.rb
|
33
|
+
- lib/sakai-info/samigo.rb
|
34
|
+
- lib/sakai-info/cli/help.rb
|
35
|
+
- lib/sakai-info/site.rb
|
36
|
+
- lib/sakai-info/assignment.rb
|
37
|
+
- lib/sakai-info/authz.rb
|
38
|
+
- lib/sakai-info/gradebook.rb
|
39
|
+
- lib/sakai-info/sakai_object.rb
|
40
|
+
- lib/sakai-info/user.rb
|
41
|
+
- lib/sakai-info/version.rb
|
42
|
+
- lib/sakai-info/announcement.rb
|
43
|
+
- lib/sakai-info/cli.rb
|
44
|
+
- lib/sakai-info/instance.rb
|
45
|
+
- lib/sakai-info/configuration.rb
|
46
|
+
- lib/sakai-info/message.rb
|
47
|
+
- lib/sakai-info/content.rb
|
48
|
+
- lib/sakai-info/db.rb
|
49
|
+
- lib/sakai-info/sakai_xml_entity.rb
|
50
|
+
- bin/sakai-info
|
51
|
+
- README.md
|
52
|
+
- LICENSE
|
53
|
+
- CHANGELOG.md
|
54
|
+
- ROADMAP.md
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: https://github.com/daveadams/sakai-info
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.3.7
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Tools and library for exploring a Sakai database
|
89
|
+
test_files: []
|
90
|
+
|