sakai-info 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60994547f55899b550d5e48c72db77c09c1bbd89
4
+ data.tar.gz: d661b8730e48e2804dbf1f582a845cf93784ace4
5
+ SHA512:
6
+ metadata.gz: 94d914c3ef6409b3f5ae018ddf4da9b79fb4eab75a51719834c2d06fde19670544c08a57910df55d2fc9ea96359912ad39572af33ac1a72e077d0a6f15c91135
7
+ data.tar.gz: f7bb94184d106cce1c804f454c5dba6fa6b2276f86746293d53e05e49043b4deb4dfe677c009aafb21cbe883c0ce37c23b0690a20d223da1ce2969346222e8a0
@@ -1,5 +1,18 @@
1
1
  # sakai-info Change History #
2
2
 
3
+ ### 0.5.3 ###
4
+
5
+ *Released 2013-06-28*
6
+
7
+ * Unit test cleanup, refactor, and migration to MiniTest
8
+ * Added simple tests against user/site fixture data
9
+ * Refactored and simplified rake tasks for initializing test database
10
+ * Added ability to specify alternate config file at the command line
11
+ * New method to find ContentResource by UUID
12
+ * Metaobj and Wiki support
13
+ * More graceful fails when Users, Sites, and AuthzRealms are not found
14
+ * Fixed Sequel 4.0 sql_or -> or support
15
+
3
16
  ### 0.5.2 ###
4
17
 
5
18
  *Released 2012-10-11*
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # sakai-info #
2
2
 
3
- last updated: 2012-10-11
3
+ last updated: 2013-06-28
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.5.2.gem`.
27
+ `sakai-info-0.5.3.gem`.
28
28
 
29
29
  Cleanup built gems using:
30
30
 
data/ROADMAP.md CHANGED
@@ -4,11 +4,10 @@
4
4
 
5
5
  ### 0.5.3 ###
6
6
 
7
- * Ability to specify alternate config file at the command line
7
+ * Add ability to specify Sequel connect string on command line
8
8
  * Better date formatting and proper time zone understanding
9
9
  * More query functionality
10
10
  * OSP presentation/metaobj support
11
- * Add simple tests against user/site fixture data
12
11
  * More query and shell functionality
13
12
 
14
13
  ### 0.5.4 ###
data/bin/sin CHANGED
@@ -5,7 +5,7 @@
5
5
  # sakai-info library
6
6
  #
7
7
  # Created 2012-02-15 daveadams@gmail.com
8
- # Last updated 2012-10-09 daveadams@gmail.com
8
+ # Last updated 2012-10-13 daveadams@gmail.com
9
9
  #
10
10
  # https://github.com/daveadams/sakai-info
11
11
  #
@@ -39,6 +39,10 @@ while arg = ARGV.shift
39
39
  logfile = arg.split("=")[1]
40
40
  elsif arg == "--trace"
41
41
  set_trace_func __trace
42
+ elsif arg == "-c"
43
+ DB.config_file = ARGV.shift
44
+ elsif arg =~ /^--config(-?file)?=/
45
+ DB.config_file = arg.split("=")[1]
42
46
  else
43
47
  flags << arg
44
48
  end
@@ -140,8 +144,13 @@ DB.logger = logger
140
144
 
141
145
  # load database config and set instance to the instance given on the command line
142
146
  DB.load_config
143
- if not db_name.nil?
144
- DB.default_database = db_name
147
+ begin
148
+ if not db_name.nil?
149
+ DB.default_database = db_name
150
+ end
151
+ rescue MissingConfigException => e
152
+ STDERR.puts "ERROR: database '#{db_name}' is not configured in #{DB.config_file}"
153
+ exit 1
145
154
  end
146
155
 
147
156
  case mode
@@ -2,7 +2,7 @@
2
2
  # Base library file
3
3
  #
4
4
  # Created 2012-02-15 daveadams@gmail.com
5
- # Last updated 2012-10-11 daveadams@gmail.com
5
+ # Last updated 2012-10-15 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -47,4 +47,6 @@ require 'sakai-info/generic_message'
47
47
  require 'sakai-info/forum'
48
48
  require 'sakai-info/private_message'
49
49
  require 'sakai-info/alias'
50
+ require 'sakai-info/metaobj'
51
+ require 'sakai-info/wiki'
50
52
 
@@ -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-14 daveadams@gmail.com
5
+ # Last updated 2012-10-25 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -267,6 +267,18 @@ module SakaiInfo
267
267
  realm
268
268
  end
269
269
 
270
+ def self.find!(id_or_name)
271
+ begin
272
+ realm = AuthzRealm.find(id_or_name)
273
+ rescue ObjectNotFoundException => e
274
+ if e.classname == AuthzRealm.name
275
+ realm = MissingAuthzRealm.find(id_or_name)
276
+ end
277
+ end
278
+ realm
279
+ end
280
+
281
+
270
282
  def self.find_by_site_id(site_id)
271
283
  AuthzRealm.find_by_name("/site/#{site_id}")
272
284
  end
@@ -319,6 +331,54 @@ module SakaiInfo
319
331
  end
320
332
  end
321
333
 
334
+ class MissingAuthzRealm < AuthzRealm
335
+ def self.clear_cache
336
+ @@cache = {}
337
+ end
338
+ clear_cache
339
+
340
+ def initialize(id)
341
+ @dbrow = {}
342
+
343
+ @dbrow = {}
344
+
345
+ @id = id
346
+ @name = id
347
+ @providers = nil
348
+ @maintain_role = nil
349
+ end
350
+
351
+ def self.find(id)
352
+ @@cache[id] ||= MissingAuthzRealm.new(id)
353
+ end
354
+
355
+ def realm_roles
356
+ []
357
+ end
358
+
359
+ def users
360
+ []
361
+ end
362
+
363
+ def default_serialization
364
+ {
365
+ "id" => "MISSING REALM: #{self.id}",
366
+ }
367
+ end
368
+
369
+ def summary_serialization
370
+ {
371
+ "id" => "MISSING REALM: #{self.id}",
372
+ }
373
+ end
374
+
375
+ def self.all_serializations
376
+ [
377
+ :default,
378
+ ]
379
+ end
380
+ end
381
+
322
382
  class AuthzRealmRole < SakaiObject
323
383
  attr_reader :realm, :role
324
384
 
@@ -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-10-11 daveadams@gmail.com
5
+ # Last updated 2012-10-31 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -29,7 +29,8 @@ Sakai INfo: sin #{VERSION}
29
29
  quiz-attempt-item-attachment, question-pool, assignment,
30
30
  assignment-submission, forum, forum-thread, forum-post, content,
31
31
  announcement, announcement-channel, gradebook, gradebook-item,
32
- role, function, realm, private-message, alias
32
+ role, function, realm, private-message, alias, metaobj,
33
+ wiki-page, wiki-page-history
33
34
 
34
35
  QUERY MODE
35
36
  Query particular fields from certain objects given certain conditions.
@@ -481,6 +482,41 @@ sin alias
481
482
  passed to include additional information:
482
483
 
483
484
  --mod Print creation/modification info
485
+ EOF
486
+ "metaobj" => <<EOF,
487
+ sin metaobj
488
+
489
+ Usage: sin metaobj <id> [<options>]
490
+
491
+ Prints information about the metaobj/form ID specified. Additional options
492
+ may be passed to include additional information:
493
+
494
+ --instructions Include form instruction text
495
+ --schemadata Include schemadata field
496
+ --mod Print creation/modification info
497
+ EOF
498
+ "wiki-page" => <<EOF,
499
+ sin wiki-page
500
+
501
+ Usage: sin wiki-page <id> [<options>]
502
+
503
+ Prints information about the wiki page ID specified. Additional options may
504
+ be passed to include additional information:
505
+
506
+ --content Include content of the wiki page itself
507
+ --permissions Break out permissions individually
508
+ --history Summarize revision history
509
+ EOF
510
+ "wiki-page-history" => <<EOF,
511
+ sin wiki-page-history
512
+
513
+ Usage: sin wiki-page-history <id> [<options>]
514
+
515
+ Prints information about the wiki page history ID specified. Additional
516
+ options may be passed to include additional information:
517
+
518
+ --content Include content of the wiki page itself
519
+ --permissions Break out permissions individually
484
520
  EOF
485
521
  "query" => <<EOF,
486
522
  sin query
@@ -2,7 +2,7 @@
2
2
  # class for handling the default command line mode
3
3
  #
4
4
  # Created 2012-05-23 daveadams@gmail.com
5
- # Last updated 2012-10-11 daveadams@gmail.com
5
+ # Last updated 2012-10-31 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -138,6 +138,12 @@ module SakaiInfo
138
138
  "private-message" => PrivateMessage,
139
139
  "pm" => PrivateMessage,
140
140
  "alias" => Alias,
141
+ "metaobj" => Metaobj,
142
+ "form" => Metaobj,
143
+ "wiki-page" => WikiPage,
144
+ "wiki" => WikiPage,
145
+ "wiki-page-history" => WikiPageHistory,
146
+ "wiki-history" => WikiPageHistory,
141
147
  }
142
148
  end
143
149
  end
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Content library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-10-04 daveadams@gmail.com
5
+ # Last updated 2012-10-19 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -157,6 +157,7 @@ module SakaiInfo
157
157
 
158
158
  def self.clear_cache
159
159
  @@cache = {}
160
+ @@uuid_cache = {}
160
161
  end
161
162
  clear_cache
162
163
 
@@ -182,10 +183,23 @@ module SakaiInfo
182
183
  raise ObjectNotFoundException.new(ContentResource, id)
183
184
  end
184
185
  @@cache[id] = ContentResource.new(row)
186
+ @@uuid_cache[row[:uuid]] = @@cache[id]
185
187
  end
186
188
  @@cache[id]
187
189
  end
188
190
 
191
+ def self.find_by_uuid(uuid)
192
+ if @@uuid_cache[uuid].nil?
193
+ row = DB.connect[:content_resource].where(:resource_uuid => uuid).first
194
+ if row.nil?
195
+ raise ObjectNotFoundException.new(ContentResource, uuid)
196
+ end
197
+ @@uuid_cache[uuid] = ContentResource.new(row)
198
+ @@cache[row[:resource_id]] = @@uuid_cache[uuid]
199
+ end
200
+ @@uuid_cache[uuid]
201
+ end
202
+
189
203
  def size_on_disk
190
204
  @file_size
191
205
  end
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Database library
3
3
  #
4
4
  # Created 2012-02-19 daveadams@gmail.com
5
- # Last updated 2012-05-04 daveadams@gmail.com
5
+ # Last updated 2012-10-13 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -48,12 +48,22 @@ ENV["NLS_LANG"] ||= "AMERICAN_AMERICA.UTF8"
48
48
 
49
49
  module SakaiInfo
50
50
  class InvalidConfigException < SakaiException; end
51
+ class MissingConfigException < SakaiException; end
51
52
  class ConnectionFailureException < SakaiException; end
52
53
 
53
54
  class DB
54
55
  DEFAULT_CONFIG_FILE = File.expand_path("~/.sakai-info")
55
56
  @@default_database_name = nil
56
57
  @@config = nil
58
+ @@config_file = DEFAULT_CONFIG_FILE
59
+
60
+ def self.config_file=(newfile)
61
+ @@config_file = newfile
62
+ end
63
+
64
+ def self.config_file
65
+ @@config_file
66
+ end
57
67
 
58
68
  def self.configure(config)
59
69
  begin
@@ -100,11 +110,11 @@ module SakaiInfo
100
110
  end
101
111
  end
102
112
 
103
- def self.load_config
104
- if File.readable? DEFAULT_CONFIG_FILE
105
- DB.configure(DEFAULT_CONFIG_FILE)
113
+ def self.load_config(config_file = DB.config_file)
114
+ if File.readable? config_file
115
+ DB.configure(config_file)
106
116
  else
107
- raise MissingConfigException.new("No config file found at #{DEFAULT_CONFIG_FILE}")
117
+ raise MissingConfigException.new("No config file found at #{config_file}")
108
118
  end
109
119
  end
110
120
 
@@ -135,6 +145,9 @@ module SakaiInfo
135
145
 
136
146
  def self.default_database=(database_name)
137
147
  @@default_database_name = database_name
148
+ # spin it up so that we throw a missing config exception if it's invalid
149
+ DB.connect(@@default_database_name)
150
+ @@default_database_name
138
151
  end
139
152
 
140
153
  # set global logger
@@ -154,7 +167,10 @@ module SakaiInfo
154
167
 
155
168
  class Database
156
169
  def initialize(connect_info, logger = nil)
157
- @connect_info=connect_info
170
+ if connect_info.nil?
171
+ raise MissingConfigException.new("No configuration was provided")
172
+ end
173
+ @connect_info = connect_info
158
174
  @logger = logger
159
175
  end
160
176
 
@@ -2,7 +2,7 @@
2
2
  # Special exception definitions
3
3
  #
4
4
  # Created 2012-05-20 daveadams@gmail.com
5
- # Last updated 2012-05-20 daveadams@gmail.com
5
+ # Last updated 2012-10-25 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -16,11 +16,15 @@ module SakaiInfo
16
16
 
17
17
  # exception to be raised when an object of a certain type cannot be found
18
18
  class ObjectNotFoundException < SakaiException
19
- def initialize(classname, identifier)
20
- @classname = classname
19
+ def initialize(missing_class, identifier)
20
+ @missing_class = missing_class
21
21
  @identifier = identifier
22
22
 
23
- super("Could not find a #{@classname} object for '#{@identifier}'")
23
+ super("Could not find a #{@missing_class.name} object for '#{@identifier}'")
24
+ end
25
+
26
+ def classname
27
+ @missing_class.name
24
28
  end
25
29
  end
26
30
  end
@@ -0,0 +1,197 @@
1
+ # sakai-info/metaobj.rb
2
+ # SakaiInfo::Metaobj library (OSP form support)
3
+ #
4
+ # Created 2012-10-15 daveadams@gmail.com
5
+ # Last updated 2012-10-23 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 Metaobj < SakaiObject
14
+ attr_reader :dbrow, :description, :external_type, :schema_hash
15
+
16
+ include ModProps
17
+ created_by_key :owner
18
+ created_at_key :created
19
+ modified_by_key :owner
20
+ modified_at_key :modified
21
+
22
+ def self.clear_cache
23
+ @@cache = {}
24
+ end
25
+ clear_cache
26
+
27
+ def initialize(dbrow)
28
+ @dbrow = dbrow
29
+
30
+ @id = dbrow[:id]
31
+ @description = dbrow[:description]
32
+ @external_type = dbrow[:externaltype]
33
+ @schema_hash = dbrow[:schema_hash]
34
+ end
35
+
36
+ def self.find(id)
37
+ if @@cache[id].nil?
38
+ row = DB.connect[:metaobj_form_def].filter(:id => id).first
39
+ if row.nil?
40
+ raise ObjectNotFoundException.new(Metaobj, id)
41
+ end
42
+ @@cache[id] = Metaobj.new(row)
43
+ end
44
+ @@cache[id]
45
+ end
46
+
47
+ def owner
48
+ @owner ||= User.find(@dbrow[:owner])
49
+ end
50
+
51
+ def system_only?
52
+ @dbrow[:systemonly] == 1
53
+ end
54
+
55
+ def site
56
+ if @dbrow[:siteid]
57
+ begin
58
+ @site ||= Site.find(@dbrow[:siteid])
59
+ rescue ObjectNotFoundException
60
+ nil
61
+ end
62
+ else
63
+ nil
64
+ end
65
+ end
66
+
67
+ def site_state
68
+ case @dbrow[:sitestate]
69
+ when 0
70
+ "unpublished"
71
+ when 2
72
+ "published"
73
+ else
74
+ @dbrow[:sitestate]
75
+ end
76
+ end
77
+
78
+ def published?
79
+ self.site_state == "published"
80
+ end
81
+
82
+ def global_state
83
+ case @dbrow[:globalstate]
84
+ when 0
85
+ "unpublished"
86
+ when 1
87
+ "pending approval"
88
+ when 2
89
+ "published"
90
+ else
91
+ @dbrow[:globalstate]
92
+ end
93
+ end
94
+
95
+ def globally_published?
96
+ self.global_state == "published"
97
+ end
98
+
99
+ def pending_approval?
100
+ self.global_state == "pending approval"
101
+ end
102
+
103
+ def alternate_create_xslt
104
+ if @dbrow[:alternatecreatexslt].nil?
105
+ nil
106
+ else
107
+ @@alternate_create_xslt ||= ContentResource.find_by_uuid(@dbrow[:alternatecreatexslt])
108
+ end
109
+ end
110
+
111
+ def alternate_view_xslt
112
+ if @dbrow[:alternateviewxslt].nil?
113
+ nil
114
+ else
115
+ @@alternate_view_xslt ||= ContentResource.find_by_uuid(@dbrow[:alternateviewxslt])
116
+ end
117
+ end
118
+
119
+ def instructions
120
+ if @dbrow[:instructions].nil?
121
+ nil
122
+ else
123
+ @instructions ||= @dbrow[:instruction].read
124
+ end
125
+ end
126
+
127
+ def schemadata
128
+ @schemadata ||= @dbrow[:schemadata].read.force_encoding(Encoding::UTF_8)
129
+ end
130
+
131
+ # serialization
132
+ def default_serialization
133
+ result = {
134
+ "id" => self.id,
135
+ "description" => self.description,
136
+ "owner" => self.owner.serialize(:summary),
137
+ "site" => nil,
138
+ "system_only" => self.system_only?,
139
+ "published" => self.published?,
140
+ "globally_published" => self.globally_published?,
141
+ "pending_approval" => self.pending_approval?,
142
+ "external_type" => self.external_type,
143
+ "alternate_create_xslt" => nil,
144
+ "alternate_view_xslt" => nil,
145
+ "schema_hash" => self.schema_hash,
146
+ }
147
+ if self.site.nil?
148
+ result.delete("site")
149
+ else
150
+ result["site"] = self.site.serialize(:summary)
151
+ end
152
+ if not self.pending_approval?
153
+ result.delete("pending_approval")
154
+ end
155
+ if self.alternate_create_xslt.nil?
156
+ result.delete("alternate_create_xslt")
157
+ else
158
+ result["alternate_create_xslt"] = self.alternate_create_xslt.serialize(:summary)
159
+ end
160
+ if self.alternate_view_xslt.nil?
161
+ result.delete("alternate_view_xslt")
162
+ else
163
+ result["alternate_view_xslt"] = self.alternate_view_xslt.serialize(:summary)
164
+ end
165
+ result
166
+ end
167
+
168
+ def summary_serialization
169
+ {
170
+ "id" => self.id,
171
+ "description" => self.description,
172
+ "owner" => self.owner.eid,
173
+ }
174
+ end
175
+
176
+ def instructions_serialization
177
+ {
178
+ "instructions" => self.instructions,
179
+ }
180
+ end
181
+
182
+ def schemadata_serialization
183
+ {
184
+ "schemadata" => self.schemadata,
185
+ }
186
+ end
187
+
188
+ def self.all_serializations
189
+ [
190
+ :default,
191
+ :mod,
192
+ :instructions,
193
+ :schemadata,
194
+ ]
195
+ end
196
+ end
197
+ end
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Site library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-10-06 daveadams@gmail.com
5
+ # Last updated 2012-10-25 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -36,6 +36,17 @@ module SakaiInfo
36
36
  @@cache[id]
37
37
  end
38
38
 
39
+ def self.find!(id)
40
+ begin
41
+ site = Site.find(id)
42
+ rescue ObjectNotFoundException => e
43
+ if e.classname == Site.name
44
+ site = MissingSite.find(id)
45
+ end
46
+ end
47
+ site
48
+ end
49
+
39
50
  def initialize(dbrow)
40
51
  @dbrow = dbrow
41
52
 
@@ -432,6 +443,41 @@ module SakaiInfo
432
443
  end
433
444
  end
434
445
 
446
+ class MissingSite < Site
447
+ def self.clear_cache
448
+ @@cache = {}
449
+ end
450
+ clear_cache
451
+
452
+ def initialize(id)
453
+ @dbrow = {}
454
+
455
+ @id = id
456
+ end
457
+
458
+ def self.find(id)
459
+ @@cache[id] ||= MissingSite.new(id)
460
+ end
461
+
462
+ def default_serialization
463
+ {
464
+ "id" => "MISSING SITE: #{self.id}",
465
+ }
466
+ end
467
+
468
+ def summary_serialization
469
+ {
470
+ "id" => "MISSING SITE: #{self.id}",
471
+ }
472
+ end
473
+
474
+ def self.all_serializations
475
+ [
476
+ :default,
477
+ ]
478
+ end
479
+ end
480
+
435
481
  class SiteProperty
436
482
  def self.get(site_id, property_name)
437
483
  row = DB.connect[:sakai_site_property].
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::User library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-10-06 daveadams@gmail.com
5
+ # Last updated 2012-10-25 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -45,9 +45,19 @@ module SakaiInfo
45
45
  @@cache[id]
46
46
  end
47
47
 
48
+ def self.find!(id)
49
+ begin
50
+ user = User.find(id)
51
+ rescue ObjectNotFoundException => e
52
+ if e.classname == User.name
53
+ user = MissingUser.find(id)
54
+ end
55
+ end
56
+ end
57
+
48
58
  def self.get_ids(id)
49
59
  @@id_cache[id] ||=
50
- DB.connect[:sakai_user_id_map].where({:user_id => id, :eid => id}.sql_or).first
60
+ DB.connect[:sakai_user_id_map].where(:user_id => id).or(:eid => id).first
51
61
  end
52
62
 
53
63
  def self.get_eid(id)
@@ -240,6 +250,42 @@ module SakaiInfo
240
250
  end
241
251
  end
242
252
 
253
+ class MissingUser < User
254
+ def self.clear_cache
255
+ @@cache = {}
256
+ end
257
+ clear_cache
258
+
259
+ def initialize(id)
260
+ @dbrow = {}
261
+
262
+ @id = id
263
+ @eid = id
264
+ end
265
+
266
+ def self.find(id)
267
+ @@cache[id] ||= MissingUser.new(id)
268
+ end
269
+
270
+ def default_serialization
271
+ {
272
+ "id" => "MISSING USER: #{self.id}",
273
+ }
274
+ end
275
+
276
+ def summary_serialization
277
+ {
278
+ "id" => "MISSING USER: #{self.id}",
279
+ }
280
+ end
281
+
282
+ def self.all_serializations
283
+ [
284
+ :default,
285
+ ]
286
+ end
287
+ end
288
+
243
289
  class UserProperty
244
290
  def self.get(user_id, property_name)
245
291
  row = DB.connect[:sakai_user_property].
@@ -1,3 +1,3 @@
1
1
  module SakaiInfo
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -0,0 +1,288 @@
1
+ # sakai-info/wiki.rb
2
+ # SakaiInfo::Wiki library
3
+ #
4
+ # Created 2012-10-23 daveadams@gmail.com
5
+ # Last updated 2012-10-31 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 WikiPage < SakaiObject
14
+ attr_reader :dbrow
15
+
16
+ def self.clear_cache
17
+ @@cache = {}
18
+ end
19
+ clear_cache
20
+
21
+ def initialize(dbrow)
22
+ @dbrow = dbrow
23
+
24
+ @id = dbrow[:id]
25
+ end
26
+
27
+ def self.find(id)
28
+ if @@cache[id].nil?
29
+ row = DB.connect[:rwikiobject].filter(:id => id).first
30
+ if row.nil?
31
+ raise ObjectNotFoundException.new(WikiPage, id)
32
+ end
33
+ @@cache[id] = WikiPage.new(row)
34
+ end
35
+ @@cache[id]
36
+ end
37
+
38
+ def last_updated
39
+ @dbrow[:version]
40
+ end
41
+
42
+ def revision
43
+ @dbrow[:revision]
44
+ end
45
+
46
+ def owner
47
+ @owner ||= User.find!(@dbrow[:owner])
48
+ end
49
+
50
+ def last_updated_by
51
+ @updated_by ||= User.find!(@dbrow[:userid])
52
+ end
53
+
54
+ def realm
55
+ if not self.realm_name.nil?
56
+ @realm ||= AuthzRealm.find!(self.realm_name)
57
+ end
58
+ end
59
+
60
+ def realm_name
61
+ @dbrow[:realm]
62
+ end
63
+
64
+ def site_id
65
+ @site_id ||= if not self.realm_name.nil?
66
+ if self.realm_name =~ /^\/site\/([^\/]+)/
67
+ $1
68
+ else
69
+ nil
70
+ end
71
+ else
72
+ nil
73
+ end
74
+ end
75
+
76
+ def site
77
+ @site ||= if not self.site_id.nil?
78
+ Site.find!(self.site_id)
79
+ else
80
+ nil
81
+ end
82
+ end
83
+
84
+ def page_name
85
+ @page_name ||= if not self.realm_name.nil?
86
+ if @dbrow[:name] =~ /^#{self.realm_name}\/(.+)$/
87
+ $1
88
+ else
89
+ @dbrow[:name]
90
+ end
91
+ end
92
+ end
93
+
94
+ def owner_readable?
95
+ @dbrow[:ownerread] == 1
96
+ end
97
+
98
+ def owner_writable?
99
+ @dbrow[:ownerwrite] == 1
100
+ end
101
+
102
+ def owner_admin?
103
+ @dbrow[:owneradmin] == 1
104
+ end
105
+
106
+ def group_readable?
107
+ @dbrow[:groupread] == 1
108
+ end
109
+
110
+ def group_writable?
111
+ @dbrow[:groupwrite] == 1
112
+ end
113
+
114
+ def group_admin?
115
+ @dbrow[:groupadmin] == 1
116
+ end
117
+
118
+ def public_readable?
119
+ @dbrow[:publicread] == 1
120
+ end
121
+
122
+ def public_writable?
123
+ @dbrow[:publicwrite] == 1
124
+ end
125
+
126
+ def permission_string
127
+ (self.owner_readable? ? "r" : "-") +
128
+ (self.owner_writable? ? "w" : "-") +
129
+ (self.owner_admin? ? "A" : "-") +
130
+ (self.group_readable? ? "r" : "-") +
131
+ (self.group_writable? ? "w" : "-") +
132
+ (self.group_admin? ? "A" : "-") +
133
+ (self.public_readable? ? "r" : "-") +
134
+ (self.public_writable? ? "w" : "-") +
135
+ "-"
136
+ end
137
+
138
+ def content
139
+ @content ||= DB.connect[:rwikicurrentcontent].where(:rwikiid => self.id).first[:content].read
140
+ end
141
+
142
+ def history
143
+ @history ||= WikiPageHistory.find_by_wiki_page_id(self.id)
144
+ end
145
+
146
+ # serialization
147
+ def default_serialization
148
+ result = {
149
+ "id" => self.id,
150
+ "page_name" => self.page_name,
151
+ "realm" => self.realm.serialize(:summary),
152
+ "owner" => self.owner.eid,
153
+ "last_updated_by" => self.last_updated_by.eid,
154
+ "last_updated" => self.last_updated,
155
+ "site" => self.site.serialize(:summary),
156
+ "permissions" => self.permission_string,
157
+ "revision" => self.revision,
158
+ }
159
+ result
160
+ end
161
+
162
+ def summary_serialization
163
+ {
164
+ "id" => self.id,
165
+ "name" => self.name,
166
+ "owner" => self.owner.eid,
167
+ "site_id" => self.site_id,
168
+ }
169
+ end
170
+
171
+ def history_summary_serialization
172
+ {
173
+ "id" => self.id,
174
+ "last_updated" => self.last_updated,
175
+ "last_updated_by" => self.last_updated_by.eid,
176
+ }
177
+ end
178
+
179
+ def permissions_serialization
180
+ {
181
+ "permissions" => {
182
+ "owner" => {
183
+ "read" => self.owner_readable?,
184
+ "write" => self.owner_writable?,
185
+ "admin" => self.owner_admin?,
186
+ },
187
+ "group" => {
188
+ "read" => self.group_readable?,
189
+ "write" => self.group_writable?,
190
+ "admin" => self.group_admin?,
191
+ },
192
+ "public" => {
193
+ "read" => self.public_readable?,
194
+ "write" => self.public_writable?,
195
+ }
196
+ }
197
+ }
198
+ end
199
+
200
+ def history_serialization
201
+ result = {
202
+ "history" => self.history.collect { |r| r.serialize(:history) },
203
+ }
204
+ if result["history"] == []
205
+ result = {}
206
+ end
207
+ result
208
+ end
209
+
210
+ def content_serialization
211
+ {
212
+ "content" => self.content,
213
+ }
214
+ end
215
+
216
+ def self.all_serializations
217
+ [
218
+ :default,
219
+ :permissions,
220
+ :content,
221
+ :history,
222
+ ]
223
+ end
224
+ end
225
+
226
+ class WikiPageHistory < WikiPage
227
+ def self.clear_cache
228
+ @@cache = {}
229
+ end
230
+ clear_cache
231
+
232
+ def self.find(id)
233
+ if @@cache[id].nil?
234
+ row = DB.connect[:rwikihistory].filter(:id => id).first
235
+ if row.nil?
236
+ raise ObjectNotFoundException.new(WikiPageHistory, id)
237
+ end
238
+ @@cache[id] = WikiPageHistory.new(row)
239
+ end
240
+ @@cache[id]
241
+ end
242
+
243
+ def content
244
+ @content ||= DB.connect[:rwikihistorycontent].where(:rwikiid => self.id).first[:content].read
245
+ end
246
+
247
+ def wiki_page_id
248
+ @dbrow[:rwikiobjectid]
249
+ end
250
+
251
+ def wiki_page
252
+ @wiki_page ||= WikiPage.find(self.wiki_page_id)
253
+ end
254
+
255
+ def self.find_by_wiki_page_id(id)
256
+ results = []
257
+ DB.connect[:rwikihistory].filter(:rwikiobjectid => id).
258
+ order(:revision).all.collect do |row|
259
+ @@cache[row[:id]] = WikiPageHistory.new(row)
260
+ results << @@cache[row[:id]]
261
+ end
262
+ results
263
+ end
264
+
265
+ def default_serialization
266
+ result = super
267
+ result["current_version"] = self.wiki_page.serialize(:history_summary)
268
+ result
269
+ end
270
+
271
+ def history_serialization
272
+ {
273
+ "id" => self.id,
274
+ "revision" => self.revision,
275
+ "last_updated" => self.last_updated,
276
+ "last_updated_by" => self.last_updated_by.eid,
277
+ }
278
+ end
279
+
280
+ def self.all_serializations
281
+ [
282
+ :default,
283
+ :permissions,
284
+ :content,
285
+ ]
286
+ end
287
+ end
288
+ end
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sakai-info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
5
- prerelease:
4
+ version: 0.5.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - David Adams
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-11 00:00:00.000000000 Z
11
+ date: 2013-06-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: sequel
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sqlite3
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: marky_markov
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: A command line tool and a suite of libraries for representing the objects
@@ -68,37 +61,39 @@ extensions: []
68
61
  extra_rdoc_files: []
69
62
  files:
70
63
  - lib/sakai-info.rb
71
- - lib/sakai-info/alias.rb
72
- - lib/sakai-info/util.rb
73
- - lib/sakai-info/group.rb
74
- - lib/sakai-info/private_message.rb
75
- - lib/sakai-info/tool.rb
76
- - lib/sakai-info/cli/help.rb
77
- - lib/sakai-info/cli/query.rb
78
- - lib/sakai-info/cli/special.rb
79
- - lib/sakai-info/cli/shell.rb
80
- - lib/sakai-info/cli/lookup.rb
81
- - lib/sakai-info/site.rb
82
- - lib/sakai-info/cache.rb
64
+ - lib/sakai-info/wiki.rb
83
65
  - lib/sakai-info/exceptions.rb
84
- - lib/sakai-info/assignment.rb
85
66
  - lib/sakai-info/authz.rb
86
- - lib/sakai-info/gradebook.rb
87
- - lib/sakai-info/mod_props.rb
88
67
  - lib/sakai-info/forum.rb
89
- - lib/sakai-info/sakai_object.rb
90
- - lib/sakai-info/quiz.rb
91
- - lib/sakai-info/user.rb
92
- - lib/sakai-info/hacks.rb
68
+ - lib/sakai-info/metaobj.rb
93
69
  - lib/sakai-info/version.rb
94
- - lib/sakai-info/announcement.rb
95
- - lib/sakai-info/database.rb
96
70
  - lib/sakai-info/cli.rb
97
- - lib/sakai-info/question_pool.rb
71
+ - lib/sakai-info/group.rb
72
+ - lib/sakai-info/quiz.rb
73
+ - lib/sakai-info/mod_props.rb
74
+ - lib/sakai-info/gradebook.rb
75
+ - lib/sakai-info/util.rb
76
+ - lib/sakai-info/assignment.rb
77
+ - lib/sakai-info/private_message.rb
78
+ - lib/sakai-info/sakai_xml_entity.rb
79
+ - lib/sakai-info/database.rb
98
80
  - lib/sakai-info/generic_message.rb
99
- - lib/sakai-info/content.rb
81
+ - lib/sakai-info/sakai_object.rb
100
82
  - lib/sakai-info/page.rb
101
- - lib/sakai-info/sakai_xml_entity.rb
83
+ - lib/sakai-info/user.rb
84
+ - lib/sakai-info/announcement.rb
85
+ - lib/sakai-info/site.rb
86
+ - lib/sakai-info/content.rb
87
+ - lib/sakai-info/hacks.rb
88
+ - lib/sakai-info/alias.rb
89
+ - lib/sakai-info/cli/lookup.rb
90
+ - lib/sakai-info/cli/help.rb
91
+ - lib/sakai-info/cli/special.rb
92
+ - lib/sakai-info/cli/query.rb
93
+ - lib/sakai-info/cli/shell.rb
94
+ - lib/sakai-info/tool.rb
95
+ - lib/sakai-info/cache.rb
96
+ - lib/sakai-info/question_pool.rb
102
97
  - bin/sin
103
98
  - README.md
104
99
  - LICENSE
@@ -107,26 +102,25 @@ files:
107
102
  homepage: https://github.com/daveadams/sakai-info
108
103
  licenses:
109
104
  - Public Domain
105
+ metadata: {}
110
106
  post_install_message:
111
107
  rdoc_options: []
112
108
  require_paths:
113
109
  - lib
114
110
  required_ruby_version: !ruby/object:Gem::Requirement
115
- none: false
116
111
  requirements:
117
- - - ! '>='
112
+ - - '>='
118
113
  - !ruby/object:Gem::Version
119
114
  version: '0'
120
115
  required_rubygems_version: !ruby/object:Gem::Requirement
121
- none: false
122
116
  requirements:
123
- - - ! '>='
117
+ - - '>='
124
118
  - !ruby/object:Gem::Version
125
119
  version: '0'
126
120
  requirements: []
127
121
  rubyforge_project:
128
- rubygems_version: 1.8.23
122
+ rubygems_version: 2.0.0
129
123
  signing_key:
130
- specification_version: 3
124
+ specification_version: 4
131
125
  summary: Tools and library for exploring a Sakai database
132
126
  test_files: []