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/lib/role.rb
CHANGED
@@ -2,6 +2,163 @@ class Role < ActiveRecord::Base
|
|
2
2
|
set_table_name :role_
|
3
3
|
set_primary_key :roleid
|
4
4
|
|
5
|
+
validates_uniqueness_of :name, :scope => 'companyid'
|
6
|
+
|
7
|
+
# com.liferay.portal.model.Role
|
8
|
+
def liferay_class
|
9
|
+
'com.liferay.portal.model.Role'
|
10
|
+
end
|
11
|
+
|
12
|
+
# Actions for Permissions.
|
13
|
+
def self.actions
|
14
|
+
%w{
|
15
|
+
ASSIGN_MEMBERS
|
16
|
+
DEFINE_PERMISSIONS
|
17
|
+
DELETE
|
18
|
+
MANAGE_ANNOUNCEMENTS
|
19
|
+
PERMISSIONS
|
20
|
+
UPDATE
|
21
|
+
VIEW
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Creates a new role.
|
26
|
+
#
|
27
|
+
# This process is engineered by creating a new role with Liferay's (v. 5.1.1) tools and
|
28
|
+
# inspecting the database dump diffs.
|
29
|
+
#
|
30
|
+
# Mandatory parameters:
|
31
|
+
# - companyid
|
32
|
+
# - name
|
33
|
+
def initialize(params)
|
34
|
+
raise 'No companyid given' unless (params[:companyid] or params[:company])
|
35
|
+
raise 'No name given' unless params[:name]
|
36
|
+
|
37
|
+
super(params)
|
38
|
+
|
39
|
+
# COPY role_ (roleid, companyid, classnameid, classpk, name, description, type_) FROM stdin;
|
40
|
+
# +10151 10109 0 0 Regular role This role is a test 1
|
41
|
+
|
42
|
+
self.classnameid ||= 0
|
43
|
+
self.classpk ||= 0
|
44
|
+
self.description ||= ''
|
45
|
+
# Type: 1 = regular, 2 = community, 3 = organization
|
46
|
+
self.type_ ||= 1
|
47
|
+
|
48
|
+
self.save
|
49
|
+
|
50
|
+
# Resource with code scope 1 is primkey'd to company.
|
51
|
+
# Resource with code scope 4 is primkey'd to this role.
|
52
|
+
|
53
|
+
# These are created regardless of what type_ is.
|
54
|
+
|
55
|
+
# COPY resourcecode (codeid, companyid, name, scope) FROM stdin;
|
56
|
+
# +29 10109 com.liferay.portal.model.Role 1
|
57
|
+
# +30 10109 com.liferay.portal.model.Role 4
|
58
|
+
|
59
|
+
[1,4].each do |scope|
|
60
|
+
rc = self.resource_code(scope)
|
61
|
+
unless rc
|
62
|
+
ResourceCode.create(
|
63
|
+
:companyid => self.companyid,
|
64
|
+
:name => self.liferay_class,
|
65
|
+
:scope => scope
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# COPY resource_ (resourceid, codeid, primkey) FROM stdin;
|
71
|
+
# +33 29 10109
|
72
|
+
# +34 30 10151
|
73
|
+
|
74
|
+
rc = self.resource_code(1)
|
75
|
+
raise 'Required ResourceCode not found' unless rc
|
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
|
+
)
|
90
|
+
|
91
|
+
# Permissions (given to administrators)
|
92
|
+
|
93
|
+
# COPY permission_ (permissionid, companyid, actionid, resourceid) FROM stdin;
|
94
|
+
# +70 10109 ASSIGN_MEMBERS 34
|
95
|
+
# +71 10109 DEFINE_PERMISSIONS 34
|
96
|
+
# +72 10109 DELETE 34
|
97
|
+
# +73 10109 MANAGE_ANNOUNCEMENTS 34
|
98
|
+
# +74 10109 PERMISSIONS 34
|
99
|
+
# +75 10109 UPDATE 34
|
100
|
+
# +76 10109 VIEW 34
|
101
|
+
|
102
|
+
# COPY users_permissions (userid, permissionid) FROM stdin;
|
103
|
+
# +10129 70
|
104
|
+
# +10129 71
|
105
|
+
# +10129 72
|
106
|
+
# +10129 73
|
107
|
+
# +10129 74
|
108
|
+
# +10129 75
|
109
|
+
# +10129 76
|
110
|
+
|
111
|
+
self.class.actions.each do |actionid|
|
112
|
+
p = Permission.create(
|
113
|
+
:companyid => self.companyid,
|
114
|
+
:actionid => actionid,
|
115
|
+
:resourceid => r.id
|
116
|
+
)
|
117
|
+
self.company.administrators.each do |user|
|
118
|
+
user.user_permissions << p
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def destroy_without_callbacks
|
124
|
+
unless new_record?
|
125
|
+
rc = self.resource_code(4)
|
126
|
+
if rc
|
127
|
+
r = Resource.find(:first, :conditions => "codeid=#{rc.id} AND primkey='#{self.id}'")
|
128
|
+
if r
|
129
|
+
self.class.actions.each do |actionid|
|
130
|
+
p = Permission.find(:first,
|
131
|
+
:conditions => "companyid=#{self.companyid} AND actionid='#{actionid}' AND resourceid=#{r.id}")
|
132
|
+
next unless p
|
133
|
+
p.users.each do |user|
|
134
|
+
user.user_permissions.delete(p)
|
135
|
+
end
|
136
|
+
p.groups.each do |group|
|
137
|
+
group.permissions.delete(p)
|
138
|
+
end
|
139
|
+
p.destroy
|
140
|
+
end
|
141
|
+
r.destroy
|
142
|
+
end
|
143
|
+
rc.destroy
|
144
|
+
end
|
145
|
+
|
146
|
+
self.users.each do |user|
|
147
|
+
user.roles.delete(self)
|
148
|
+
end
|
149
|
+
|
150
|
+
self.groups.each do |group|
|
151
|
+
group.roles.delete(self)
|
152
|
+
end
|
153
|
+
|
154
|
+
super
|
155
|
+
|
156
|
+
end
|
157
|
+
freeze
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
|
5
162
|
belongs_to :company,
|
6
163
|
:foreign_key => "companyid"
|
7
164
|
|
@@ -16,4 +173,16 @@ class Role < ActiveRecord::Base
|
|
16
173
|
:foreign_key => "roleid",
|
17
174
|
:association_foreign_key => "userid"
|
18
175
|
|
176
|
+
# association to users
|
177
|
+
has_and_belongs_to_many :groups,
|
178
|
+
:join_table => "groups_roles",
|
179
|
+
:foreign_key => "roleid",
|
180
|
+
:association_foreign_key => "groupid"
|
181
|
+
|
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
|
+
|
19
188
|
end
|
data/lib/tag/asset.rb
CHANGED
@@ -33,13 +33,13 @@ module Tag
|
|
33
33
|
[
|
34
34
|
BlogPost,
|
35
35
|
Wiki::Page,
|
36
|
-
|
36
|
+
# MB::Message,
|
37
37
|
Journal::Article,
|
38
38
|
DlFile,
|
39
39
|
IG::Image,
|
40
40
|
Bookmark::Entry,
|
41
|
-
|
42
|
-
|
41
|
+
# Group,
|
42
|
+
# DlFolder
|
43
43
|
]
|
44
44
|
end
|
45
45
|
|
@@ -69,5 +69,18 @@ module Tag
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
+
# label (logic to fetch non-empty title)
|
73
|
+
def label
|
74
|
+
return self.title if self.title.any?
|
75
|
+
|
76
|
+
# fallback to the name of the resource
|
77
|
+
if self.resource.respond_to?(:name) && self.resource.name.any?
|
78
|
+
return self.resource.name
|
79
|
+
else
|
80
|
+
STDERR.puts 'Asset %i has no title' % self.id
|
81
|
+
return ''
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
72
85
|
end
|
73
86
|
end
|
data/lib/tag/entry.rb
CHANGED
data/lib/user.rb
CHANGED
@@ -4,24 +4,42 @@ class User < ActiveRecord::Base
|
|
4
4
|
set_primary_key :userid
|
5
5
|
|
6
6
|
validates_uniqueness_of :uuid_
|
7
|
-
validates_uniqueness_of :emailaddress
|
8
|
-
validates_uniqueness_of :screenname
|
7
|
+
validates_uniqueness_of :emailaddress, :scope => :companyid
|
8
|
+
validates_uniqueness_of :screenname, :scope => :companyid
|
9
9
|
|
10
10
|
public
|
11
11
|
|
12
12
|
# com.liferay.portal.model.User
|
13
|
-
def liferay_class
|
13
|
+
def self.liferay_class
|
14
14
|
'com.liferay.portal.model.User'
|
15
15
|
end
|
16
16
|
|
17
|
+
# FIXME: move all references from instance method to class method
|
18
|
+
def liferay_class
|
19
|
+
self.class.liferay_class
|
20
|
+
end
|
21
|
+
|
22
|
+
# Actions for Permissions.
|
23
|
+
def self.actions
|
24
|
+
%w{ DELETE IMPERSONATE PERMISSIONS UPDATE VIEW }
|
25
|
+
end
|
26
|
+
|
17
27
|
# Creates a new user.
|
18
28
|
#
|
19
29
|
# It is a complicated process, as Liferay inserts new data into many tables.
|
20
|
-
# This process is
|
21
|
-
#
|
30
|
+
# This process is engineered by creating a new role with Liferay's (v. 5.1.1) tools and
|
31
|
+
# inspecting the database dump diffs.
|
32
|
+
#
|
33
|
+
# Mandatory parameters:
|
34
|
+
# - companyid
|
35
|
+
# - firstname
|
36
|
+
# - lastname
|
37
|
+
# - emailaddress
|
22
38
|
def initialize(params)
|
39
|
+
raise 'No companyid given' unless (params[:companyid] or params[:company])
|
23
40
|
raise 'No firstname' unless params[:firstname]
|
24
41
|
raise 'No lastname' unless params[:lastname]
|
42
|
+
raise 'No emailaddress' unless params[:emailaddress]
|
25
43
|
# Do not create Contact before creating self!
|
26
44
|
firstname = params.delete(:firstname)
|
27
45
|
lastname = params.delete(:lastname)
|
@@ -31,6 +49,9 @@ class User < ActiveRecord::Base
|
|
31
49
|
|
32
50
|
super(params)
|
33
51
|
|
52
|
+
# COPY user_ (uuid_, userid, companyid, createdate, modifieddate, defaultuser, contactid, password_, passwordencrypted, passwordreset, passwordmodifieddate, gracelogincount, screenname, emailaddress, openid, portraitid, languageid, timezoneid, greeting, comments, logindate, loginip, lastlogindate, lastloginip, lastfailedlogindate, failedloginattempts, lockout, lockoutdate, agreedtotermsofuse, active_) FROM stdin;
|
53
|
+
# +c130e60d-d85a-40b8-b778-e0c0c868e508 10164 10109 2009-01-15 00:51:58.558 2009-01-15 00:51:58.558 f 10165 jGrep/LZ9ghV6N1IJ5iWcH3d4ps= t f \N 0 teppo teppo@localhost.localdomain 0 en_US GMT Welcome Teppo Testaaja! \N \N \N 0 f \N f t
|
54
|
+
|
34
55
|
# insert data into user_
|
35
56
|
unless self.uuid_
|
36
57
|
require 'rubygems'
|
@@ -65,6 +86,10 @@ class User < ActiveRecord::Base
|
|
65
86
|
self.reload
|
66
87
|
|
67
88
|
# create new contact
|
89
|
+
|
90
|
+
# COPY contact_ (contactid, companyid, userid, username, createdate, modifieddate, accountid, parentcontactid, firstname, middlename, lastname, prefixid, suffixid, male, birthday, smssn, aimsn, facebooksn, icqsn, jabbersn, msnsn, myspacesn, skypesn, twittersn, ymsn, employeestatusid, employeenumber, jobtitle, jobclass, hoursofoperation) FROM stdin;
|
91
|
+
# +10165 10109 10129 Test Test 2009-01-15 00:51:58.558 2009-01-15 00:51:58.558 10110 0 Teppo Testaaja 0 0 t 1970-01-01 00:00:00
|
92
|
+
|
68
93
|
if male.is_a?(String)
|
69
94
|
male = (male=='true')
|
70
95
|
end
|
@@ -76,20 +101,20 @@ class User < ActiveRecord::Base
|
|
76
101
|
:male => male
|
77
102
|
})
|
78
103
|
|
79
|
-
#
|
80
|
-
org = self.company.organizations.select{|o| o.parent==nil}.first
|
81
|
-
self.organizations << org
|
82
|
-
|
83
|
-
org_role = Role.find(:first, :conditions => "companyid=#{self.companyid} AND name='Organization Member'")
|
84
|
-
group = org.group
|
104
|
+
# assign "User" and "Power User" roles
|
85
105
|
|
86
|
-
#
|
87
|
-
|
88
|
-
|
89
|
-
self.id, org.group.id, org_role.id])
|
106
|
+
# COPY users_roles (userid, roleid) FROM stdin;
|
107
|
+
# +10164 10116
|
108
|
+
# +10164 10117
|
90
109
|
|
110
|
+
self.roles << Role.find(:first, :conditions => "companyid=#{self.companyid} AND name='User'")
|
111
|
+
self.roles << Role.find(:first, :conditions => "companyid=#{self.companyid} AND name='Power User'")
|
91
112
|
|
92
113
|
# Personal group
|
114
|
+
|
115
|
+
# COPY group_ (groupid, companyid, creatoruserid, classnameid, classpk, parentgroupid, livegroupid, name, description, type_, typesettings, friendlyurl, active_) FROM stdin;
|
116
|
+
# +10166 10109 10164 10034 10164 0 0 0 /teppo t
|
117
|
+
|
93
118
|
g = Group.create(
|
94
119
|
:companyid => self.companyid,
|
95
120
|
:creatoruserid => self.id,
|
@@ -98,26 +123,24 @@ class User < ActiveRecord::Base
|
|
98
123
|
:friendlyurl => '/'+self.screenname
|
99
124
|
)
|
100
125
|
|
101
|
-
#
|
102
|
-
|
103
|
-
self.roles << Role.find(:first, :conditions => "companyid=#{self.companyid} AND name='Power User'")
|
126
|
+
# Group's public + private layoutsets (should be created only for Power Users?)
|
127
|
+
# are created in the Group model.
|
104
128
|
|
105
|
-
#
|
106
|
-
#
|
107
|
-
|
108
|
-
Web::LayoutSet.create(
|
109
|
-
:groupid => g.id,
|
110
|
-
:companyid => self.companyid,
|
111
|
-
:privatelayout => privacy
|
112
|
-
)
|
113
|
-
end
|
129
|
+
# COPY layoutset (layoutsetid, groupid, companyid, privatelayout, logo, logoid, themeid, colorschemeid, wapthemeid, wapcolorschemeid, css, pagecount, virtualhost) FROM stdin;
|
130
|
+
# +10167 10166 10109 t f 0 01 mobile 01 0
|
131
|
+
# +10168 10166 10109 f f 0 01 mobile 01 0
|
114
132
|
|
115
|
-
|
133
|
+
|
134
|
+
# scope=4 means that the resource is "owned" by User
|
116
135
|
rc = self.resource_code(4)
|
117
136
|
raise 'Required ResourceCode not found' unless rc
|
118
137
|
|
119
138
|
# insert data into counter_ so that Hibernate won't die
|
120
139
|
Counter.increment(:resource, 100)
|
140
|
+
|
141
|
+
# COPY resource_ (resourceid, codeid, primkey) FROM stdin;
|
142
|
+
# +44 5 10164
|
143
|
+
|
121
144
|
resource = Resource.create(
|
122
145
|
:codeid => rc.id,
|
123
146
|
:primkey => self.id
|
@@ -125,8 +148,23 @@ class User < ActiveRecord::Base
|
|
125
148
|
|
126
149
|
permissions = []
|
127
150
|
# insert data into counter_ so that Hibernate won't die
|
151
|
+
|
152
|
+
# COPY permission_ (permissionid, companyid, actionid, resourceid) FROM stdin;
|
153
|
+
# +114 10109 DELETE 44
|
154
|
+
# +115 10109 IMPERSONATE 44
|
155
|
+
# +116 10109 PERMISSIONS 44
|
156
|
+
# +117 10109 UPDATE 44
|
157
|
+
# +118 10109 VIEW 44
|
158
|
+
|
159
|
+
# COPY users_permissions (userid, permissionid) FROM stdin;
|
160
|
+
# +10129 114
|
161
|
+
# +10129 115
|
162
|
+
# +10129 116
|
163
|
+
# +10129 117
|
164
|
+
# +10129 118
|
165
|
+
|
128
166
|
Counter.increment(:permission, 100)
|
129
|
-
|
167
|
+
self.class.actions.each do |action|
|
130
168
|
self.user_permissions << Permission.create(
|
131
169
|
:companyid => self.companyid,
|
132
170
|
:actionid => action,
|
@@ -135,6 +173,12 @@ class User < ActiveRecord::Base
|
|
135
173
|
end
|
136
174
|
|
137
175
|
# announcementsdelivery
|
176
|
+
|
177
|
+
# COPY announcementsdelivery (deliveryid, companyid, userid, type_, email, sms, website) FROM stdin;
|
178
|
+
# +10169 10109 10164 general f f t
|
179
|
+
# +10170 10109 10164 news f f t
|
180
|
+
# +10171 10109 10164 test f f t
|
181
|
+
|
138
182
|
%w{ general news test }.each do |type|
|
139
183
|
Announcement::Delivery.create(
|
140
184
|
:userid => self.id,
|
@@ -150,6 +194,7 @@ class User < ActiveRecord::Base
|
|
150
194
|
|
151
195
|
# insert data into phone
|
152
196
|
self.gsm=gsm if gsm
|
197
|
+
return self
|
153
198
|
end
|
154
199
|
|
155
200
|
def save
|
@@ -248,6 +293,29 @@ class User < ActiveRecord::Base
|
|
248
293
|
user_permissions + group_permissions + role_permissions
|
249
294
|
end
|
250
295
|
|
296
|
+
|
297
|
+
# Adds User to Organization members.
|
298
|
+
# TODO: move to Organization
|
299
|
+
#
|
300
|
+
# Updates users_organizations, adds the 'Organization Member' Role,
|
301
|
+
# and updates 3-way associations to usergrouprole.
|
302
|
+
def assign_organization_membership(org)
|
303
|
+
# organization membership
|
304
|
+
org = self.company.organizations.select{|o| o.parent==nil}.first
|
305
|
+
self.organizations << org
|
306
|
+
|
307
|
+
org_role = Role.find(:first, :conditions => "companyid=#{self.companyid} AND name='Organization Member'")
|
308
|
+
group = org.group
|
309
|
+
|
310
|
+
# can ActiveRecord handle 3-way associations?
|
311
|
+
ActiveRecord::Base.connection.execute(
|
312
|
+
"INSERT INTO usergrouprole (userid, groupid, roleid) VALUES (%i, %i, %i);" % [
|
313
|
+
self.id, org.group.id, org_role.id])
|
314
|
+
|
315
|
+
true
|
316
|
+
end
|
317
|
+
|
318
|
+
|
251
319
|
# Fullname is fetched from Contact
|
252
320
|
def name
|
253
321
|
self.contact ?
|
@@ -344,19 +412,23 @@ class User < ActiveRecord::Base
|
|
344
412
|
true
|
345
413
|
end
|
346
414
|
|
415
|
+
# Perhaps it would make more sense to select phones with classnameid of "mobile"
|
347
416
|
def gsm
|
348
417
|
self.phones.any? ? self.phones.first.number : nil
|
349
418
|
end
|
350
419
|
# Creates a new Phone unless it exists
|
351
420
|
def gsm=(number)
|
421
|
+
_number = self.class.cleanup_mobile_number(number)
|
422
|
+
return false if _number.empty? # no not save empty numbers
|
423
|
+
|
352
424
|
if self.phones.any?
|
353
425
|
phone = self.phones.first
|
354
|
-
phone.number=
|
426
|
+
phone.number=_number
|
355
427
|
phone.save
|
356
428
|
else
|
357
429
|
Phone.create(
|
358
430
|
:userid => self.id,
|
359
|
-
:number_ =>
|
431
|
+
:number_ => _number,
|
360
432
|
:primary_ => true
|
361
433
|
)
|
362
434
|
self.phones.reload
|
@@ -364,6 +436,11 @@ class User < ActiveRecord::Base
|
|
364
436
|
true
|
365
437
|
end
|
366
438
|
|
439
|
+
# This method is meant to be overridden in custom configurations.
|
440
|
+
def self.cleanup_mobile_number(number)
|
441
|
+
return number
|
442
|
+
end
|
443
|
+
|
367
444
|
def birthday
|
368
445
|
self.contact.birthday
|
369
446
|
end
|
@@ -420,5 +497,33 @@ class User < ActiveRecord::Base
|
|
420
497
|
end
|
421
498
|
alias :is_guest? :is_default?
|
422
499
|
|
500
|
+
# Activates inactive users. Makes it easy to extend functionality with mixins (to send email, for example).
|
501
|
+
def activate
|
502
|
+
self.active_ = true
|
503
|
+
self.save
|
504
|
+
self.class.instance_method_already_implemented?(:activate) ?
|
505
|
+
super : true
|
506
|
+
end
|
507
|
+
|
508
|
+
# Deactivates active users
|
509
|
+
def deactivate
|
510
|
+
self.active_ = false
|
511
|
+
self.save
|
512
|
+
self.class.instance_method_already_implemented?(:deactivate) ?
|
513
|
+
super : true
|
514
|
+
end
|
515
|
+
|
516
|
+
# URL path to this User's public or private page
|
517
|
+
def path(pl=:public)
|
518
|
+
self.hive.nil? ? nil : self.hive.path(pl)
|
519
|
+
end
|
520
|
+
|
521
|
+
# URL to user's portrait (needs to be prefixed with Liferay server URL).
|
522
|
+
# Unless the user has a portrait, a default image should be displayed.
|
523
|
+
def portrait_path
|
524
|
+
path = '/image/user_%s_portrait' % (self.contact.male ? 'male' : 'female')
|
525
|
+
path << "?img_id=#{self.portraitid}" if self.portraitid != 0
|
526
|
+
return path
|
527
|
+
end
|
423
528
|
|
424
529
|
end
|
data/lib/web/layout.rb
CHANGED
@@ -5,11 +5,149 @@ module Web
|
|
5
5
|
set_table_name :layout
|
6
6
|
set_primary_key :plid
|
7
7
|
|
8
|
+
validates_uniqueness_of :layoutid, :scope => [:groupid, :privatelayout]
|
9
|
+
|
10
|
+
|
8
11
|
# com.liferay.portal.model.Layout
|
9
12
|
def liferay_class
|
10
13
|
'com.liferay.portal.model.Layout'
|
11
14
|
end
|
12
15
|
|
16
|
+
# Actions for Permissions.
|
17
|
+
def self.actions
|
18
|
+
%w{
|
19
|
+
ADD_DISCUSSION
|
20
|
+
UPDATE
|
21
|
+
VIEW
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Creates a new Layout.
|
26
|
+
#
|
27
|
+
# This process is engineered by creating a new layout with Liferay's (v. 5.1.1) tools and
|
28
|
+
# inspecting the database dump diffs.
|
29
|
+
#
|
30
|
+
# Mandatory parameters:
|
31
|
+
# - groupid
|
32
|
+
# - privatelayout (true or false)
|
33
|
+
#
|
34
|
+
# Optional extra parameters:
|
35
|
+
# - locale
|
36
|
+
def initialize(params)
|
37
|
+
raise 'No groupid given' unless (params[:groupid] or params[:group])
|
38
|
+
raise 'No privatelayout given' if params[:privatelayout].nil?
|
39
|
+
_name = params.delete(:name) || 'New layout'
|
40
|
+
_locale = params[:locale] || 'en_US'
|
41
|
+
|
42
|
+
super(params)
|
43
|
+
|
44
|
+
# COPY layout (plid, groupid, companyid, privatelayout, layoutid, parentlayoutid, name, title, description, type_, typesettings, hidden_, friendlyurl, iconimage, iconimageid, themeid, colorschemeid, wapthemeid, wapcolorschemeid, css, priority, dlfolderid) FROM stdin;
|
45
|
+
# +10301 10166 10109 f 1 0 <?xml version='1.0' encoding='UTF-8'?><root available-locales="en_US" default-locale="en_US"><name language-id="en_US">frontpage</name></root> <root /> portlet layout-template-id=2_columns_ii\n f /1 f 0 0 0
|
46
|
+
|
47
|
+
self.companyid = self.group.companyid
|
48
|
+
|
49
|
+
name = "<?xml version='1.0' encoding='UTF-8'?>"
|
50
|
+
name += '<root available-locales="%s" default-locale="%s">' % [_locale, _locale]
|
51
|
+
name += '<name language-id="%s">' % _locale
|
52
|
+
name += _name
|
53
|
+
name += '</name></root>'
|
54
|
+
self.name = name
|
55
|
+
|
56
|
+
# perhaps layoutid could be sequenced.
|
57
|
+
layouts = (self.is_public? ? self.group.public_layouts : self.group.private_layouts)
|
58
|
+
_ids = (layouts.any? ? layouts.collect(&:layoutid) : nil)
|
59
|
+
self.layoutid = (_ids.nil? ? 1 : _ids.sort.max+1)
|
60
|
+
|
61
|
+
# increment pagecount
|
62
|
+
_set = self.layoutset
|
63
|
+
_set.pagecount += 1
|
64
|
+
_set.save
|
65
|
+
|
66
|
+
self.friendlyurl ||= '/'+self.layoutid.to_s
|
67
|
+
self.type_ ||= 'portlet'
|
68
|
+
self.typesettings ||= Web::Typesettings.new.to_s # 'bout to change
|
69
|
+
self.title ||= '<root />'
|
70
|
+
self.description ||= ''
|
71
|
+
self.parentlayoutid ||= 0
|
72
|
+
self.priority ||= 0
|
73
|
+
self.dlfolderid ||= 0
|
74
|
+
self.iconimageid ||= 0
|
75
|
+
self.iconimage = false if self.iconimage.nil?
|
76
|
+
self.hidden_ = false if self.hidden_.nil?
|
77
|
+
|
78
|
+
self.save
|
79
|
+
|
80
|
+
#####
|
81
|
+
# Group 10166 is a private group of User 10164.
|
82
|
+
# 10129 is the Company's admin. 10111 is Guest.
|
83
|
+
#####
|
84
|
+
|
85
|
+
# Create a resource with scope=2 for the Group.
|
86
|
+
|
87
|
+
# COPY resource_ (resourceid, codeid, primkey) FROM stdin;
|
88
|
+
# +201 2 10166
|
89
|
+
# +202 3 10301
|
90
|
+
|
91
|
+
rc = self.resource_code(2)
|
92
|
+
unless rc
|
93
|
+
rc = ResourceCode.create(
|
94
|
+
:companyid => self.companyid,
|
95
|
+
:name => self.liferay_class,
|
96
|
+
:scope => 2
|
97
|
+
)
|
98
|
+
end
|
99
|
+
unless Resource.find(:first, :conditions => "codeid=#{rc.id} AND primkey='#{self.group.id}'")
|
100
|
+
Resource.create(
|
101
|
+
:codeid => rc.id,
|
102
|
+
:primkey => self.group.id
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Create a resource with scope=4 for this Layout.
|
107
|
+
rc = self.resource_code(4)
|
108
|
+
unless rc
|
109
|
+
rc = ResourceCode.create(
|
110
|
+
:companyid => self.companyid,
|
111
|
+
:name => self.liferay_class,
|
112
|
+
:scope => 4
|
113
|
+
)
|
114
|
+
end
|
115
|
+
resource = Resource.create(
|
116
|
+
:codeid => rc.id,
|
117
|
+
:primkey => self.id
|
118
|
+
)
|
119
|
+
|
120
|
+
# COPY permission_ (permissionid, companyid, actionid, resourceid) FROM stdin;
|
121
|
+
# +301 10109 ADD_DISCUSSION 202
|
122
|
+
# +302 10109 UPDATE 202
|
123
|
+
# +303 10109 VIEW 202
|
124
|
+
|
125
|
+
self.class.actions.each do |actionid|
|
126
|
+
p = Permission.create(
|
127
|
+
:companyid => self.companyid,
|
128
|
+
:actionid => actionid,
|
129
|
+
:resourceid => resource.id
|
130
|
+
)
|
131
|
+
|
132
|
+
# COPY users_permissions (userid, permissionid) FROM stdin;
|
133
|
+
# +10129 301
|
134
|
+
# +10129 302
|
135
|
+
# +10129 303
|
136
|
+
# +10111 303
|
137
|
+
|
138
|
+
self.company.administrators.each do |user|
|
139
|
+
user.user_permissions << p
|
140
|
+
end
|
141
|
+
|
142
|
+
# COPY groups_permissions (groupid, permissionid) FROM stdin;
|
143
|
+
# +10166 301
|
144
|
+
# +10166 303
|
145
|
+
group = self.group
|
146
|
+
self.group.permissions << p
|
147
|
+
end
|
148
|
+
return self
|
149
|
+
end
|
150
|
+
|
13
151
|
public
|
14
152
|
|
15
153
|
belongs_to :group,
|
@@ -72,5 +210,15 @@ module Web
|
|
72
210
|
self.layoutset.url_prefix + self.group.friendlyurl + self.friendlyurl
|
73
211
|
end
|
74
212
|
|
213
|
+
# ResourceCode associated to this instance (and scope)
|
214
|
+
def resource_code(scope=4)
|
215
|
+
ResourceCode.find(:first,
|
216
|
+
:conditions => "companyid=#{self.companyid} AND name='#{self.liferay_class}' AND scope=#{scope}")
|
217
|
+
end
|
218
|
+
|
219
|
+
def contents
|
220
|
+
Typesettings.new(self.typesettings)
|
221
|
+
end
|
222
|
+
|
75
223
|
end
|
76
224
|
end
|