Class: SakaiInfo::WikiPage

Inherits:
SakaiObject show all
Defined in:
lib/sakai-info/wiki.rb

Direct Known Subclasses

WikiPageHistory

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SakaiObject

#dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml

Constructor Details

#initialize(dbrow) ⇒ WikiPage

Returns a new instance of WikiPage.



21
22
23
24
25
# File 'lib/sakai-info/wiki.rb', line 21

def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:id]
end

Instance Attribute Details

#dbrowObject (readonly)

Returns the value of attribute dbrow.



14
15
16
# File 'lib/sakai-info/wiki.rb', line 14

def dbrow
  @dbrow
end

Class Method Details

.all_serializationsObject



216
217
218
219
220
221
222
223
# File 'lib/sakai-info/wiki.rb', line 216

def self.all_serializations
  [
   :default,
   :permissions,
   :content,
   :history,
  ]
end

.clear_cacheObject



16
17
18
# File 'lib/sakai-info/wiki.rb', line 16

def self.clear_cache
  @@cache = {}
end

.find(id) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/sakai-info/wiki.rb', line 27

def self.find(id)
  if @@cache[id].nil?
    row = DB.connect[:rwikiobject].filter(:id => id).first
    if row.nil?
      raise ObjectNotFoundException.new(WikiPage, id)
    end
    @@cache[id] = WikiPage.new(row)
  end
  @@cache[id]
end

Instance Method Details

#contentObject



138
139
140
# File 'lib/sakai-info/wiki.rb', line 138

def content
  @content ||= DB.connect[:rwikicurrentcontent].where(:rwikiid => self.id).first[:content].read
end

#content_serializationObject



210
211
212
213
214
# File 'lib/sakai-info/wiki.rb', line 210

def content_serialization
  {
    "content" => self.content,
  }
end

#default_serializationObject

serialization



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/sakai-info/wiki.rb', line 147

def default_serialization
  result = {
    "id" => self.id,
    "page_name" => self.page_name,
    "realm" => self.realm.serialize(:summary),
    "owner" => self.owner.eid,
    "last_updated_by" => self.last_updated_by.eid,
    "last_updated" => self.last_updated,
    "site" => self.site.serialize(:summary),
    "permissions" => self.permission_string,
    "revision" => self.revision,
  }
  result
end

#group_admin?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/sakai-info/wiki.rb', line 114

def group_admin?
  @dbrow[:groupadmin] == 1
end

#group_readable?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/sakai-info/wiki.rb', line 106

def group_readable?
  @dbrow[:groupread] == 1
end

#group_writable?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/sakai-info/wiki.rb', line 110

def group_writable?
  @dbrow[:groupwrite] == 1
end

#historyObject



142
143
144
# File 'lib/sakai-info/wiki.rb', line 142

def history
  @history ||= WikiPageHistory.find_by_wiki_page_id(self.id)
end

#history_serializationObject



200
201
202
203
204
205
206
207
208
# File 'lib/sakai-info/wiki.rb', line 200

def history_serialization
  result = {
    "history" => self.history.collect { |r| r.serialize(:history) },
  }
  if result["history"] == []
    result = {}
  end
  result
end

#history_summary_serializationObject



171
172
173
174
175
176
177
# File 'lib/sakai-info/wiki.rb', line 171

def history_summary_serialization
  {
    "id" => self.id,
    "last_updated" => self.last_updated,
    "last_updated_by" => self.last_updated_by.eid,
  }
end

#last_updatedObject



38
39
40
# File 'lib/sakai-info/wiki.rb', line 38

def last_updated
  @dbrow[:version]
end

#last_updated_byObject



50
51
52
# File 'lib/sakai-info/wiki.rb', line 50

def last_updated_by
  @updated_by ||= User.find!(@dbrow[:userid])
end

#ownerObject



46
47
48
# File 'lib/sakai-info/wiki.rb', line 46

def owner
  @owner ||= User.find!(@dbrow[:owner])
end

#owner_admin?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/sakai-info/wiki.rb', line 102

def owner_admin?
  @dbrow[:owneradmin] == 1
end

#owner_readable?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/sakai-info/wiki.rb', line 94

def owner_readable?
  @dbrow[:ownerread] == 1
end

#owner_writable?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/sakai-info/wiki.rb', line 98

def owner_writable?
  @dbrow[:ownerwrite] == 1
end

#page_nameObject



84
85
86
87
88
89
90
91
92
# File 'lib/sakai-info/wiki.rb', line 84

def page_name
  @page_name ||= if not self.realm_name.nil?
                   if @dbrow[:name] =~ /^#{self.realm_name}\/(.+)$/
                     $1
                   else
                     @dbrow[:name]
                   end
                 end
end

#permission_stringObject



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/sakai-info/wiki.rb', line 126

def permission_string
  (self.owner_readable? ? "r" : "-") +
    (self.owner_writable? ? "w" : "-") +
    (self.owner_admin? ? "A" : "-") +
    (self.group_readable? ? "r" : "-") +
    (self.group_writable? ? "w" : "-") +
    (self.group_admin? ? "A" : "-") +
    (self.public_readable? ? "r" : "-") +
    (self.public_writable? ? "w" : "-") +
    "-"
end

#permissions_serializationObject



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/sakai-info/wiki.rb', line 179

def permissions_serialization
  {
    "permissions" => {
      "owner" => {
        "read" => self.owner_readable?,
        "write" => self.owner_writable?,
        "admin" => self.owner_admin?,
      },
      "group" => {
        "read" => self.group_readable?,
        "write" => self.group_writable?,
        "admin" => self.group_admin?,
      },
      "public" => {
        "read" => self.public_readable?,
        "write" => self.public_writable?,
      }
    }
  }
end

#public_readable?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/sakai-info/wiki.rb', line 118

def public_readable?
  @dbrow[:publicread] == 1
end

#public_writable?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/sakai-info/wiki.rb', line 122

def public_writable?
  @dbrow[:publicwrite] == 1
end

#realmObject



54
55
56
57
58
# File 'lib/sakai-info/wiki.rb', line 54

def realm
  if not self.realm_name.nil?
    @realm ||= AuthzRealm.find!(self.realm_name)
  end
end

#realm_nameObject



60
61
62
# File 'lib/sakai-info/wiki.rb', line 60

def realm_name
  @dbrow[:realm]
end

#revisionObject



42
43
44
# File 'lib/sakai-info/wiki.rb', line 42

def revision
  @dbrow[:revision]
end

#siteObject



76
77
78
79
80
81
82
# File 'lib/sakai-info/wiki.rb', line 76

def site
  @site ||= if not self.site_id.nil?
              Site.find!(self.site_id)
            else
              nil
            end
end

#site_idObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sakai-info/wiki.rb', line 64

def site_id
  @site_id ||= if not self.realm_name.nil?
                 if self.realm_name =~ /^\/site\/([^\/]+)/
                   $1
                 else
                   nil
                 end
               else
                 nil
               end
end

#summary_serializationObject



162
163
164
165
166
167
168
169
# File 'lib/sakai-info/wiki.rb', line 162

def summary_serialization
  {
    "id" => self.id,
    "name" => self.name,
    "owner" => self.owner.eid,
    "site_id" => self.site_id,
  }
end