lportal 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README +81 -10
- data/lib/blog_post.rb +7 -7
- data/lib/bookmark/entry.rb +4 -0
- data/lib/contact.rb +1 -1
- data/lib/dl_file.rb +1 -0
- data/lib/dl_folder.rb +4 -0
- data/lib/group.rb +183 -4
- data/lib/ig/image.rb +1 -0
- data/lib/journal/article_resource.rb +1 -0
- data/lib/mb/category.rb +168 -1
- data/lib/mb/message.rb +4 -0
- data/lib/resource_code.rb +12 -0
- data/lib/role.rb +169 -0
- data/lib/tag/asset.rb +16 -3
- data/lib/tag/entry.rb +1 -0
- data/lib/user.rb +136 -31
- data/lib/web/layout.rb +148 -0
- data/lib/web/portlet_preferences.rb +1 -1
- data/lib/web/typesettings.rb +113 -0
- data/lib/wiki/pageresource.rb +1 -0
- data/test/unit/blog_post_test.rb +6 -0
- data/test/unit/group_test.rb +111 -5
- data/test/unit/mb/category_test.rb +63 -1
- data/test/unit/phone_test.rb +33 -0
- data/test/unit/role_test.rb +127 -8
- data/test/unit/tag/asset_test.rb +24 -12
- data/test/unit/user_test.rb +189 -1
- data/test/unit/web/layout_test.rb +62 -6
- data/test/unit/web/typesettings_test.rb +54 -0
- data/version.rb +1 -1
- metadata +5 -2
data/README
CHANGED
@@ -9,20 +9,91 @@ This is a collection of (some) Liferay models for developers that use the databa
|
|
9
9
|
2. require 'lportal'
|
10
10
|
3. You're good to go.
|
11
11
|
|
12
|
-
This gem quite effectively pollutes your namespace, and that is intentional. If you are working in the context of the portal, having your users modeled by User is more convenient rather than having to reference them as Lportal::Users.
|
12
|
+
This gem quite effectively pollutes your namespace, and that is intentional. If you are working in the context of the portal, having your users modeled by User is more convenient rather than having to reference them as "Lportal::Users".
|
13
13
|
|
14
14
|
|
15
|
-
==
|
16
|
-
|
17
|
-
|
15
|
+
== General notions and examples
|
16
|
+
=== Caterpillar
|
17
|
+
To create new instances you need Caterpillar. Liferay's ORM, Hibernate, does not seem to use database sequences, but ActiveRecord assumes they exist. Caterpillar's purpose is to lower the barriers to deploy Rails portlets and it contains various tasks that do not belong to this library. See the Caterpillar docs on installation; this document assumes your environment is set up. Do not forget to run the migrations!
|
18
18
|
|
19
|
-
title = 'Message Boards'
|
20
|
-
g = Group.find 15833
|
21
19
|
|
22
|
-
|
23
|
-
|
20
|
+
=== Layouts
|
21
|
+
Each Group can have public and private pages. In both cases, there has to first exist a Web::LayoutSet, which is automatically created for a new Group. The individual pages (class Web::Layout) belong to this set, but they are not directly linked (in 5.1.1 at least). Instead, they belong to the Group and are either public or private. The models have methods to query the relations.
|
24
22
|
|
25
|
-
|
23
|
+
Say you create a new Group "group".
|
26
24
|
|
25
|
+
company = Company.first
|
26
|
+
group = Group.create(
|
27
|
+
:company => company,
|
28
|
+
:creatoruserid => company.administrators.first.id,
|
29
|
+
:name => 'Example'
|
30
|
+
)
|
27
31
|
|
28
|
-
|
32
|
+
=> #<Group groupid: 8400004, companyid: 10109, creatoruserid: 10129, classnameid: 0, classpk: 0, parentgroupid: 0, livegroupid: 0, name: "Example", description: "", type_: 1, typesettings: "", friendlyurl: "/example", active_: true>
|
33
|
+
|
34
|
+
The LayoutSets can then be queried:
|
35
|
+
|
36
|
+
group.public_layoutset
|
37
|
+
|
38
|
+
=> #<Web::LayoutSet layoutsetid: 8400011, groupid: 8400004, companyid: 10109, privatelayout: false, logo: false, logoid: 0, themeid: "", colorschemeid: "01", wapthemeid: "mobile", wapcolorschemeid: "01", css: "", pagecount: 0, virtualhost: "">
|
39
|
+
|
40
|
+
group.private_layoutset
|
41
|
+
|
42
|
+
=> #<Web::LayoutSet layoutsetid: 8400010, groupid: 8400004, companyid: 10109, privatelayout: true, logo: false, logoid: 0, themeid: "", colorschemeid: "01", wapthemeid: "mobile", wapcolorschemeid: "01", css: "", pagecount: 0, virtualhost: "">
|
43
|
+
|
44
|
+
group.layoutsets.size
|
45
|
+
|
46
|
+
=> 2
|
47
|
+
|
48
|
+
And a new empty Layout can be created:
|
49
|
+
|
50
|
+
layout = Web::Layout.create(
|
51
|
+
:group => group,
|
52
|
+
:privatelayout => true,
|
53
|
+
:name => 'Private page'
|
54
|
+
)
|
55
|
+
|
56
|
+
=> #<Web::Layout plid: 8400000, groupid: 8400004, companyid: 10109, privatelayout: true, layoutid: 1, parentlayoutid: 0, name: "<?xml version='1.0' encoding='UTF-8'?><root availab...", title: "<root />", description: "", type_: "portlet", typesettings: "layout-template-id=2_columns_ii\n", hidden_: false, friendlyurl: "/1", iconimage: false, iconimageid: 0, themeid: nil, colorschemeid: nil, wapthemeid: nil, wapcolorschemeid: nil, css: nil, priority: 0, dlfolderid: 0>
|
57
|
+
|
58
|
+
You can view this page in the Liferay "Communities" portlet via "Available Communities" => "Actions" => "Manage Pages" => "Private Pages" => "View Pages".
|
59
|
+
|
60
|
+
|
61
|
+
=== Portlets and Caterpillar
|
62
|
+
To add new portlets the Caterpillar mixins and migrations are required. This data does not live in the lportal database, and this library does not understand about the environment in which Liferay is. Caterpillar, however, does. It parses some Liferay XML configuration files and makes the data available by defining a couple of new methods to classes in the Web module.
|
63
|
+
|
64
|
+
The Layout contents are defined in its typesettings. The Web::Typesettings class makes their definitions more Ruby-like. To add a message_boards portlet into column 2:
|
65
|
+
|
66
|
+
layout.typesettings = Web::Typesettings.new.message_boards(:column => 2).to_s
|
67
|
+
|
68
|
+
=> "layout-template-id=2_columns_ii\ncolumn-2=19,"
|
69
|
+
|
70
|
+
|
71
|
+
The other way around, find the private layouts of "group" that have the Message Board portlet:
|
72
|
+
|
73
|
+
layouts = group.private_layouts.select{|l| l.contents.include?('message_boards')}
|
74
|
+
|
75
|
+
Or, using a method designed for this:
|
76
|
+
|
77
|
+
layouts = group.select_layouts_with('message_boards',:private)
|
78
|
+
=> [#<Web::Layout plid: 8400000, groupid: 8400004, companyid: 10109, privatelayout: true, layoutid: 1, parentlayoutid: 0, name: "<?xml version='1.0' encoding='UTF-8'?><root availab...", title: "<root />", description: "", type_: "portlet", typesettings: "layout-template-id=2_columns_ii\ncolumn-2=19,", hidden_: false, friendlyurl: "/1", iconimage: false, iconimageid: 0, themeid: nil, colorschemeid: nil, wapthemeid: nil, wapcolorschemeid: nil, css: nil, priority: 0, dlfolderid: 0>]
|
79
|
+
|
80
|
+
Or query what portlets are in the Layout:
|
81
|
+
|
82
|
+
layouts.first.portlets.each{|p| puts p.title}
|
83
|
+
|
84
|
+
Message Boards
|
85
|
+
=> [#<Web::PortletPreferences portletpreferencesid: 10210, ownerid: 0, ownertype: 3, plid: 10146, portletid: "19", preferences: "<portlet-preferences xmlns=\"http://java.sun.com/xml...">]
|
86
|
+
|
87
|
+
Or whether the layouts include a specific portlet:
|
88
|
+
|
89
|
+
group.layouts_include?('message_boards')
|
90
|
+
=> true
|
91
|
+
group.layouts_include?('message_boards',:private)
|
92
|
+
=> true
|
93
|
+
group.layouts_include?('message_boards',:public)
|
94
|
+
=> false
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
Copyright (c) 2008,2009 Mikael Lammentausta, released under the MIT license
|
data/lib/blog_post.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# TODO: rename to Blog::Entry
|
1
2
|
class BlogPost < ActiveRecord::Base
|
2
3
|
set_table_name :blogsentry
|
3
4
|
set_primary_key :entryid
|
@@ -22,14 +23,13 @@ class BlogPost < ActiveRecord::Base
|
|
22
23
|
alias :community :group
|
23
24
|
|
24
25
|
has_one :asset,
|
26
|
+
:class_name => 'Tag::Asset',
|
25
27
|
:foreign_key => 'classpk'
|
26
28
|
|
27
|
-
# #
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
# :association_foreign_key => 'assetid'
|
33
|
-
|
29
|
+
# # URL path to this BlogPost.
|
30
|
+
# # Layout should contain the 'tagged_content' portlet.
|
31
|
+
# def path(layout)
|
32
|
+
# basic_asset_url(content_viewer)
|
33
|
+
# end
|
34
34
|
|
35
35
|
end
|
data/lib/bookmark/entry.rb
CHANGED
data/lib/contact.rb
CHANGED
data/lib/dl_file.rb
CHANGED
data/lib/dl_folder.rb
CHANGED
data/lib/group.rb
CHANGED
@@ -10,17 +10,137 @@ class Group < ActiveRecord::Base
|
|
10
10
|
'com.liferay.portal.model.Group'
|
11
11
|
end
|
12
12
|
|
13
|
+
# Actions for Permissions.
|
14
|
+
def self.actions
|
15
|
+
%w{
|
16
|
+
APPROVE_PROPOSAL
|
17
|
+
ASSIGN_MEMBERS
|
18
|
+
ASSIGN_REVIEWER
|
19
|
+
DELETE
|
20
|
+
MANAGE_ANNOUNCEMENTS
|
21
|
+
MANAGE_ARCHIVED_SETUPS
|
22
|
+
MANAGE_LAYOUTS
|
23
|
+
MANAGE_STAGING
|
24
|
+
PERMISSIONS
|
25
|
+
PUBLISH_STAGING
|
26
|
+
UPDATE
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
# Creates a new group (community).
|
31
|
+
#
|
32
|
+
#
|
33
|
+
# Some instances are created based on the Classname of the Group.
|
34
|
+
# User's own group, for instance, has to be created with classnameid and classpk.
|
35
|
+
#
|
36
|
+
# The Group may also have public and private Web::LayoutSet s.
|
37
|
+
#
|
38
|
+
# This process is engineered by creating a new role with Liferay's (v. 5.1.1) tools and
|
39
|
+
# inspecting the database dump diffs.
|
40
|
+
#
|
41
|
+
# Mandatory parameters:
|
42
|
+
# - companyid
|
43
|
+
# - creatoruserid
|
13
44
|
def initialize(params)
|
45
|
+
raise 'No companyid given' unless (params[:companyid] or params[:company])
|
46
|
+
raise 'No creatoruserid given' unless params[:creatoruserid]
|
47
|
+
raise 'No name given' if (
|
48
|
+
params[:name].nil? and (params[:classnameid].nil? or params[:classnameid]==0))
|
49
|
+
|
14
50
|
super(params)
|
51
|
+
|
52
|
+
# COPY group_ (groupid, companyid, creatoruserid, classnameid, classpk, parentgroupid, livegroupid, name, description, type_, typesettings, friendlyurl, active_) FROM stdin;
|
53
|
+
# +10155 10109 10129 0 0 0 0 testiyhteisö open testataan yhteisön luomista 1 /10155 t
|
54
|
+
|
55
|
+
self.classnameid ||= 0 # Community
|
56
|
+
self.classpk ||= 0 # -"-
|
15
57
|
self.parentgroupid ||= 0
|
16
58
|
self.livegroupid ||= 0
|
17
|
-
self.type_ ||= 0
|
18
|
-
self.active_ ||= true
|
19
59
|
self.name ||= ''
|
20
60
|
self.description ||= ''
|
61
|
+
self.type_ ||= 1
|
21
62
|
self.typesettings ||= ''
|
63
|
+
self.active_ ||= true
|
64
|
+
|
65
|
+
unless self.friendlyurl
|
66
|
+
self.friendlyurl = (
|
67
|
+
case self.classnameid
|
68
|
+
when 0
|
69
|
+
'/'+self.name.downcase
|
70
|
+
else
|
71
|
+
self.friendlyurl ||= '/%i' % self.id
|
72
|
+
end
|
73
|
+
)
|
74
|
+
end
|
22
75
|
|
23
76
|
self.save
|
77
|
+
|
78
|
+
# public and private layoutsets
|
79
|
+
|
80
|
+
# COPY layoutset (layoutsetid, groupid, companyid, privatelayout, logo, logoid, themeid, colorschemeid, wapthemeid, wapcolorschemeid, css, pagecount, virtualhost) FROM stdin;
|
81
|
+
# +10156 10155 10109 t f 0 01 mobile 01 0
|
82
|
+
# +10157 10155 10109 f f 0 01 mobile 01 0
|
83
|
+
|
84
|
+
[true, false].each do |privacy|
|
85
|
+
Web::LayoutSet.create(
|
86
|
+
:groupid => self.id,
|
87
|
+
:companyid => self.companyid,
|
88
|
+
:privatelayout => privacy
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
### GROUP
|
93
|
+
unless self.classnameid == 0
|
94
|
+
# Type is != 0 only for Groups of type Group (?)
|
95
|
+
self.type_ = 0
|
96
|
+
self.save
|
97
|
+
else
|
98
|
+
|
99
|
+
# COPY resource_ (resourceid, codeid, primkey) FROM stdin;
|
100
|
+
# +41 6 10155
|
101
|
+
#
|
102
|
+
# Create a resource with scope=4 for this Layout.
|
103
|
+
rc = self.resource_code(4)
|
104
|
+
unless rc
|
105
|
+
rc = ResourceCode.create(
|
106
|
+
:companyid => self.companyid,
|
107
|
+
:name => self.liferay_class,
|
108
|
+
:scope => 4
|
109
|
+
)
|
110
|
+
end
|
111
|
+
r = Resource.create(
|
112
|
+
:codeid => rc.id,
|
113
|
+
:primkey => self.id
|
114
|
+
)
|
115
|
+
|
116
|
+
# Permissions (given to administrators)
|
117
|
+
|
118
|
+
#
|
119
|
+
# COPY permission_ (permissionid, companyid, actionid, resourceid) FROM stdin;
|
120
|
+
# +81 10109 APPROVE_PROPOSAL 41
|
121
|
+
# +82 10109 ASSIGN_MEMBERS 41
|
122
|
+
# +83 10109 ASSIGN_REVIEWER 41
|
123
|
+
# +84 10109 DELETE 41
|
124
|
+
# +85 10109 MANAGE_ANNOUNCEMENTS 41
|
125
|
+
# +86 10109 MANAGE_ARCHIVED_SETUPS 41
|
126
|
+
# +87 10109 MANAGE_LAYOUTS 41
|
127
|
+
# +88 10109 MANAGE_STAGING 41
|
128
|
+
# +89 10109 PERMISSIONS 41
|
129
|
+
# +90 10109 PUBLISH_STAGING 41
|
130
|
+
# +91 10109 UPDATE 41
|
131
|
+
#
|
132
|
+
|
133
|
+
self.class.actions.each do |actionid|
|
134
|
+
p = Permission.create(
|
135
|
+
:companyid => self.companyid,
|
136
|
+
:actionid => actionid,
|
137
|
+
:resourceid => r.id
|
138
|
+
)
|
139
|
+
self.company.administrators.each do |user|
|
140
|
+
user.user_permissions << p
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
24
144
|
end
|
25
145
|
|
26
146
|
belongs_to :company,
|
@@ -69,6 +189,7 @@ class Group < ActiveRecord::Base
|
|
69
189
|
|
70
190
|
# association to assets
|
71
191
|
has_many :assets,
|
192
|
+
:class_name => 'Tag::Asset',
|
72
193
|
:foreign_key => 'groupid'
|
73
194
|
|
74
195
|
# a group may have two layoutsets (public and private)
|
@@ -101,6 +222,11 @@ class Group < ActiveRecord::Base
|
|
101
222
|
:foreign_key => 'groupid',
|
102
223
|
:conditions => 'privatelayout = true'
|
103
224
|
|
225
|
+
def name
|
226
|
+
self.classnameid != 0 ?
|
227
|
+
self.owner.name : super
|
228
|
+
end
|
229
|
+
|
104
230
|
# find owner by classnameid + classpk
|
105
231
|
def owner
|
106
232
|
return nil if self.classnameid==0
|
@@ -108,6 +234,29 @@ class Group < ActiveRecord::Base
|
|
108
234
|
_class.find self.classpk
|
109
235
|
end
|
110
236
|
|
237
|
+
# Members by the group type, ie. if the group is of type Organization, return Organization members.
|
238
|
+
def members
|
239
|
+
if self.owner.kind_of?(Organization)
|
240
|
+
return self.owner.members
|
241
|
+
else
|
242
|
+
#[self.users, self.organizations.collect(&:users)].flatten
|
243
|
+
return self.users
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
# Assign User to be a member of this Group
|
248
|
+
def assign_membership(user)
|
249
|
+
raise 'TODO'
|
250
|
+
# COPY usergrouprole (userid, groupid, roleid) FROM stdin;
|
251
|
+
# +10129 10155 10120
|
252
|
+
# +10129 10155 10119
|
253
|
+
#
|
254
|
+
# COPY users_groups (userid, groupid) FROM stdin;
|
255
|
+
# +10129 10155
|
256
|
+
#
|
257
|
+
end
|
258
|
+
|
259
|
+
|
111
260
|
has_one :resource,
|
112
261
|
:foreign_key => 'primkey'
|
113
262
|
|
@@ -131,7 +280,7 @@ class Group < ActiveRecord::Base
|
|
131
280
|
self.type_ == 3
|
132
281
|
end
|
133
282
|
|
134
|
-
#
|
283
|
+
# URL path to this Group's public or private page
|
135
284
|
def path(pl=:public)
|
136
285
|
case pl
|
137
286
|
when :public
|
@@ -147,5 +296,35 @@ class Group < ActiveRecord::Base
|
|
147
296
|
end
|
148
297
|
end
|
149
298
|
|
299
|
+
# ResourceCode associated to this instance (and scope)
|
300
|
+
def resource_code(scope=4)
|
301
|
+
ResourceCode.find(:first,
|
302
|
+
:conditions => "companyid=#{self.companyid} AND name='#{self.liferay_class}' AND scope=#{scope}")
|
303
|
+
end
|
304
|
+
|
305
|
+
# Selects the layout (from both public and private) that has the portlet.
|
306
|
+
# Parameters:
|
307
|
+
# - portlet can be either a String of portlet name (eg. 'message_boards') or a Web::PortletName instance.
|
308
|
+
# - pl only check public or private layouts? defaults to both. ( nil | :public | :private )
|
309
|
+
def select_layouts_with(portlet,pl=nil)
|
310
|
+
layouts = (
|
311
|
+
if pl.nil?
|
312
|
+
self.layouts
|
313
|
+
elsif pl==:public
|
314
|
+
self.public_layouts
|
315
|
+
elsif pl==:private
|
316
|
+
self.private_layouts
|
317
|
+
else
|
318
|
+
[]
|
319
|
+
end
|
320
|
+
)
|
321
|
+
|
322
|
+
layouts.select{|l| l.contents.include?(portlet)}
|
323
|
+
end
|
324
|
+
|
325
|
+
# Does any of the layouts include this portlet? See #select_layouts_with
|
326
|
+
def layouts_include?(portlet,pl=nil)
|
327
|
+
self.select_layouts_with(portlet,pl).any?
|
328
|
+
end
|
150
329
|
|
151
|
-
end
|
330
|
+
end
|
data/lib/ig/image.rb
CHANGED
data/lib/mb/category.rb
CHANGED
@@ -4,11 +4,163 @@ module MB
|
|
4
4
|
set_table_name :mbcategory
|
5
5
|
set_primary_key :categoryid
|
6
6
|
|
7
|
+
validates_uniqueness_of :uuid_
|
8
|
+
|
7
9
|
# com.liferay.portlet.messageboards.model.MBCategory
|
8
10
|
def liferay_class
|
9
11
|
'com.liferay.portlet.messageboards.model.MBCategory'
|
10
12
|
end
|
11
13
|
|
14
|
+
# Actions for Permissions.
|
15
|
+
def self.actions
|
16
|
+
%w{
|
17
|
+
ADD_FILE
|
18
|
+
ADD_MESSAGE
|
19
|
+
ADD_SUBCATEGORY
|
20
|
+
DELETE
|
21
|
+
MOVE_THREAD
|
22
|
+
PERMISSIONS
|
23
|
+
REPLY_TO_MESSAGE
|
24
|
+
SUBSCRIBE
|
25
|
+
UPDATE
|
26
|
+
UPDATE_THREAD_PRIORITY
|
27
|
+
VIEW
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
# Creates a new Message Board category.
|
32
|
+
#
|
33
|
+
# This process is engineered by creating a new layout with Liferay's (v. 5.1.1) tools and
|
34
|
+
# inspecting the database dump diffs.
|
35
|
+
#
|
36
|
+
# Mandatory parameters:
|
37
|
+
# - groupid
|
38
|
+
# - name
|
39
|
+
def initialize(params)
|
40
|
+
raise 'No groupid given' unless (params[:groupid] or params[:group])
|
41
|
+
raise 'No name given' unless params[:name]
|
42
|
+
super(params)
|
43
|
+
|
44
|
+
# COPY mbcategory (uuid_, categoryid, groupid, companyid, userid, username, createdate, modifieddate, parentcategoryid, name, description, lastpostdate) FROM stdin;
|
45
|
+
# +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
|
46
|
+
|
47
|
+
unless self.uuid_
|
48
|
+
require 'rubygems'
|
49
|
+
require 'uuidtools'
|
50
|
+
self.uuid_ = UUID.random_create.to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
self.companyid = self.group.companyid
|
54
|
+
|
55
|
+
# owner (if undefined, use admin)
|
56
|
+
unless self.userid
|
57
|
+
user = Company.first.administrators.first
|
58
|
+
self.userid ||= user.id
|
59
|
+
end
|
60
|
+
self.username ||= self.user.fullname
|
61
|
+
self.createdate = Time.now
|
62
|
+
self.modifieddate = Time.now
|
63
|
+
self.parentcategoryid ||= 0
|
64
|
+
self.description ||= ''
|
65
|
+
|
66
|
+
self.save
|
67
|
+
|
68
|
+
# ResourceCode with scope 1 => Resource for Company
|
69
|
+
# ResourceCode with scope 2 => Resource for this Group and Guest's Group
|
70
|
+
# ResourceCode with scope 4 => Resource for self
|
71
|
+
|
72
|
+
# COPY resourcecode (codeid, companyid, name, scope) FROM stdin;
|
73
|
+
# +104 10109 com.liferay.portlet.messageboards.model.MBCategory 1
|
74
|
+
# +105 10109 com.liferay.portlet.messageboards.model.MBCategory 2
|
75
|
+
# +106 10109 com.liferay.portlet.messageboards.model.MBCategory 4
|
76
|
+
|
77
|
+
# COPY resource_ (resourceid, codeid, primkey) FROM stdin;
|
78
|
+
# +210 104 10109
|
79
|
+
# +211 105 10124
|
80
|
+
# +212 105 10166
|
81
|
+
# +213 106 10307
|
82
|
+
|
83
|
+
rc = self.resource_code(1)
|
84
|
+
unless rc
|
85
|
+
rc = ResourceCode.create(
|
86
|
+
:companyid => self.companyid,
|
87
|
+
:name => self.liferay_class,
|
88
|
+
:scope => 1
|
89
|
+
)
|
90
|
+
end
|
91
|
+
unless Resource.find(:first, :conditions => "codeid=#{rc.id} AND primkey='#{self.companyid}'")
|
92
|
+
Resource.create(
|
93
|
+
:codeid => rc.id,
|
94
|
+
:primkey => self.companyid
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
rc = self.resource_code(2)
|
99
|
+
unless rc
|
100
|
+
rc = ResourceCode.create(
|
101
|
+
:companyid => self.companyid,
|
102
|
+
:name => self.liferay_class,
|
103
|
+
:scope => 2
|
104
|
+
)
|
105
|
+
end
|
106
|
+
unless Resource.find(:first, :conditions => "codeid=#{rc.id} AND primkey='#{self.group.id}'")
|
107
|
+
Resource.create(
|
108
|
+
:codeid => rc.id,
|
109
|
+
:primkey => self.group.id
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Create a resource with scope=4 for this Layout.
|
114
|
+
rc = self.resource_code(4)
|
115
|
+
unless rc
|
116
|
+
rc = ResourceCode.create(
|
117
|
+
:companyid => self.companyid,
|
118
|
+
:name => self.liferay_class,
|
119
|
+
:scope => 4
|
120
|
+
)
|
121
|
+
end
|
122
|
+
resource = Resource.create(
|
123
|
+
:codeid => rc.id,
|
124
|
+
:primkey => self.id
|
125
|
+
)
|
126
|
+
|
127
|
+
# Permissions to scope 4
|
128
|
+
|
129
|
+
# COPY permission_ (permissionid, companyid, actionid, resourceid) FROM stdin;
|
130
|
+
# +312 10109 ADD_FILE 213
|
131
|
+
# +313 10109 ADD_MESSAGE 213
|
132
|
+
# +314 10109 ADD_SUBCATEGORY 213
|
133
|
+
# +315 10109 DELETE 213
|
134
|
+
# +316 10109 MOVE_THREAD 213
|
135
|
+
# +317 10109 PERMISSIONS 213
|
136
|
+
# +318 10109 REPLY_TO_MESSAGE 213
|
137
|
+
# +319 10109 SUBSCRIBE 213
|
138
|
+
# +320 10109 UPDATE 213
|
139
|
+
# +321 10109 UPDATE_THREAD_PRIORITY 213
|
140
|
+
# +322 10109 VIEW 213
|
141
|
+
|
142
|
+
# COPY users_permissions (userid, permissionid) FROM stdin;
|
143
|
+
# +10129 312
|
144
|
+
# +10129 313
|
145
|
+
# +10129 314
|
146
|
+
# +10129 315
|
147
|
+
# +10129 316
|
148
|
+
# +10129 317
|
149
|
+
# +10129 318
|
150
|
+
# +10129 319
|
151
|
+
# +10129 320
|
152
|
+
# +10129 321
|
153
|
+
# +10129 322
|
154
|
+
|
155
|
+
self.class.actions.each do |actionid|
|
156
|
+
self.user.user_permissions << Permission.create(
|
157
|
+
:companyid => self.companyid,
|
158
|
+
:actionid => actionid,
|
159
|
+
:resourceid => resource.id
|
160
|
+
)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
12
164
|
belongs_to :group,
|
13
165
|
:foreign_key => "groupid"
|
14
166
|
|
@@ -26,7 +178,7 @@ module MB
|
|
26
178
|
# :class_name => self.class,
|
27
179
|
# :foreign_key => "parentcategoryid"
|
28
180
|
|
29
|
-
#
|
181
|
+
# Parent Category, nil if this is already root.
|
30
182
|
def parent
|
31
183
|
self.parentcategoryid != 0 ? MB::Category.find(self.parentcategoryid) : nil
|
32
184
|
end
|
@@ -43,5 +195,20 @@ module MB
|
|
43
195
|
:class_name => 'MB::Message',
|
44
196
|
:foreign_key => 'categoryid'
|
45
197
|
|
198
|
+
# ResourceCode associated to this instance (and scope)
|
199
|
+
def resource_code(scope=4)
|
200
|
+
ResourceCode.find(:first,
|
201
|
+
:conditions => "companyid=#{self.companyid} AND name='#{self.liferay_class}' AND scope=#{scope}")
|
202
|
+
end
|
203
|
+
|
204
|
+
# URL path to this Category. Works on Liferay 5.1.1.
|
205
|
+
# Parameters:
|
206
|
+
# - pl only check public or private layouts? defaults to both. ( nil | :public | :private )
|
207
|
+
def path(pl=nil)
|
208
|
+
layouts = self.group.select_layouts_with('message_boards',pl)
|
209
|
+
return nil unless layouts.any?
|
210
|
+
'%s/-/message_boards/category/%i' % [layouts.first.path, self.id]
|
211
|
+
end
|
212
|
+
|
46
213
|
end
|
47
214
|
end
|
data/lib/mb/message.rb
CHANGED
data/lib/resource_code.rb
CHANGED
@@ -10,4 +10,16 @@ class ResourceCode < ActiveRecord::Base
|
|
10
10
|
has_many :resources,
|
11
11
|
:foreign_key => "codeid"
|
12
12
|
|
13
|
+
# ResourceCode associated to an Liferay class
|
14
|
+
#
|
15
|
+
# Args:
|
16
|
+
# - :companyid
|
17
|
+
# - :name
|
18
|
+
# - :scope (defaults to 4)
|
19
|
+
def self.find_by_liferay_class(args={})
|
20
|
+
args.update(:scope => 4) unless args[:scope]
|
21
|
+
ResourceCode.find(:first,
|
22
|
+
:conditions => "companyid=#{args[:companyid]} AND name='#{args[:name]}' AND scope=#{args[:scope]}")
|
23
|
+
end
|
24
|
+
|
13
25
|
end
|