lportal 1.0.9 → 1.0.17
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 +71 -0
- data/MIT-LICENSE +20 -0
- data/README +6 -5
- data/Rakefile +23 -0
- data/init.rb +1 -1
- data/lib/acts/resourceful.rb +104 -0
- data/lib/company.rb +25 -0
- data/lib/group.rb +83 -29
- data/lib/journal/article.rb +8 -4
- data/lib/mb/category.rb +30 -59
- data/lib/mb/message.rb +24 -67
- data/lib/permission.rb +16 -0
- data/lib/release.rb +9 -0
- data/lib/resource.rb +19 -0
- data/lib/resource_code.rb +21 -1
- data/lib/role.rb +7 -27
- data/lib/tag/asset.rb +26 -4
- data/lib/user.rb +20 -23
- data/lib/web/layout.rb +134 -39
- data/lib/web/layout_set.rb +8 -4
- data/lib/web/portlet.rb +92 -20
- data/lib/web/portlet_preferences.rb +176 -13
- data/lib/web/portlet_properties.rb +32 -0
- data/lib/web/typesettings.rb +32 -7
- data/lportal.rb +30 -3
- data/migrations/20090101000001_add_sequences.rb +64 -0
- data/migrations/20090309000001_portlet_properties.rb +19 -0
- data/portlets.rb +76 -0
- data/schema.rb +34 -0
- data/test/unit/company_test.rb +21 -9
- data/test/unit/dl_file_test.rb +2 -1
- data/test/unit/group_test.rb +74 -16
- data/test/unit/journal/article_test.rb +15 -1
- data/test/unit/mb/category_test.rb +12 -15
- data/test/unit/mb/message_test.rb +3 -2
- data/test/unit/mb/thread_test.rb +1 -1
- data/test/unit/organization_test.rb +7 -2
- data/test/unit/phone_test.rb +2 -0
- data/test/unit/release_test.rb +25 -0
- data/test/unit/role_test.rb +7 -7
- data/test/unit/tag/asset_test.rb +59 -2
- data/test/unit/user_test.rb +73 -77
- data/test/unit/web/layout_set_test.rb +18 -1
- data/test/unit/web/layout_test.rb +191 -5
- data/test/unit/web/portlet_preferences_test.rb +314 -17
- data/test/unit/web/portlet_properties_test.rb +36 -0
- data/test/unit/web/portlet_test.rb +121 -19
- data/test/unit/web/typesettings_test.rb +24 -11
- data/version.rb +1 -2
- metadata +20 -6
- data/install.rb +0 -1
data/lib/mb/message.rb
CHANGED
@@ -3,6 +3,8 @@ module MB
|
|
3
3
|
set_table_name :mbmessage
|
4
4
|
set_primary_key :messageid
|
5
5
|
|
6
|
+
acts_as_resourceful
|
7
|
+
|
6
8
|
# validates_presence_of :user, :category, :subject, :body
|
7
9
|
|
8
10
|
|
@@ -22,9 +24,11 @@ module MB
|
|
22
24
|
}
|
23
25
|
end
|
24
26
|
|
27
|
+
# Parameters:
|
25
28
|
# - user
|
26
29
|
# - category or parent message
|
27
30
|
# - body
|
31
|
+
# - flag (Fixnum)
|
28
32
|
def initialize(params)
|
29
33
|
raise 'No user' unless params[:user] or params[:userid]
|
30
34
|
unless ((params[:category] or params[:categoryid]) || (params[:parent] or params[:parentmessageid]))
|
@@ -95,13 +99,12 @@ module MB
|
|
95
99
|
# COPY mbmessageflag (messageflagid, userid, messageid, flag) FROM stdin;
|
96
100
|
# +10313 10129 10308 1
|
97
101
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
102
|
+
flag = (params[:flag] || 1)
|
103
|
+
self.flag = MB::MessageFlag.create(
|
104
|
+
:user => self.user,
|
105
|
+
:message => self,
|
106
|
+
:flag => flag
|
107
|
+
)
|
105
108
|
|
106
109
|
|
107
110
|
# COPY mbstatsuser (statsuserid, groupid, userid, messagecount, lastpostdate) FROM stdin;
|
@@ -182,53 +185,12 @@ module MB
|
|
182
185
|
|
183
186
|
# only create resources with scope 1,2 for rootmessages
|
184
187
|
if self.is_root?
|
185
|
-
|
186
|
-
|
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
|
188
|
+
get_resource(:scope => 1)
|
189
|
+
get_resource(:scope => 2)
|
214
190
|
end
|
215
191
|
|
216
192
|
# Create a resource with scope=4
|
217
|
-
|
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
|
193
|
+
resource = get_resource(:scope => 4)
|
232
194
|
|
233
195
|
|
234
196
|
# COPY permission_ (permissionid, companyid, actionid, resourceid) FROM stdin;
|
@@ -246,16 +208,12 @@ module MB
|
|
246
208
|
# +10129 327
|
247
209
|
|
248
210
|
self.class.actions.each do |actionid|
|
249
|
-
permission = Permission.
|
250
|
-
:
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
:resourceid => resource.id
|
256
|
-
)
|
257
|
-
end
|
258
|
-
self.user.user_permissions << permission
|
211
|
+
permission = Permission.get({
|
212
|
+
:companyid => self.companyid,
|
213
|
+
:actionid => actionid,
|
214
|
+
:resourceid => resource.id
|
215
|
+
})
|
216
|
+
self.user.permissions << permission
|
259
217
|
end
|
260
218
|
|
261
219
|
self.save
|
@@ -287,6 +245,11 @@ module MB
|
|
287
245
|
:foreign_key => 'classpk'
|
288
246
|
|
289
247
|
|
248
|
+
def scope2_primkey
|
249
|
+
raise 'instance does not belong to a category' unless self.category
|
250
|
+
self.category.groupid
|
251
|
+
end
|
252
|
+
|
290
253
|
# Parent message
|
291
254
|
def parent
|
292
255
|
self.is_root? ? nil : MB::Message.find(self.parentmessageid)
|
@@ -323,11 +286,5 @@ module MB
|
|
323
286
|
self.anonymous
|
324
287
|
end
|
325
288
|
|
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
|
-
|
332
289
|
end
|
333
290
|
end
|
data/lib/permission.rb
CHANGED
@@ -24,6 +24,22 @@ class Permission < ActiveRecord::Base
|
|
24
24
|
:foreign_key => 'permissionid',
|
25
25
|
:association_foreign_key => 'groupid'
|
26
26
|
|
27
|
+
# finds or creates
|
28
|
+
def self.get(args)
|
29
|
+
conditions = []
|
30
|
+
args.each_pair{ |k,v|
|
31
|
+
conditions << (k==:actionid ?
|
32
|
+
("%s='%s'" % [k,v]) : ("%s=%s" % [k,v]))
|
33
|
+
}
|
34
|
+
#puts conditions.inspect
|
35
|
+
p = Permission.find(:first, :conditions => conditions.join(' AND '))
|
36
|
+
unless p
|
37
|
+
logger.debug 'creating new Permission'
|
38
|
+
p = self.create(args)
|
39
|
+
end
|
40
|
+
return p
|
41
|
+
end
|
42
|
+
|
27
43
|
def holders
|
28
44
|
self.users + self.roles + self.groups
|
29
45
|
end
|
data/lib/release.rb
ADDED
data/lib/resource.rb
CHANGED
@@ -20,6 +20,25 @@ class Resource < ActiveRecord::Base
|
|
20
20
|
:class_name => 'Web::Layout',
|
21
21
|
:foreign_key => 'primkey'
|
22
22
|
|
23
|
+
# Finds existing or creates a new Resource. TODO: DRY to resourceful
|
24
|
+
# Args Hash:
|
25
|
+
# - :codeid
|
26
|
+
# - :primkey
|
27
|
+
def self.get(args)
|
28
|
+
conditions = []
|
29
|
+
args.each_pair{ |k,v|
|
30
|
+
conditions << (k==:primkey ?
|
31
|
+
("%s='%s'" % [k,v]) : ("%s=%s" % [k,v]))
|
32
|
+
}
|
33
|
+
#puts conditions.inspect
|
34
|
+
r = self.find(:first, :conditions => conditions.join(' AND '))
|
35
|
+
unless r
|
36
|
+
logger.debug 'creating new %s' % self.class
|
37
|
+
r = self.create(args)
|
38
|
+
end
|
39
|
+
r.reload
|
40
|
+
end
|
41
|
+
|
23
42
|
def plid
|
24
43
|
self.primkey[/([0-9]*)_LAYOUT_(.*)/,1]
|
25
44
|
end
|
data/lib/resource_code.rb
CHANGED
@@ -18,8 +18,28 @@ class ResourceCode < ActiveRecord::Base
|
|
18
18
|
# - :scope (defaults to 4)
|
19
19
|
def self.find_by_liferay_class(args={})
|
20
20
|
args.update(:scope => 4) unless args[:scope]
|
21
|
-
ResourceCode.
|
21
|
+
ResourceCode.get(:first,
|
22
22
|
:conditions => "companyid=#{args[:companyid]} AND name='#{args[:name]}' AND scope=#{args[:scope]}")
|
23
23
|
end
|
24
24
|
|
25
|
+
# Finds existing or creates a new ResourceCode
|
26
|
+
# Args:
|
27
|
+
# - :companyid
|
28
|
+
# - :name
|
29
|
+
# - :scope
|
30
|
+
def self.get(args)
|
31
|
+
conditions = []
|
32
|
+
args.each_pair{ |k,v|
|
33
|
+
conditions << (k==:name ?
|
34
|
+
("%s='%s'" % [k,v]) : ("%s=%s" % [k,v]))
|
35
|
+
}
|
36
|
+
#logger.debug conditions.inspect
|
37
|
+
rc = ResourceCode.find(:first, :conditions => conditions.join(' AND '))
|
38
|
+
unless rc
|
39
|
+
logger.debug 'creating new ResourceCode'
|
40
|
+
rc = self.create(args)
|
41
|
+
end
|
42
|
+
return rc
|
43
|
+
end
|
44
|
+
|
25
45
|
end
|
data/lib/role.rb
CHANGED
@@ -2,6 +2,8 @@ class Role < ActiveRecord::Base
|
|
2
2
|
set_table_name :role_
|
3
3
|
set_primary_key :roleid
|
4
4
|
|
5
|
+
acts_as_resourceful
|
6
|
+
|
5
7
|
validates_uniqueness_of :name, :scope => 'companyid'
|
6
8
|
|
7
9
|
# com.liferay.portal.model.Role
|
@@ -71,22 +73,8 @@ class Role < ActiveRecord::Base
|
|
71
73
|
# +33 29 10109
|
72
74
|
# +34 30 10151
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
-
r = Resource.find(:first, :conditions => "codeid=#{rc.id} AND primkey='#{self.companyid}'")
|
77
|
-
unless r
|
78
|
-
Resource.create(
|
79
|
-
:codeid => rc.id,
|
80
|
-
:primkey => self.companyid
|
81
|
-
)
|
82
|
-
end
|
83
|
-
|
84
|
-
rc = self.resource_code(4)
|
85
|
-
raise 'Required ResourceCode not found' unless rc
|
86
|
-
r = Resource.create(
|
87
|
-
:codeid => rc.id,
|
88
|
-
:primkey => self.id
|
89
|
-
)
|
76
|
+
self.get_resource(:scope => 1)
|
77
|
+
r = self.get_resource(:scope => 4)
|
90
78
|
|
91
79
|
# Permissions (given to administrators)
|
92
80
|
|
@@ -109,13 +97,13 @@ class Role < ActiveRecord::Base
|
|
109
97
|
# +10129 76
|
110
98
|
|
111
99
|
self.class.actions.each do |actionid|
|
112
|
-
p = Permission.
|
100
|
+
p = Permission.get(
|
113
101
|
:companyid => self.companyid,
|
114
102
|
:actionid => actionid,
|
115
103
|
:resourceid => r.id
|
116
104
|
)
|
117
105
|
self.company.administrators.each do |user|
|
118
|
-
user.
|
106
|
+
user.permissions << p
|
119
107
|
end
|
120
108
|
end
|
121
109
|
end
|
@@ -131,7 +119,7 @@ class Role < ActiveRecord::Base
|
|
131
119
|
:conditions => "companyid=#{self.companyid} AND actionid='#{actionid}' AND resourceid=#{r.id}")
|
132
120
|
next unless p
|
133
121
|
p.users.each do |user|
|
134
|
-
user.
|
122
|
+
user.permissions.delete(p)
|
135
123
|
end
|
136
124
|
p.groups.each do |group|
|
137
125
|
group.permissions.delete(p)
|
@@ -157,8 +145,6 @@ class Role < ActiveRecord::Base
|
|
157
145
|
freeze
|
158
146
|
end
|
159
147
|
|
160
|
-
|
161
|
-
|
162
148
|
belongs_to :company,
|
163
149
|
:foreign_key => "companyid"
|
164
150
|
|
@@ -179,10 +165,4 @@ class Role < ActiveRecord::Base
|
|
179
165
|
:foreign_key => "roleid",
|
180
166
|
:association_foreign_key => "groupid"
|
181
167
|
|
182
|
-
# ResourceCode associated to this instance (and scope)
|
183
|
-
def resource_code(scope=4)
|
184
|
-
ResourceCode.find(:first,
|
185
|
-
:conditions => "companyid=#{self.companyid} AND name='#{self.liferay_class}' AND scope=#{scope}")
|
186
|
-
end
|
187
|
-
|
188
168
|
end
|
data/lib/tag/asset.rb
CHANGED
@@ -4,14 +4,14 @@ module Tag
|
|
4
4
|
set_table_name :tagsasset
|
5
5
|
set_primary_key :assetid
|
6
6
|
|
7
|
+
|
7
8
|
# com.liferay.portlet.tags.model.TagsAsset
|
8
9
|
def liferay_class
|
9
10
|
'com.liferay.portlet.tags.model.TagsAsset'
|
10
11
|
end
|
11
12
|
|
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
|
-
|
13
|
+
# 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;
|
14
|
+
# +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
|
15
15
|
|
16
16
|
def initialize(params)
|
17
17
|
super(params)
|
@@ -101,9 +101,31 @@ module Tag
|
|
101
101
|
if self.resource.respond_to?(:name) && self.resource.name.any?
|
102
102
|
return self.resource.name
|
103
103
|
else
|
104
|
-
|
104
|
+
logger.warn 'Asset %i has no title' % self.id
|
105
|
+
return ''
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Presents the Asset resource in a portlet that is capable of viewing tagged content.
|
110
|
+
# This depends on the version of Liferay. See Group#asset_viewer_portlet.
|
111
|
+
#
|
112
|
+
# This method requires that the Asset belongs to a Group, or that the portletpreferences is given.
|
113
|
+
#
|
114
|
+
# Params:
|
115
|
+
# - content_id the id of the resource (not always self.resource.id)
|
116
|
+
# - portletpreferences defaults to the asset_viewer_portlet of the Asset's Group.
|
117
|
+
def path(portletpreferences=self.group.asset_viewer_portlet)
|
118
|
+
if self.group==0
|
119
|
+
logger.warn 'No asset path will be given for assets with groupid 0'
|
120
|
+
return ''
|
121
|
+
elsif !portletpreferences.is_a?(Web::PortletPreferences)
|
122
|
+
logger.error 'No portletpreferences for asset display given'
|
105
123
|
return ''
|
106
124
|
end
|
125
|
+
logger.debug portletpreferences.inspect
|
126
|
+
path = portletpreferences.path(:asset => self)
|
127
|
+
logger.debug path
|
128
|
+
return path
|
107
129
|
end
|
108
130
|
|
109
131
|
end
|
data/lib/user.rb
CHANGED
@@ -3,6 +3,8 @@ class User < ActiveRecord::Base
|
|
3
3
|
set_table_name :user_
|
4
4
|
set_primary_key :userid
|
5
5
|
|
6
|
+
acts_as_resourceful
|
7
|
+
|
6
8
|
validates_uniqueness_of :uuid_
|
7
9
|
validates_uniqueness_of :emailaddress, :scope => :companyid
|
8
10
|
validates_uniqueness_of :screenname, :scope => :companyid
|
@@ -131,23 +133,16 @@ class User < ActiveRecord::Base
|
|
131
133
|
# +10168 10166 10109 f f 0 01 mobile 01 0
|
132
134
|
|
133
135
|
|
134
|
-
# scope=4 means that the resource is "owned" by User
|
135
|
-
rc = self.resource_code(4)
|
136
|
-
raise 'Required ResourceCode not found' unless rc
|
137
136
|
|
138
137
|
# insert data into counter_ so that Hibernate won't die
|
139
|
-
|
138
|
+
# Counter.increment(:resource, 100)
|
140
139
|
|
141
140
|
# COPY resource_ (resourceid, codeid, primkey) FROM stdin;
|
142
141
|
# +44 5 10164
|
143
142
|
|
144
|
-
|
145
|
-
|
146
|
-
:primkey => self.id
|
147
|
-
)
|
143
|
+
# scope=4 means that the resource is "owned" by User
|
144
|
+
resource = get_resource(:scope => 4)
|
148
145
|
|
149
|
-
permissions = []
|
150
|
-
# insert data into counter_ so that Hibernate won't die
|
151
146
|
|
152
147
|
# COPY permission_ (permissionid, companyid, actionid, resourceid) FROM stdin;
|
153
148
|
# +114 10109 DELETE 44
|
@@ -163,9 +158,10 @@ class User < ActiveRecord::Base
|
|
163
158
|
# +10129 117
|
164
159
|
# +10129 118
|
165
160
|
|
166
|
-
|
161
|
+
# insert data into counter_ so that Hibernate won't die
|
162
|
+
# Counter.increment(:permission, 100)
|
167
163
|
self.class.actions.each do |action|
|
168
|
-
self.
|
164
|
+
self.permissions << Permission.get(
|
169
165
|
:companyid => self.companyid,
|
170
166
|
:actionid => action,
|
171
167
|
:resourceid => resource.id
|
@@ -239,7 +235,7 @@ class User < ActiveRecord::Base
|
|
239
235
|
:association_foreign_key => 'roleid'
|
240
236
|
|
241
237
|
# association to direct user permissions.
|
242
|
-
has_and_belongs_to_many :
|
238
|
+
has_and_belongs_to_many :permissions,
|
243
239
|
:class_name => 'Permission',
|
244
240
|
:join_table => 'users_permissions',
|
245
241
|
:foreign_key => 'userid',
|
@@ -289,8 +285,8 @@ class User < ActiveRecord::Base
|
|
289
285
|
|
290
286
|
# All permissions that the user has.
|
291
287
|
# Permissions are summed up from user, group and role permissions.
|
292
|
-
def
|
293
|
-
|
288
|
+
def all_permissions
|
289
|
+
(self.permissions + group_permissions + role_permissions).flatten
|
294
290
|
end
|
295
291
|
|
296
292
|
|
@@ -479,12 +475,6 @@ class User < ActiveRecord::Base
|
|
479
475
|
self.address.save
|
480
476
|
end
|
481
477
|
|
482
|
-
# ResourceCode associated to this instance (and scope)
|
483
|
-
def resource_code(scope=4)
|
484
|
-
ResourceCode.find(:first,
|
485
|
-
:conditions => "companyid=#{self.companyid} AND name='#{self.liferay_class}' AND scope=#{scope}")
|
486
|
-
end
|
487
|
-
|
488
478
|
# Resources associated to this instance
|
489
479
|
def resources
|
490
480
|
Resource.find(:all, :conditions => "primkey='#{self.id}'")
|
@@ -517,13 +507,20 @@ class User < ActiveRecord::Base
|
|
517
507
|
|
518
508
|
# URL path to this User's public or private page
|
519
509
|
def path(pl=:public)
|
520
|
-
self.hive.nil? ?
|
510
|
+
self.hive.nil? ? '' : self.hive.path(pl)
|
521
511
|
end
|
522
512
|
|
523
513
|
# URL to user's portrait (needs to be prefixed with Liferay server URL).
|
524
514
|
# Unless the user has a portrait, a default image should be displayed.
|
525
515
|
def portrait_path
|
526
|
-
|
516
|
+
gender = (
|
517
|
+
if self.contact
|
518
|
+
self.contact.male ? 'male' : 'female'
|
519
|
+
else
|
520
|
+
'male'
|
521
|
+
end
|
522
|
+
)
|
523
|
+
path = '/image/user_%s_portrait' % gender
|
527
524
|
path << "?img_id=#{self.portraitid}" if self.portraitid != 0
|
528
525
|
return path
|
529
526
|
end
|