lportal 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/company.rb +2 -0
- data/lib/dl_file.rb +6 -0
- data/lib/group.rb +40 -0
- data/lib/mb/category.rb +2 -1
- data/lib/mb/message.rb +292 -5
- data/lib/mb/message_flag.rb +19 -0
- data/lib/mb/stats_user.rb +18 -0
- data/lib/mb/thread.rb +12 -6
- data/lib/ratings_stats.rb +18 -0
- data/lib/social_activity.rb +29 -0
- data/lib/social_relation.rb +19 -0
- data/lib/tag/asset.rb +25 -1
- data/lib/user.rb +4 -2
- data/test/unit/dl_file_test.rb +31 -3
- data/test/unit/mb/message_test.rb +155 -1
- data/version.rb +1 -1
- metadata +7 -2
data/lib/company.rb
CHANGED
@@ -32,12 +32,14 @@ class Company < ActiveRecord::Base
|
|
32
32
|
'com.liferay.portal.model.Company'
|
33
33
|
end
|
34
34
|
|
35
|
+
# A list of Users who have the Role 'Administrator'. Scope is not checked!
|
35
36
|
def administrators
|
36
37
|
adminrole = Role.find(:first, :conditions => "companyid=#{self.id} AND name='Administrator'")
|
37
38
|
return self.users.select{|u| u.roles.include?(adminrole) }
|
38
39
|
end
|
39
40
|
alias :admins :administrators
|
40
41
|
|
42
|
+
# The default user for this Company.
|
41
43
|
def guest
|
42
44
|
User.find(:first, :conditions => "companyid=#{self.id} AND defaultuser = true" )
|
43
45
|
end
|
data/lib/dl_file.rb
CHANGED
@@ -22,4 +22,10 @@ class DlFile < ActiveRecord::Base
|
|
22
22
|
:class_name => 'Tag::Asset',
|
23
23
|
:foreign_key => 'classpk'
|
24
24
|
|
25
|
+
|
26
|
+
# URL path to download this Document Library File
|
27
|
+
def path
|
28
|
+
'/c/document_library/get_file?folderId=%i&name=%s' % [self.folderid, self.name]
|
29
|
+
end
|
30
|
+
|
25
31
|
end
|
data/lib/group.rb
CHANGED
@@ -222,6 +222,41 @@ class Group < ActiveRecord::Base
|
|
222
222
|
:foreign_key => 'groupid',
|
223
223
|
:conditions => 'privatelayout = true'
|
224
224
|
|
225
|
+
|
226
|
+
# --
|
227
|
+
# Class methods
|
228
|
+
# ++
|
229
|
+
|
230
|
+
class << self
|
231
|
+
|
232
|
+
# 0 = personal user groups
|
233
|
+
def find_personal(companyid)
|
234
|
+
self.find(:all, :conditions => "companyid=#{companyid} AND type_=0")
|
235
|
+
end
|
236
|
+
|
237
|
+
# 1 = public, guest can see
|
238
|
+
def find_public(companyid)
|
239
|
+
self.find(:all, :conditions => "companyid=#{companyid} AND type_=1")
|
240
|
+
end
|
241
|
+
|
242
|
+
# 2 = user-created open communities
|
243
|
+
def find_open(companyid)
|
244
|
+
self.find(:all, :conditions => "companyid=#{companyid} AND type_=2")
|
245
|
+
end
|
246
|
+
|
247
|
+
# 3 = private, also contains admins
|
248
|
+
def find_private(companyid)
|
249
|
+
self.find(:all, :conditions => "companyid=#{companyid} AND type_=3")
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
|
254
|
+
# --
|
255
|
+
# Instance methods
|
256
|
+
# ++
|
257
|
+
|
258
|
+
# Group's name. If classnameid==0 (Group is a basic group), use the name in the group_ column.
|
259
|
+
# Otherwise use the owner's name.
|
225
260
|
def name
|
226
261
|
self.classnameid != 0 ?
|
227
262
|
self.owner.name : super
|
@@ -327,4 +362,9 @@ class Group < ActiveRecord::Base
|
|
327
362
|
self.select_layouts_with(portlet,pl).any?
|
328
363
|
end
|
329
364
|
|
365
|
+
# Helper to collect all tags that are related to this Group through Tag::Asset.
|
366
|
+
def assets_tags
|
367
|
+
self.assets.collect(&:tags).flatten.uniq
|
368
|
+
end
|
369
|
+
|
330
370
|
end
|
data/lib/mb/category.rb
CHANGED
@@ -4,7 +4,8 @@ module MB
|
|
4
4
|
set_table_name :mbcategory
|
5
5
|
set_primary_key :categoryid
|
6
6
|
|
7
|
-
|
7
|
+
# this causes trouble when modifying instance attributes (!)
|
8
|
+
#validates_uniqueness_of :uuid_
|
8
9
|
|
9
10
|
# com.liferay.portlet.messageboards.model.MBCategory
|
10
11
|
def liferay_class
|
data/lib/mb/message.rb
CHANGED
@@ -3,11 +3,264 @@ module MB
|
|
3
3
|
set_table_name :mbmessage
|
4
4
|
set_primary_key :messageid
|
5
5
|
|
6
|
+
# validates_presence_of :user, :category, :subject, :body
|
7
|
+
|
8
|
+
|
6
9
|
# com.liferay.portlet.messageboards.model.MBMessage
|
7
10
|
def liferay_class
|
8
11
|
'com.liferay.portlet.messageboards.model.MBMessage'
|
9
12
|
end
|
10
13
|
|
14
|
+
# Actions for Permissions.
|
15
|
+
def self.actions
|
16
|
+
%w{
|
17
|
+
DELETE
|
18
|
+
PERMISSIONS
|
19
|
+
SUBSCRIBE
|
20
|
+
UPDATE
|
21
|
+
VIEW
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
# - user
|
26
|
+
# - category or parent message
|
27
|
+
# - body
|
28
|
+
def initialize(params)
|
29
|
+
raise 'No user' unless params[:user] or params[:userid]
|
30
|
+
unless ((params[:category] or params[:categoryid]) || (params[:parent] or params[:parentmessageid]))
|
31
|
+
raise 'No category or parentmessage'
|
32
|
+
end
|
33
|
+
raise 'No body' unless params[:body]
|
34
|
+
super(params)
|
35
|
+
|
36
|
+
# COPY mbmessage (uuid_, messageid, companyid, userid, username, createdate, modifieddate, categoryid, threadid, parentmessageid, subject, body, attachments, anonymous) FROM stdin;
|
37
|
+
# +66089117-ddb5-4577-ba9b-76479a273727 10308 10109 10129 Test Test 2009-01-17 08:07:11.947 2009-01-17 08:07:11.947 10307 10309 0 New thread This is a test, using rich editor. f f
|
38
|
+
|
39
|
+
unless self.uuid_
|
40
|
+
require 'rubygems'
|
41
|
+
require 'uuidtools'
|
42
|
+
self.uuid_ = UUID.random_create.to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
self.category ||= self.parent.category
|
46
|
+
category = self.category
|
47
|
+
|
48
|
+
self.companyid ||= category.companyid
|
49
|
+
|
50
|
+
# always require User
|
51
|
+
#unless self.userid
|
52
|
+
# self.userid = 0
|
53
|
+
# self.anonymous = true
|
54
|
+
#else
|
55
|
+
self.anonymous = false
|
56
|
+
#end
|
57
|
+
|
58
|
+
self.subject ||= ''
|
59
|
+
self.username ||= ''
|
60
|
+
self.createdate = Time.now
|
61
|
+
self.modifieddate = Time.now
|
62
|
+
self.parentmessageid ||= 0
|
63
|
+
self.attachments ||= false
|
64
|
+
self.save
|
65
|
+
|
66
|
+
|
67
|
+
# COPY mbcategory (uuid_, categoryid, groupid, companyid, userid, username, createdate, modifieddate, parentcategoryid, name, description, lastpostdate) FROM stdin;
|
68
|
+
# -fda18eef-3992-419e-a373-6e2f01a8b6a9 10307 10166 10109 10129 Test Test 2009-01-17 08:06:00.359 2009-01-17 08:06:00.359 0 Teppo Testaaja message board for user Teppo \N
|
69
|
+
# +fda18eef-3992-419e-a373-6e2f01a8b6a9 10307 10166 10109 10129 Test Test 2009-01-17 08:06:00.359 2009-01-17 08:06:00.359 0 Teppo Testaaja message board for user Teppo 2009-01-17 08:07:11.947
|
70
|
+
|
71
|
+
category.lastpostdate = Time.now
|
72
|
+
category.save
|
73
|
+
|
74
|
+
|
75
|
+
# COPY mbthread (threadid, categoryid, rootmessageid, messagecount, viewcount, lastpostbyuserid, lastpostdate, priority) FROM stdin;
|
76
|
+
# +10309 10307 10308 1 1 10129 2009-01-17 08:07:11.947 0
|
77
|
+
|
78
|
+
thread = MB::Thread.find(:first,
|
79
|
+
:conditions => "categoryid=#{category.id} AND rootmessageid=#{self.find_thread_root.id}")
|
80
|
+
unless thread
|
81
|
+
thread = MB::Thread.create(
|
82
|
+
:category => category,
|
83
|
+
:rootmessage => self,
|
84
|
+
:messagecount => 0,
|
85
|
+
:viewcount => 0
|
86
|
+
)
|
87
|
+
end
|
88
|
+
thread.messagecount += 1
|
89
|
+
thread.lastpostbyuserid = self.user.id
|
90
|
+
thread.lastpostdate = Time.now
|
91
|
+
thread.save
|
92
|
+
self.thread = thread
|
93
|
+
|
94
|
+
|
95
|
+
# COPY mbmessageflag (messageflagid, userid, messageid, flag) FROM stdin;
|
96
|
+
# +10313 10129 10308 1
|
97
|
+
|
98
|
+
unless self.flag # wtf?
|
99
|
+
MB::MessageFlag.create(
|
100
|
+
:user => self.user,
|
101
|
+
:message => self,
|
102
|
+
:flag => 1
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
# COPY mbstatsuser (statsuserid, groupid, userid, messagecount, lastpostdate) FROM stdin;
|
108
|
+
# +10310 10166 10129 1 2009-01-17 08:07:12.014
|
109
|
+
|
110
|
+
stats = MB::StatsUser.find(:first, :conditions => "groupid=#{category.groupid} AND userid=#{self.user.id}")
|
111
|
+
unless stats
|
112
|
+
stats = MB::StatsUser.create(
|
113
|
+
:groupid => category.groupid,
|
114
|
+
:user => self.user,
|
115
|
+
:messagecount => 0
|
116
|
+
)
|
117
|
+
end
|
118
|
+
stats.messagecount += 1
|
119
|
+
stats.lastpostdate = Time.now
|
120
|
+
stats.save
|
121
|
+
|
122
|
+
|
123
|
+
# COPY ratingsstats (statsid, classnameid, classpk, totalentries, totalscore, averagescore) FROM stdin;
|
124
|
+
# +10312 10071 10308 0 0 0
|
125
|
+
|
126
|
+
classnameid = Classname.find_by_value(self.liferay_class).id
|
127
|
+
|
128
|
+
unless RatingsStats.find(:first,
|
129
|
+
:conditions => "classnameid=#{classnameid} AND classpk=#{self.id}")
|
130
|
+
RatingsStats.create(
|
131
|
+
:classnameid => classnameid,
|
132
|
+
:classpk => self.id
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
# COPY socialactivity (activityid, groupid, companyid, userid, createdate, mirroractivityid, classnameid, classpk, type_, extradata, receiveruserid) FROM stdin;
|
138
|
+
# +1 10166 10109 10129 2009-01-17 08:07:12.024 0 10071 10308 1 0
|
139
|
+
|
140
|
+
unless SocialActivity.find(:first,
|
141
|
+
:conditions => "userid=#{self.user.id} AND classnameid=#{classnameid} AND classpk=#{self.id}")
|
142
|
+
SocialActivity.create(
|
143
|
+
:group => category.group,
|
144
|
+
:company => self.company,
|
145
|
+
:user => self.user,
|
146
|
+
:classnameid => classnameid,
|
147
|
+
:classpk => self.id
|
148
|
+
)
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
# COPY tagsasset (assetid, groupid, companyid, userid, username, createdate, modifieddate, classnameid, classpk, startdate, enddate, publishdate, expirationdate, mimetype, title, description, summary, url, height, width, priority, viewcount) FROM stdin;
|
153
|
+
# +10311 10166 10109 10129 Test Test 2009-01-17 08:07:12.039 2009-01-17 08:07:12.039 10071 10308 \N \N \N \N text/html New thread 0 0 0 0
|
154
|
+
|
155
|
+
unless Tag::Asset.find(:first,
|
156
|
+
:conditions => "userid=#{self.user.id} AND classnameid=#{classnameid} AND classpk=#{self.id}")
|
157
|
+
Tag::Asset.create(
|
158
|
+
:group => category.group,
|
159
|
+
:company => self.company,
|
160
|
+
:user => self.user,
|
161
|
+
:classnameid => classnameid,
|
162
|
+
:classpk => self.id,
|
163
|
+
:title => 'New thread'
|
164
|
+
)
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
# ResourceCode with scope 1 => Resource for Company
|
169
|
+
# ResourceCode with scope 2 => Resource for this Group and Guest's Group
|
170
|
+
# ResourceCode with scope 4 => Resource for self
|
171
|
+
|
172
|
+
# COPY resourcecode (codeid, companyid, name, scope) FROM stdin;
|
173
|
+
# +107 10109 com.liferay.portlet.messageboards.model.MBMessage 1
|
174
|
+
# +108 10109 com.liferay.portlet.messageboards.model.MBMessage 2
|
175
|
+
# +109 10109 com.liferay.portlet.messageboards.model.MBMessage 4
|
176
|
+
|
177
|
+
# COPY resource_ (resourceid, codeid, primkey) FROM stdin;
|
178
|
+
# +214 107 10109
|
179
|
+
# +215 108 10124 << this is Guest's group
|
180
|
+
# +216 108 10166
|
181
|
+
# +217 109 10308
|
182
|
+
|
183
|
+
# only create resources with scope 1,2 for rootmessages
|
184
|
+
if self.is_root?
|
185
|
+
rc = self.resource_code(1)
|
186
|
+
unless rc
|
187
|
+
rc = ResourceCode.create(
|
188
|
+
:companyid => self.companyid,
|
189
|
+
:name => self.liferay_class,
|
190
|
+
:scope => 1
|
191
|
+
)
|
192
|
+
end
|
193
|
+
unless Resource.find(:first, :conditions => "codeid=#{rc.id} AND primkey='#{self.companyid}'")
|
194
|
+
Resource.create(
|
195
|
+
:codeid => rc.id,
|
196
|
+
:primkey => self.companyid
|
197
|
+
)
|
198
|
+
end
|
199
|
+
|
200
|
+
rc = self.resource_code(2)
|
201
|
+
unless rc
|
202
|
+
rc = ResourceCode.create(
|
203
|
+
:companyid => self.companyid,
|
204
|
+
:name => self.liferay_class,
|
205
|
+
:scope => 2
|
206
|
+
)
|
207
|
+
end
|
208
|
+
unless Resource.find(:first, :conditions => "codeid=#{rc.id} AND primkey='#{category.groupid}'")
|
209
|
+
Resource.create(
|
210
|
+
:codeid => rc.id,
|
211
|
+
:primkey => category.groupid
|
212
|
+
)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# Create a resource with scope=4
|
217
|
+
rc = self.resource_code(4)
|
218
|
+
unless rc
|
219
|
+
rc = ResourceCode.create(
|
220
|
+
:companyid => self.companyid,
|
221
|
+
:name => self.liferay_class,
|
222
|
+
:scope => 4
|
223
|
+
)
|
224
|
+
end
|
225
|
+
resource = Resource.find(:first, :conditions => "codeid=#{rc.id} AND primkey='#{self.id}'")
|
226
|
+
unless resource
|
227
|
+
resource = Resource.create(
|
228
|
+
:codeid => rc.id,
|
229
|
+
:primkey => self.id
|
230
|
+
)
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
# COPY permission_ (permissionid, companyid, actionid, resourceid) FROM stdin;
|
235
|
+
# +323 10109 DELETE 217
|
236
|
+
# +324 10109 PERMISSIONS 217
|
237
|
+
# +325 10109 SUBSCRIBE 217
|
238
|
+
# +326 10109 UPDATE 217
|
239
|
+
# +327 10109 VIEW 217
|
240
|
+
|
241
|
+
# COPY users_permissions (userid, permissionid) FROM stdin;
|
242
|
+
# +10129 323
|
243
|
+
# +10129 324
|
244
|
+
# +10129 325
|
245
|
+
# +10129 326
|
246
|
+
# +10129 327
|
247
|
+
|
248
|
+
self.class.actions.each do |actionid|
|
249
|
+
permission = Permission.find(:first,
|
250
|
+
:conditions => "companyid=#{self.companyid} AND actionid='#{actionid}' AND resourceid=#{resource.id}")
|
251
|
+
unless permission
|
252
|
+
permission = Permission.create(
|
253
|
+
:companyid => self.companyid,
|
254
|
+
:actionid => actionid,
|
255
|
+
:resourceid => resource.id
|
256
|
+
)
|
257
|
+
end
|
258
|
+
self.user.user_permissions << permission
|
259
|
+
end
|
260
|
+
|
261
|
+
self.save
|
262
|
+
end
|
263
|
+
|
11
264
|
belongs_to :company,
|
12
265
|
:foreign_key => 'companyid'
|
13
266
|
|
@@ -24,14 +277,42 @@ module MB
|
|
24
277
|
:class_name => 'MB::Thread',
|
25
278
|
:foreign_key => 'threadid'
|
26
279
|
|
27
|
-
|
28
|
-
|
29
|
-
|
280
|
+
has_one :flag,
|
281
|
+
:class_name => 'MB::MessageFlag',
|
282
|
+
:foreign_key => 'messageid'
|
30
283
|
|
31
284
|
|
32
|
-
|
285
|
+
has_one :asset,
|
286
|
+
:class_name => 'Tag::Asset',
|
287
|
+
:foreign_key => 'classpk'
|
288
|
+
|
289
|
+
|
290
|
+
# Parent message
|
33
291
|
def parent
|
34
|
-
self.
|
292
|
+
self.is_root? ? nil : MB::Message.find(self.parentmessageid)
|
293
|
+
end
|
294
|
+
def parent=(msg)
|
295
|
+
raise 'Parent must be MB::Message' unless msg.is_a?(MB::Message)
|
296
|
+
self.parentmessageid = msg.id
|
297
|
+
end
|
298
|
+
|
299
|
+
# First in thread?
|
300
|
+
def is_root?
|
301
|
+
self.parentmessageid == 0
|
302
|
+
end
|
303
|
+
|
304
|
+
# Finds the first in the thread recursively.
|
305
|
+
#
|
306
|
+
# Since initialize() uses this method to find the root message before the thread is known,
|
307
|
+
# MB::Thread methods cannot be used. Otherwise, self.thread.rootmessage would be faster.
|
308
|
+
# Using while (or until) loops may lead to never-ending loops if the database contains awkward data
|
309
|
+
# (actual root message pointing to another message etc)
|
310
|
+
def find_thread_root
|
311
|
+
msg = self
|
312
|
+
until (msg.is_root?) do
|
313
|
+
msg = msg.parent
|
314
|
+
end
|
315
|
+
return msg
|
35
316
|
end
|
36
317
|
|
37
318
|
def has_attachements?
|
@@ -42,5 +323,11 @@ module MB
|
|
42
323
|
self.anonymous
|
43
324
|
end
|
44
325
|
|
326
|
+
# ResourceCode associated to this instance (and scope)
|
327
|
+
def resource_code(scope=4)
|
328
|
+
ResourceCode.find(:first,
|
329
|
+
:conditions => "companyid=#{self.companyid} AND name='#{self.liferay_class}' AND scope=#{scope}")
|
330
|
+
end
|
331
|
+
|
45
332
|
end
|
46
333
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MB
|
2
|
+
class MessageFlag < ActiveRecord::Base
|
3
|
+
set_table_name :mbmessageflag
|
4
|
+
set_primary_key :messageflagid
|
5
|
+
|
6
|
+
# com.liferay.portlet.messageboards.model.MBMessageFlag
|
7
|
+
def liferay_class
|
8
|
+
'com.liferay.portlet.messageboards.model.MBMessageFlag'
|
9
|
+
end
|
10
|
+
|
11
|
+
belongs_to :user,
|
12
|
+
:foreign_key => 'userid'
|
13
|
+
|
14
|
+
belongs_to :message,
|
15
|
+
:class_name => 'MB::Message',
|
16
|
+
:foreign_key => 'messageid'
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module MB
|
2
|
+
class StatsUser < ActiveRecord::Base
|
3
|
+
set_table_name :mbstatsuser
|
4
|
+
set_primary_key :statsuserid
|
5
|
+
|
6
|
+
# com.liferay.portlet.messageboards.model.MBStatsUser
|
7
|
+
def liferay_class
|
8
|
+
'com.liferay.portlet.messageboards.model.MBStatsUser'
|
9
|
+
end
|
10
|
+
|
11
|
+
belongs_to :user,
|
12
|
+
:foreign_key => 'userid'
|
13
|
+
|
14
|
+
belongs_to :group,
|
15
|
+
:foreign_key => 'groupid'
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/mb/thread.rb
CHANGED
@@ -9,15 +9,21 @@ module MB
|
|
9
9
|
end
|
10
10
|
|
11
11
|
belongs_to :category,
|
12
|
-
:class_name =>
|
13
|
-
:foreign_key =>
|
12
|
+
:class_name => 'MB::Category',
|
13
|
+
:foreign_key => 'categoryid'
|
14
|
+
|
15
|
+
belongs_to :rootmessage,
|
16
|
+
:class_name => 'MB::Message',
|
17
|
+
:foreign_key => 'rootmessageid'
|
18
|
+
|
19
|
+
has_many :messages,
|
20
|
+
:class_name => 'MB::Message',
|
21
|
+
:foreign_key => 'threadid',
|
22
|
+
:order => :createdate
|
14
23
|
|
15
|
-
belongs_to :root,
|
16
|
-
:class_name => "MB::Message",
|
17
|
-
:foreign_key => "rootmessageid"
|
18
24
|
|
19
25
|
def first_entry
|
20
|
-
self.
|
26
|
+
self.rootmessage
|
21
27
|
end
|
22
28
|
|
23
29
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class RatingsStats < ActiveRecord::Base
|
2
|
+
set_table_name :ratingsstats
|
3
|
+
set_primary_key :statsid
|
4
|
+
|
5
|
+
# com.liferay.portlet.ratings.model.RatingsStats
|
6
|
+
def liferay_class
|
7
|
+
'com.liferay.portlet.ratings.model.RatingsStats'
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(params)
|
11
|
+
super(params)
|
12
|
+
self.totalentries ||= 0
|
13
|
+
self.totalscore ||= 0
|
14
|
+
self.averagescore ||= 0
|
15
|
+
self.save
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class SocialActivity < ActiveRecord::Base
|
2
|
+
set_table_name :socialactivity
|
3
|
+
set_primary_key :activityid
|
4
|
+
|
5
|
+
# com.liferay.portlet.social.model.SocialActivity
|
6
|
+
def liferay_class
|
7
|
+
'com.liferay.portlet.social.model.SocialActivity'
|
8
|
+
end
|
9
|
+
|
10
|
+
belongs_to :group,
|
11
|
+
:foreign_key => 'groupid'
|
12
|
+
|
13
|
+
belongs_to :company,
|
14
|
+
:foreign_key => 'companyid'
|
15
|
+
|
16
|
+
belongs_to :user,
|
17
|
+
:foreign_key => 'userid'
|
18
|
+
|
19
|
+
def initialize(params)
|
20
|
+
super(params)
|
21
|
+
self.createdate ||= Time.now
|
22
|
+
self.mirroractivityid ||= 0
|
23
|
+
self.type_ ||= 1
|
24
|
+
self.extradata ||= ''
|
25
|
+
self.receiveruserid ||= 0
|
26
|
+
self.save
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class SocialRelation < ActiveRecord::Base
|
2
|
+
set_table_name :socialrelation
|
3
|
+
set_primary_key :relationid
|
4
|
+
|
5
|
+
# com.liferay.portlet.social.model.SocialRelation
|
6
|
+
def liferay_class
|
7
|
+
'com.liferay.portlet.social.model.SocialRelation'
|
8
|
+
end
|
9
|
+
|
10
|
+
belongs_to :company,
|
11
|
+
:foreign_key => 'companyid'
|
12
|
+
|
13
|
+
belongs_to :user1,
|
14
|
+
:foreign_key => 'userid1'
|
15
|
+
|
16
|
+
belongs_to :user2,
|
17
|
+
:foreign_key => 'userid2'
|
18
|
+
|
19
|
+
end
|
data/lib/tag/asset.rb
CHANGED
@@ -9,6 +9,30 @@ module Tag
|
|
9
9
|
'com.liferay.portlet.tags.model.TagsAsset'
|
10
10
|
end
|
11
11
|
|
12
|
+
# COPY tagsasset (assetid, groupid, companyid, userid, username, createdate, modifieddate, classnameid, classpk, startdate, enddate, publishdate, expirationdate, mimetype, title, description, summary, url, height, width, priority, viewcount) FROM stdin;
|
13
|
+
# +10311 10166 10109 10129 Test Test 2009-01-17 08:07:12.039 2009-01-17 08:07:12.039 10071 10308 \N \N \N \N text/html New thread 0 0 0 0
|
14
|
+
|
15
|
+
|
16
|
+
def initialize(params)
|
17
|
+
super(params)
|
18
|
+
self.createdate ||= Time.now
|
19
|
+
self.modifieddate ||= Time.now
|
20
|
+
self.startdate ||= nil
|
21
|
+
self.enddate ||= nil
|
22
|
+
self.publishdate ||= nil
|
23
|
+
self.expirationdate ||= nil
|
24
|
+
self.mimetype ||= 'text/html'
|
25
|
+
self.title ||= ''
|
26
|
+
self.description ||= ''
|
27
|
+
self.summary ||= ''
|
28
|
+
self.url ||= ''
|
29
|
+
self.height ||= 0
|
30
|
+
self.width ||= 0
|
31
|
+
self.priority ||= 0
|
32
|
+
self.viewcount ||= 0
|
33
|
+
self.save
|
34
|
+
end
|
35
|
+
|
12
36
|
belongs_to :company,
|
13
37
|
:foreign_key => 'companyid'
|
14
38
|
|
@@ -33,7 +57,7 @@ module Tag
|
|
33
57
|
[
|
34
58
|
BlogPost,
|
35
59
|
Wiki::Page,
|
36
|
-
|
60
|
+
MB::Message,
|
37
61
|
Journal::Article,
|
38
62
|
DlFile,
|
39
63
|
IG::Image,
|
data/lib/user.rb
CHANGED
@@ -274,7 +274,7 @@ class User < ActiveRecord::Base
|
|
274
274
|
alias :articles :wikipages
|
275
275
|
|
276
276
|
# association to MessageBoardMessages
|
277
|
-
has_many :
|
277
|
+
has_many :mbmessages,
|
278
278
|
:class_name => 'MB::Message',
|
279
279
|
:foreign_key => 'userid'
|
280
280
|
|
@@ -304,10 +304,12 @@ class User < ActiveRecord::Base
|
|
304
304
|
org = self.company.organizations.select{|o| o.parent==nil}.first
|
305
305
|
self.organizations << org
|
306
306
|
|
307
|
+
# give the user the 'Organization member' role, within the scope of this Organization.
|
307
308
|
org_role = Role.find(:first, :conditions => "companyid=#{self.companyid} AND name='Organization Member'")
|
308
309
|
group = org.group
|
309
310
|
|
310
311
|
# can ActiveRecord handle 3-way associations?
|
312
|
+
# - perhaps with hacking, http://bjhess.com/blog/2007/09/19/my-foray-into-has_many_polymorphs/
|
311
313
|
ActiveRecord::Base.connection.execute(
|
312
314
|
"INSERT INTO usergrouprole (userid, groupid, roleid) VALUES (%i, %i, %i);" % [
|
313
315
|
self.id, org.group.id, org_role.id])
|
@@ -369,7 +371,7 @@ class User < ActiveRecord::Base
|
|
369
371
|
|
370
372
|
# Creates a new Contact unless it exists
|
371
373
|
#
|
372
|
-
# 1=female, 2=male
|
374
|
+
# 1=female, 2=male (WHERE IS CONSISTENCY?!)
|
373
375
|
def sex=(v)
|
374
376
|
male = (v==2 ? true : false)
|
375
377
|
if self.contact
|
data/test/unit/dl_file_test.rb
CHANGED
@@ -1,8 +1,36 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class DlFileTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
def
|
6
|
-
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@files = DLFile.all
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_company
|
10
|
+
@files.each do |dlf|
|
11
|
+
assert_not_nil dlf.company
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_user
|
16
|
+
@files.each do |dlf|
|
17
|
+
assert_not_nil dlf.user
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_asset
|
22
|
+
@files.each do |dlf|
|
23
|
+
assert_not_nil dlf.asset
|
24
|
+
end
|
7
25
|
end
|
26
|
+
|
27
|
+
def test_path
|
28
|
+
@files.each do |dlf|
|
29
|
+
assert_not_nil dlf.path
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
8
36
|
end
|
@@ -5,13 +5,161 @@ class MB::MessageTest < ActiveSupport::TestCase
|
|
5
5
|
:mbcategory,
|
6
6
|
:mbdiscussion,
|
7
7
|
:mbmessage,
|
8
|
-
:mbthread
|
8
|
+
:mbthread,
|
9
|
+
:mbstatsuser,
|
10
|
+
:mbmessageflag,
|
11
|
+
:classname_,
|
12
|
+
:group_,
|
13
|
+
:user_
|
9
14
|
]
|
10
15
|
|
11
16
|
def setup
|
12
17
|
@messages = MB::Message.all
|
13
18
|
end
|
14
19
|
|
20
|
+
def test_new_rootmsg
|
21
|
+
user = User.first
|
22
|
+
category = MB::Category.first
|
23
|
+
subject = random_string
|
24
|
+
body = random_string
|
25
|
+
|
26
|
+
msg = MB::Message.create(:category => category, :user => user, :subject => subject, :body => body)
|
27
|
+
|
28
|
+
assert_equal subject, msg.subject
|
29
|
+
assert_equal body, msg.body
|
30
|
+
|
31
|
+
assert_not_nil msg.flag
|
32
|
+
assert_equal 1, msg.flag.flag
|
33
|
+
|
34
|
+
category.reload
|
35
|
+
assert_equal category, msg.category
|
36
|
+
assert_in_delta Time.now, category.lastpostdate.getlocal, 1.0
|
37
|
+
|
38
|
+
|
39
|
+
thread = MB::Thread.find(:first,
|
40
|
+
:conditions => "categoryid=#{category.id} AND rootmessageid=#{msg.id}")
|
41
|
+
assert_not_nil thread
|
42
|
+
assert_equal thread, msg.thread
|
43
|
+
assert_equal 1, thread.messagecount
|
44
|
+
assert_equal user.id, thread.lastpostbyuserid
|
45
|
+
assert_in_delta Time.now, thread.lastpostdate.getlocal, 1.0
|
46
|
+
|
47
|
+
|
48
|
+
stats = MB::StatsUser.find(:first, :conditions => "groupid=#{category.group.id} AND userid=#{user.id}")
|
49
|
+
assert_not_nil stats
|
50
|
+
assert_equal 1, stats.messagecount
|
51
|
+
assert_in_delta Time.now, stats.lastpostdate.getlocal, 1.0
|
52
|
+
|
53
|
+
|
54
|
+
classnameid = Classname.find_by_value(msg.liferay_class).id
|
55
|
+
assert_not_nil RatingsStats.find(:first, :conditions => "classnameid=#{classnameid} AND classpk=#{msg.id}")
|
56
|
+
|
57
|
+
assert_not_nil SocialActivity.find(:first,
|
58
|
+
:conditions => "userid=#{user.id} AND classnameid=#{classnameid} AND classpk=#{msg.id}")
|
59
|
+
|
60
|
+
assert_not_nil Tag::Asset.find(:first,
|
61
|
+
:conditions => "userid=#{user.id} AND classnameid=#{classnameid} AND classpk=#{msg.id}")
|
62
|
+
|
63
|
+
rc = msg.resource_code(1)
|
64
|
+
assert_not_nil rc
|
65
|
+
assert_not_nil Resource.find(:first,
|
66
|
+
:conditions => "codeid=#{rc.id} AND primkey='#{msg.companyid}'")
|
67
|
+
|
68
|
+
rc = msg.resource_code(2)
|
69
|
+
assert_not_nil rc
|
70
|
+
assert_not_nil Resource.find(:first,
|
71
|
+
:conditions => "codeid=#{rc.id} AND primkey='#{category.group.id}'")
|
72
|
+
|
73
|
+
rc = msg.resource_code(4)
|
74
|
+
assert_not_nil rc
|
75
|
+
resource = Resource.find(:first,
|
76
|
+
:conditions => "codeid=#{rc.id} AND primkey='#{msg.id}'")
|
77
|
+
assert_not_nil resource
|
78
|
+
|
79
|
+
msg.class.actions.each do |actionid|
|
80
|
+
p = Permission.find(:first,
|
81
|
+
:conditions => "companyid=#{msg.companyid} AND actionid='#{actionid}' AND resourceid=#{resource.id}")
|
82
|
+
assert_not_nil p
|
83
|
+
assert user.user_permissions.include?(p)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_new_reply
|
88
|
+
parent = MB::Message.first
|
89
|
+
category = parent.category
|
90
|
+
assert_not_nil category
|
91
|
+
|
92
|
+
user = User.first
|
93
|
+
subject = random_string
|
94
|
+
body = random_string
|
95
|
+
|
96
|
+
thread = parent.thread
|
97
|
+
assert_not_nil thread
|
98
|
+
thread_messagecount = thread.messagecount
|
99
|
+
|
100
|
+
stats = MB::StatsUser.find(:first, :conditions => "groupid=#{category.groupid} AND userid=#{user.id}")
|
101
|
+
stats_messagecount = (stats.nil? ? 0 : stats.messagecount)
|
102
|
+
|
103
|
+
msg = MB::Message.create(
|
104
|
+
:parent => parent,
|
105
|
+
:user => user,
|
106
|
+
:subject => subject,
|
107
|
+
:body => body
|
108
|
+
)
|
109
|
+
|
110
|
+
assert_equal subject, msg.subject
|
111
|
+
assert_equal body, msg.body
|
112
|
+
assert_equal parent, msg.parent
|
113
|
+
|
114
|
+
assert_not_nil msg.flag
|
115
|
+
assert_equal 1, msg.flag.flag
|
116
|
+
|
117
|
+
|
118
|
+
category.reload
|
119
|
+
assert_equal category, msg.category
|
120
|
+
assert_in_delta Time.now, category.lastpostdate.getlocal, 1.0
|
121
|
+
|
122
|
+
|
123
|
+
thread.reload
|
124
|
+
assert_equal thread, msg.thread
|
125
|
+
assert_equal thread_messagecount+1, thread.messagecount
|
126
|
+
assert_equal user.id, thread.lastpostbyuserid
|
127
|
+
assert_in_delta Time.now, thread.lastpostdate.getlocal, 1.0
|
128
|
+
|
129
|
+
|
130
|
+
stats = MB::StatsUser.find(:first, :conditions => "groupid=#{category.groupid} AND userid=#{user.id}")
|
131
|
+
assert_not_nil stats
|
132
|
+
assert_equal stats_messagecount+1, stats.messagecount
|
133
|
+
assert_in_delta Time.now, stats.lastpostdate.getlocal, 1.0
|
134
|
+
|
135
|
+
|
136
|
+
# COPY ratingsstats (statsid, classnameid, classpk, totalentries, totalscore, averagescore) FROM stdin;
|
137
|
+
# +10316 10071 10314 0 0 0
|
138
|
+
|
139
|
+
classnameid = Classname.find_by_value(msg.liferay_class).id
|
140
|
+
assert_not_nil RatingsStats.find(:first, :conditions => "classnameid=#{classnameid} AND classpk=#{msg.id}")
|
141
|
+
|
142
|
+
assert_not_nil SocialActivity.find(:first,
|
143
|
+
:conditions => "userid=#{user.id} AND classnameid=#{classnameid} AND classpk=#{msg.id}")
|
144
|
+
|
145
|
+
assert_not_nil Tag::Asset.find(:first,
|
146
|
+
:conditions => "userid=#{user.id} AND classnameid=#{classnameid} AND classpk=#{msg.id}")
|
147
|
+
|
148
|
+
rc = msg.resource_code(4)
|
149
|
+
assert_not_nil rc
|
150
|
+
resource = Resource.find(:first,
|
151
|
+
:conditions => "codeid=#{rc.id} AND primkey='#{msg.id}'")
|
152
|
+
assert_not_nil resource
|
153
|
+
|
154
|
+
msg.class.actions.each do |actionid|
|
155
|
+
p = Permission.find(:first,
|
156
|
+
:conditions => "companyid=#{msg.companyid} AND actionid='#{actionid}' AND resourceid=#{resource.id}")
|
157
|
+
assert_not_nil p
|
158
|
+
assert user.user_permissions.include?(p)
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
15
163
|
def test_company
|
16
164
|
@messages.each do |x|
|
17
165
|
assert_not_nil x.company, "#{x.id} belongs to no company"
|
@@ -51,4 +199,10 @@ class MB::MessageTest < ActiveSupport::TestCase
|
|
51
199
|
end
|
52
200
|
end
|
53
201
|
|
202
|
+
def test_asset
|
203
|
+
@messages.each do |x|
|
204
|
+
assert_nothing_raised { x.asset }
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
54
208
|
end
|
data/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lportal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Lammentausta
|
@@ -9,7 +9,7 @@ autorequire: init
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-02-12 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -45,7 +45,9 @@ files:
|
|
45
45
|
- version.rb
|
46
46
|
- init.rb
|
47
47
|
- lportal.rb
|
48
|
+
- lib/social_activity.rb
|
48
49
|
- lib/counter.rb
|
50
|
+
- lib/social_relation.rb
|
49
51
|
- lib/image.rb
|
50
52
|
- lib/dl_folder.rb
|
51
53
|
- lib/blog_post.rb
|
@@ -56,6 +58,7 @@ files:
|
|
56
58
|
- lib/journal/article.rb
|
57
59
|
- lib/journal/feed.rb
|
58
60
|
- lib/journal/article_image.rb
|
61
|
+
- lib/ratings_stats.rb
|
59
62
|
- lib/user.rb
|
60
63
|
- lib/organization.rb
|
61
64
|
- lib/wiki
|
@@ -85,7 +88,9 @@ files:
|
|
85
88
|
- lib/mb
|
86
89
|
- lib/mb/thread.rb
|
87
90
|
- lib/mb/message.rb
|
91
|
+
- lib/mb/message_flag.rb
|
88
92
|
- lib/mb/category.rb
|
93
|
+
- lib/mb/stats_user.rb
|
89
94
|
- lib/mb/discussion.rb
|
90
95
|
- lib/web
|
91
96
|
- lib/web/layout.rb
|