sakai-info 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # sakai-info Change History #
2
2
 
3
+ ### 0.4.5 ###
4
+
5
+ *Released 2012-05-14*
6
+
7
+ * CLI support for authz roles, realms, and functions
8
+ * Bugfix: fix syntax error using ContentCollection.find! on missing collections
9
+ * Bugfix: gracefully handle missing AnnouncementChannel for Site serializations
10
+
3
11
  ### 0.4.4 ###
4
12
 
5
13
  *Released 2012-05-12*
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # sakai-info #
2
2
 
3
- last updated: 2012-05-12
3
+ last updated: 2012-05-14
4
4
  author: David Adams (daveadams@gmail.com)
5
5
  github url: https://github.com/daveadams/sakai-info
6
6
 
@@ -24,7 +24,7 @@ Use `rake` to test and build the gem:
24
24
  $ rake gem:build
25
25
 
26
26
  The resulting gem will be saved to the working directory as
27
- `sakai-info-0.4.4.gem`.
27
+ `sakai-info-0.4.5.gem`.
28
28
 
29
29
  Cleanup built gems using:
30
30
 
data/ROADMAP.md CHANGED
@@ -1,23 +1,20 @@
1
1
  # sakai-info Roadmap #
2
2
 
3
- *Last updated 2012-05-12*
3
+ *Last updated 2012-05-14*
4
4
 
5
- ### 0.4.5 ###
6
-
7
- * CLI access to authz (realms, roles, functions)
8
-
9
- ### 0.5.0 ###
5
+ ### 0.5.x ###
10
6
 
11
7
  * Sqlite test infrastructure for a few basic objects
12
8
  * Deeper query functionality and field specification
13
9
  * Simple web query interface - HTML, JSON, and YAML
10
+ * Global cache instead of per-class
14
11
 
15
- ### 0.6.0 ###
12
+ ### 0.6.x ###
16
13
 
17
14
  * Test fixtures and basic unit tests for all represented objects
18
15
  * RDoc coverage for every class
19
16
 
20
- ### 0.7.0 ###
17
+ ### 0.7.x ###
21
18
 
22
19
  * OSP support
23
20
 
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Authz library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-05-10 daveadams@gmail.com
5
+ # Last updated 2012-05-14 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -18,9 +18,11 @@ module SakaiInfo
18
18
  end
19
19
  clear_cache
20
20
 
21
- def initialize(id, name)
22
- @id = id
23
- @name = name
21
+ def initialize(dbrow)
22
+ @dbrow = dbrow
23
+
24
+ @id = @dbrow[:role_key].to_i
25
+ @name = @dbrow[:role_name]
24
26
  end
25
27
 
26
28
  def to_s
@@ -30,13 +32,12 @@ module SakaiInfo
30
32
  def self.find_by_id(id)
31
33
  id = id.to_s
32
34
  if @@cache[id].nil?
33
- row = DB.connect.fetch("select role_name from sakai_realm_role " +
34
- "where role_key = ?", id.to_i).first
35
+ row = DB.connect[:sakai_realm_role].where(:role_key => id.to_i).first
35
36
  if row.nil?
36
37
  raise ObjectNotFoundException.new(AuthzRole, id)
37
38
  end
38
- @@cache[id] = AuthzRole.new(id, row[:role_name])
39
- @@cache[name] = @@cache[id]
39
+ @@cache[id] = AuthzRole.new(row)
40
+ @@cache[@@cache[id].name] = @@cache[id]
40
41
  end
41
42
  @@cache[id]
42
43
  end
@@ -46,14 +47,12 @@ module SakaiInfo
46
47
  raise ObjectNotFoundException.new(AuthzRole, "")
47
48
  end
48
49
  if @@cache[name].nil?
49
- row = DB.connect.fetch("select role_key from sakai_realm_role " +
50
- "where role_name = ?", name).first
50
+ row = DB.connect[:sakai_realm_role].where(:role_name => name).first
51
51
  if row.nil?
52
52
  raise ObjectNotFoundException.new(AuthzRole, name)
53
53
  end
54
- id = row[:role_key].to_i.to_s
55
- @@cache[name] = AuthzRole.new(id, name)
56
- @@cache[id] = @@cache[name]
54
+ @@cache[name] = AuthzRole.new(row)
55
+ @@cache[@@cache[name].id] = @@cache[name]
57
56
  end
58
57
  @@cache[name]
59
58
  end
@@ -73,18 +72,26 @@ module SakaiInfo
73
72
  role
74
73
  end
75
74
 
75
+ def self.query_by_realm_id_and_function_id(realm_id, function_id)
76
+ DB.connect[:sakai_realm_role].
77
+ where(:role_key => DB.connect[:sakai_realm_rl_fn].select(:role_key).
78
+ where(:realm_key => realm_id, :function_key => function_id))
79
+ end
80
+
81
+ def self.count_by_realm_id_and_function_id(realm_id, function_id)
82
+ AuthzRole.query_by_realm_id_and_function_id(realm_id, function_id).count
83
+ end
84
+
76
85
  def self.find_by_realm_id_and_function_id(realm_id, function_id)
77
- roles = []
78
- DB.connect.fetch("select role_key, role_name from " +
79
- "sakai_realm_role where role_key in " +
80
- "(select role_key from sakai_realm_rl_fn " +
81
- "where realm_key=? and function_key=?) " +
82
- "order by role_name", realm_id, function_id) do |row|
83
- role_id = row[:role_key].to_i.to_s
84
- role_name = row[:role_name]
85
- roles << AuthzRole.new(role_id, role_name)
86
- end
87
- roles
86
+ AuthzRole.query_by_realm_id_and_function_id(realm_id, function_id).
87
+ order(:role_name).all.collect { |row| AuthzRole.new(row) }
88
+ end
89
+
90
+ def default_serialization
91
+ {
92
+ "id" => self.id,
93
+ "name" => self.name,
94
+ }
88
95
  end
89
96
  end
90
97
 
@@ -96,9 +103,11 @@ module SakaiInfo
96
103
  end
97
104
  clear_cache
98
105
 
99
- def initialize(id, name)
100
- @id = id
101
- @name = name
106
+ def initialize(dbrow)
107
+ @dbrow = dbrow
108
+
109
+ @id = @dbrow[:function_key].to_i
110
+ @name = @dbrow[:function_name]
102
111
  end
103
112
 
104
113
  def to_s
@@ -108,28 +117,27 @@ module SakaiInfo
108
117
  def self.find_by_id(id)
109
118
  id = id.to_s
110
119
  if @@cache[id].nil?
111
- row = DB.connect.fetch("select function_name from sakai_realm_function " +
112
- "where function_key = ?", id.to_i).first
120
+ row = DB.connect[:sakai_realm_function].where(:function_key => id.to_i).first
113
121
  if row.nil?
114
122
  raise ObjectNotFoundException.new(AuthzFunction, id)
115
123
  end
116
- @@cache[id] = AuthzFunction.new(id, row[:function_name])
117
- @@cache[row[:function_name]] = @@cache[id]
124
+ @@cache[id] = AuthzFunction.new(row)
125
+ @@cache[@@cache[id].name] = @@cache[id]
118
126
  end
119
127
  @@cache[id]
120
128
  end
121
129
 
122
130
  def self.find_by_name(name)
131
+ if name.nil?
132
+ raise ObjectNotFoundException.new(AuthzFunction, "")
133
+ end
123
134
  if @@cache[name].nil?
124
- id = nil
125
- row = DB.connect.fetch("select function_key from sakai_realm_function " +
126
- "where function_name = ?", name).first
135
+ row = DB.connect[:sakai_realm_function].where(:function_name => name).first
127
136
  if row.nil?
128
137
  raise ObjectNotFoundException.new(AuthzFunction, name)
129
138
  end
130
- id = row[:function_key].to_i.to_s
131
- @@cache[name] = AuthzFunction.new(id, name)
132
- @@cache[id] = @@cache[name]
139
+ @@cache[name] = AuthzFunction.new(row)
140
+ @@cache[@@cache[name].id] = @@cache[name]
133
141
  end
134
142
  @@cache[name]
135
143
  end
@@ -149,47 +157,62 @@ module SakaiInfo
149
157
  function
150
158
  end
151
159
 
160
+ def self.query_by_realm_id_and_role_id(realm_id, role_id)
161
+ DB.connect[:sakai_realm_function].
162
+ where(:function_key => DB.connect[:sakai_realm_rl_fn].select(:function_key).
163
+ where(:realm_key => realm_id, :role_key => role_id))
164
+ end
165
+
152
166
  def self.count_by_realm_id_and_role_id(realm_id, role_id)
153
- DB.connect[:sakai_realm_rl_fn].
154
- filter(:realm_key => realm_id, :role_key => role_id).count
167
+ AuthzFunction.query_by_realm_id_and_role_id(realm_id, role_id).count
155
168
  end
156
169
 
157
170
  def self.find_by_realm_id_and_role_id(realm_id, role_id)
158
- functions = []
159
- DB.connect.fetch("select function_key, function_name from " +
160
- "sakai_realm_function where function_key in " +
161
- "(select function_key from sakai_realm_rl_fn " +
162
- "where realm_key=? and role_key=?) " +
163
- "order by function_name", realm_id, role_id) do |row|
164
- function_id = row[:function_key].to_i.to_s
165
- function_name = row[:function_name]
166
- functions << AuthzFunction.new(function_id, function_name)
167
- end
168
- functions
171
+ AuthzFunction.query_by_realm_id_and_role_id(realm_id, role_id).
172
+ order(:function_name).all.collect { |row| AuthzFunction.new(row) }
173
+ end
174
+
175
+ def default_serialization
176
+ {
177
+ "id" => self.id,
178
+ "name" => self.name,
179
+ }
169
180
  end
170
181
  end
171
182
 
172
183
  class AuthzRealm < SakaiObject
173
184
  attr_reader :name, :providers, :maintain_role
174
185
 
186
+ include ModProps
187
+ created_at_key :createdon
188
+ created_by_key :createdby
189
+ modified_at_key :modifiedon
190
+ modified_by_key :modifiedby
191
+
175
192
  def self.clear_cache
176
193
  @@cache = {}
177
194
  end
178
195
  clear_cache
179
196
 
180
- def initialize(id, name, providers, maintain_role)
181
- @id = id
182
- @name = name
183
- if providers.nil?
197
+ def initialize(row)
198
+ @dbrow = row
199
+
200
+ @id = @dbrow[:realm_key].to_i
201
+ @name = @dbrow[:realm_id]
202
+ if @dbrow[:provider_id].nil?
184
203
  @providers = nil
185
204
  else
186
- @providers = providers.split("+")
205
+ @providers = @dbrow[:provider_id].split("+")
206
+ end
207
+ if @dbrow[:maintain_role].nil? or @dbrow[:maintain_role] == ""
208
+ @maintain_role = nil
209
+ else
210
+ @maintain_role = AuthzRole.find_by_id(@dbrow[:maintain_role])
187
211
  end
188
- @maintain_role = maintain_role
189
212
  end
190
213
 
191
214
  def realm_roles
192
- @realm_roles ||= AuthzRealmRole.find_by_realm_id(@id)
215
+ @realm_roles ||= AuthzRealmRole.find_by_realm_id(self.id)
193
216
  end
194
217
 
195
218
  def to_s
@@ -197,56 +220,34 @@ module SakaiInfo
197
220
  end
198
221
 
199
222
  def user_count
200
- @user_count ||= AuthzRealmMembership.count_by_realm_id(@id)
223
+ @user_count ||= AuthzRealmMembership.count_by_realm_id(self.id)
201
224
  end
202
225
 
203
- def membership
204
- @membership ||= AuthzRealmMembership.find_by_realm_id(@id)
226
+ def users
227
+ @users ||= AuthzRealmMembership.find_by_realm_id(self.id)
205
228
  end
206
229
 
207
230
  def self.find_by_id(id)
208
231
  id = id.to_s
209
232
  if @@cache[id].nil?
210
- row = DB.connect.fetch("select realm_id, provider_id, maintain_role " +
211
- "from sakai_realm " +
212
- "where realm_key = ?", id.to_i).first
233
+ row = DB.connect[:sakai_realm].where(:realm_key => id.to_i).first
213
234
  if row.nil?
214
235
  raise ObjectNotFoundException.new(AuthzRealm, id)
215
236
  end
216
-
217
- name = row[:realm_id]
218
- providers = row[:provider_id]
219
- maintain_role = nil
220
- if row[:maintain_role].nil? or row[:maintain_role] == ""
221
- maintain_role = nil
222
- else
223
- maintain_role = AuthzRole.find_by_id(row[:maintain_role].to_i)
224
- end
225
- @@cache[id] = AuthzRealm.new(id, name, providers, maintain_role)
226
- @@cache[name] = @@cache[id]
237
+ @@cache[id] = AuthzRealm.new(row)
238
+ @@cache[@@cache[id].name] = @@cache[id]
227
239
  end
228
240
  @@cache[id]
229
241
  end
230
242
 
231
243
  def self.find_by_name(name)
232
244
  if @@cache[name].nil?
233
- row = DB.connect.fetch("select realm_key, provider_id, maintain_role " +
234
- "from sakai_realm " +
235
- "where realm_id = ?", name).first
245
+ row = DB.connect[:sakai_realm].where(:realm_id => name).first
236
246
  if row.nil?
237
247
  raise ObjectNotFoundException.new(AuthzRealm, name)
238
248
  end
239
-
240
- id = row[:realm_key].to_i.to_s
241
- providers = row[:provider_id]
242
- maintain_role = nil
243
- if row[:maintain_role].nil? or row[:maintain_role] == ""
244
- maintain_role = nil
245
- else
246
- maintain_role = AuthzRole.find_by_id(row[:maintain_role].to_i)
247
- end
248
- @@cache[name] = AuthzRealm.new(id, name, providers, maintain_role)
249
- @@cache[id] = @@cache[name]
249
+ @@cache[name] = AuthzRealm.new(row)
250
+ @@cache[@@cache[name].id] = @@cache[name]
250
251
  end
251
252
  @@cache[name]
252
253
  end
@@ -273,6 +274,49 @@ module SakaiInfo
273
274
  def self.find_by_site_id_and_group_id(site_id, group_id)
274
275
  AuthzRealm.find_by_name("/site/#{site_id}/group/#{group_id}")
275
276
  end
277
+
278
+ def default_serialization
279
+ result = {
280
+ "id" => self.id,
281
+ "name" => self.name,
282
+ "user_count" => self.user_count,
283
+ }
284
+ if not self.providers.nil?
285
+ result["providers"] = self.providers
286
+ end
287
+ if not self.maintain_role.nil?
288
+ result["maintain_role"] = self.maintain_role.name
289
+ end
290
+ result
291
+ end
292
+
293
+ def summary_serialization
294
+ {
295
+ "id" => self.id,
296
+ "name" => self.name,
297
+ }
298
+ end
299
+
300
+ def roles_serialization
301
+ {
302
+ "roles" => self.realm_roles.collect { |rr| rr.serialize(:realm_summary) }
303
+ }
304
+ end
305
+
306
+ def users_serialization
307
+ {
308
+ "users" => self.users.collect { |u| u.serialize(:realm_summary) }
309
+ }
310
+ end
311
+
312
+ def self.all_serializations
313
+ [
314
+ :default,
315
+ :mod,
316
+ :roles,
317
+ :users,
318
+ ]
319
+ end
276
320
  end
277
321
 
278
322
  class AuthzRealmRole < SakaiObject
@@ -284,19 +328,23 @@ module SakaiInfo
284
328
  end
285
329
 
286
330
  def function_count
287
- @function_count ||= AuthzFunction.count_by_realm_id_and_role_id(@realm.id, @role.id)
331
+ @function_count ||=
332
+ AuthzFunction.count_by_realm_id_and_role_id(self.realm.id, self.role.id)
288
333
  end
289
334
 
290
335
  def functions
291
- @functions ||= AuthzFunction.find_by_realm_id_and_role_id(@realm.id, @role.id)
336
+ @functions ||=
337
+ AuthzFunction.find_by_realm_id_and_role_id(self.realm.id, self.role.id)
292
338
  end
293
339
 
294
340
  def user_count
295
- @user_count ||= User.count_by_realm_id_and_role_id(@realm.id, @role.id)
341
+ @user_count ||=
342
+ User.count_by_realm_id_and_role_id(self.realm.id, self.role.id)
296
343
  end
297
344
 
298
345
  def users
299
- @users ||= User.find_by_realm_id_and_role_id(@realm.id, @role.id)
346
+ @users ||=
347
+ User.find_by_realm_id_and_role_id(self.realm.id, self.role.id)
300
348
  end
301
349
 
302
350
  def self.find_by_realm_id(realm_id)
@@ -319,15 +367,22 @@ module SakaiInfo
319
367
  "realm_name" => self.realm.name,
320
368
  "role_name" => self.role.name,
321
369
  "user_count" => self.user_count,
322
- "function_count" => self.function_count
370
+ "function_count" => self.function_count,
323
371
  }
324
372
  end
325
373
 
326
374
  def summary_serialization
327
375
  {
328
- "role_name" => self.role.name,
376
+ "realm" => self.realm.name,
377
+ "role" => self.role.name,
378
+ }
379
+ end
380
+
381
+ def realm_summary_serialization
382
+ {
383
+ "role" => self.role.name,
329
384
  "user_count" => self.user_count,
330
- "function_count" => self.function_count
385
+ "function_count" => self.function_count,
331
386
  }
332
387
  end
333
388
  end
@@ -354,7 +409,7 @@ module SakaiInfo
354
409
  end
355
410
 
356
411
  def self.count_by_realm_id(realm_id)
357
- DB.connect[:sakai_realm_rl_gr].filter(:realm_key => realm_id).count
412
+ DB.connect[:sakai_realm_rl_gr].where(:realm_key => realm_id).count
358
413
  end
359
414
 
360
415
  def self.find_by_user_id(user_id)
@@ -369,5 +424,28 @@ module SakaiInfo
369
424
  end
370
425
  results
371
426
  end
427
+
428
+ def default_serialization
429
+ {
430
+ "realm" => self.realm.serialize(:summary),
431
+ "user" => self.user.serialize(:summary),
432
+ "role" => self.role.serialize(:summary),
433
+ }
434
+ end
435
+
436
+ def summary_serialization
437
+ {
438
+ "realm" => self.realm.name,
439
+ "user" => self.user.eid,
440
+ "role" => self.role.name,
441
+ }
442
+ end
443
+
444
+ def realm_summary_serialization
445
+ {
446
+ "user" => self.user.eid,
447
+ "role" => self.role.name,
448
+ }
449
+ end
372
450
  end
373
451
  end
@@ -2,7 +2,7 @@
2
2
  # - sakai-info command line tool support
3
3
  #
4
4
  # Created 2012-02-19 daveadams@gmail.com
5
- # Last updated 2012-05-12 daveadams@gmail.com
5
+ # Last updated 2012-05-14 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -40,6 +40,9 @@ module SakaiInfo
40
40
  "announcement-channel" => AnnouncementChannel,
41
41
  "gradebook" => Gradebook,
42
42
  "gradebook-item" => GradebookItem,
43
+ "role" => AuthzRole,
44
+ "function" => AuthzFunction,
45
+ "realm" => AuthzRealm,
43
46
  }
44
47
  end
45
48
  end
@@ -2,7 +2,7 @@
2
2
  # - sin command line help
3
3
  #
4
4
  # Created 2012-02-19 daveadams@gmail.com
5
- # Last updated 2012-05-12 daveadams@gmail.com
5
+ # Last updated 2012-05-14 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -14,14 +14,15 @@ module SakaiInfo
14
14
  class Help
15
15
  STRINGS = {
16
16
  :default => <<EOF,
17
- sin #{VERSION}
17
+ Sakai Info: sin #{VERSION}
18
18
  Usage: sin <command> [<id>] [<options>]
19
19
 
20
20
  Object commands:
21
21
  user, group, site, page, tool, quiz, quiz-section, quiz-item, quiz-attempt,
22
22
  quiz-attempt-item, quiz-attempt-item-attachment, question-pool, assignment,
23
23
  assignment-submission, forum, forum-thread, forum-post, content,
24
- announcement, announcement-channel, gradebook, gradebook-item
24
+ announcement, announcement-channel, gradebook, gradebook-item, role,
25
+ function, realm
25
26
 
26
27
  Misc commands:
27
28
  test Tests configured database connections
@@ -32,7 +33,7 @@ sin #{VERSION}
32
33
  EOF
33
34
 
34
35
  "options" => <<EOF,
35
- sin #{VERSION}
36
+ Sakai Info: sin #{VERSION}
36
37
  Options that apply globally:
37
38
  --database=<name>
38
39
  Connect to database instance <name> as defined in ~/.sakai-info instead
@@ -121,16 +122,17 @@ sin site
121
122
  Prints information about the site ID specified. Additional options may be
122
123
  passed to include additional information:
123
124
 
124
- --users Print membership information
125
- --pages Print page list with tools
126
- --groups Print group information
127
- --quizzes Print information about quizzes
128
- --disk Print disk usage
129
- --assignments Print assignment info
130
- --gradebook Print gradebook item info
131
- --realm Print site realm details
132
- --forums Print forum details
133
- --mod Print creation/modification info
125
+ --users Print membership information
126
+ --pages Print page list with tools
127
+ --groups Print group information
128
+ --quizzes Print information about quizzes
129
+ --disk Print disk usage
130
+ --assignments Print assignment info
131
+ --announcements Print announcement info
132
+ --gradebook Print gradebook item info
133
+ --realm Print site realm details
134
+ --forums Print forum details
135
+ --mod Print creation/modification info
134
136
  EOF
135
137
 
136
138
  "page" => <<EOF,
@@ -350,6 +352,32 @@ sin gradebook-item
350
352
  Usage: sin gradebook-item <id> [<options>]
351
353
 
352
354
  Prints information about the gradebook item ID specified.
355
+ EOF
356
+ "role" => <<EOF,
357
+ sin role
358
+
359
+ Usage: sin role <id> [<options>]
360
+
361
+ Prints information about the authz role ID specified.
362
+ EOF
363
+ "function" => <<EOF,
364
+ sin function
365
+
366
+ Usage: sin function <id> [<options>]
367
+
368
+ Prints information about the authz function ID specified.
369
+ EOF
370
+ "realm" => <<EOF,
371
+ sin realm
372
+
373
+ Usage: sin realm <id> [<options>]
374
+
375
+ Prints information about the authz realm ID specified. Additional options may
376
+ be passed to include additional information:
377
+
378
+ --roles List roles associated with this realm
379
+ --users List users in this realm
380
+ --mod Print creation/modification info
353
381
  EOF
354
382
  }
355
383
 
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Content library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-05-10 daveadams@gmail.com
5
+ # Last updated 2012-05-14 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -361,8 +361,12 @@ module SakaiInfo
361
361
  end
362
362
  clear_cache
363
363
 
364
+ def initialize(id)
365
+ @id = id
366
+ end
367
+
364
368
  def self.find(id)
365
- @@cache[id] ||= MissingContentCollection.new(id, nil)
369
+ @@cache[id] ||= MissingContentCollection.new(id)
366
370
  end
367
371
 
368
372
  def size_on_disk
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Site library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-05-12 daveadams@gmail.com
5
+ # Last updated 2012-05-14 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -108,12 +108,28 @@ module SakaiInfo
108
108
  end
109
109
 
110
110
  # announcement properties
111
+ def announcement_channel
112
+ if @announcement_channel.nil?
113
+ begin
114
+ @announcement_channel = AnnouncementChannel.find_by_site_id(self.id)
115
+ rescue ObjectNotFoundException
116
+ @announcement_channel = -1
117
+ return nil
118
+ end
119
+ elsif @announcement_channel == -1
120
+ return nil
121
+ end
122
+ @announcement_channel
123
+ end
124
+
111
125
  def announcements
112
- @announcements ||= AnnouncementChannel.find_by_site_id(@id).announcements
126
+ return nil if self.announcement_channel.nil?
127
+ @announcements ||= self.announcement_channel.announcements
113
128
  end
114
129
 
115
130
  def announcement_count
116
- @announcement_count ||= AnnouncementChannel.find_by_site_id(@id).announcement_count
131
+ return 0 if self.announcement_channel.nil?
132
+ @announcement_count ||= self.announcement_channel.announcement_count
117
133
  end
118
134
 
119
135
  # samigo quiz properties
@@ -252,7 +268,7 @@ module SakaiInfo
252
268
  "pending_quiz_count" => self.pending_quiz_count,
253
269
  "published_quiz_count" => self.published_quiz_count,
254
270
  "assignment_count" => self.assignment_count,
255
- # "announcement_count" => self.announcement_count,
271
+ "announcement_count" => self.announcement_count,
256
272
  "gradebook_item_count" => (self.gradebook.nil? ? 0 : self.gradebook.item_count),
257
273
  "forum_count" => self.forum_count
258
274
  }
@@ -387,8 +403,18 @@ module SakaiInfo
387
403
 
388
404
  def self.all_serializations
389
405
  [
390
- :default, :users, :pages, :groups, :quizzes, :disk, :assignments,
391
- :announcements, :gradebook, :realm, :forums
406
+ :default,
407
+ :users,
408
+ :pages,
409
+ :groups,
410
+ :quizzes,
411
+ :disk,
412
+ :assignments,
413
+ :announcements,
414
+ :gradebook,
415
+ :realm,
416
+ :forums,
417
+ :mod,
392
418
  ]
393
419
  end
394
420
  end
@@ -1,3 +1,3 @@
1
1
  module SakaiInfo
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sakai-info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-12 00:00:00.000000000 Z
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel