lportal 1.0.4 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README +15 -2
- data/init.rb +1 -1
- data/lib/announcement/delivery.rb +13 -0
- data/lib/classname.rb +23 -11
- data/lib/company.rb +5 -1
- data/lib/contact.rb +40 -17
- data/lib/counter.rb +20 -2
- data/lib/group.rb +54 -3
- data/lib/journal/feed.rb +21 -0
- data/lib/journal/structure.rb +21 -0
- data/lib/journal/template.rb +21 -0
- data/lib/list_type.rb +4 -0
- data/lib/organization.rb +4 -0
- data/lib/phone.rb +15 -10
- data/lib/poll/question.rb +21 -0
- data/lib/user.rb +209 -40
- data/lib/web/layout.rb +5 -0
- data/lib/web/layout_set.rb +34 -0
- data/lib/web/portlet.rb +5 -1
- data/lib/web/portlet_preferences.rb +5 -1
- data/test/unit/journal/feed_test.rb +8 -0
- data/test/unit/journal/structure_test.rb +8 -0
- data/test/unit/journal/template_test.rb +8 -0
- data/test/unit/poll/question_test.rb +8 -0
- data/test/unit/tag/asset_test.rb +3 -2
- data/test/unit/tag/entry_test.rb +1 -1
- data/test/unit/user_test.rb +18 -1
- data/version.rb +1 -1
- metadata +13 -2
data/README
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
== Liferay
|
1
|
+
== Liferay & ActiveRecord
|
2
2
|
|
3
|
-
This is a collection of (some) Liferay models for developers that use the database with ActiveRecord. You may want to check out the Rails-portlet package if you're going to deploy Rails applications
|
3
|
+
This is a collection of (some) Liferay models for developers that use the database with ActiveRecord. You may want to check out the Rails-portlet package if you're going to deploy Rails applications on Liferay.
|
4
4
|
|
5
5
|
|
6
6
|
== Follow these steps
|
@@ -12,4 +12,17 @@ This is a collection of (some) Liferay models for developers that use the databa
|
|
12
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
|
+
== Tips & Tricks
|
16
|
+
Find the public layouts of a Group "g" that have the Message Board portlet:
|
17
|
+
(only possible with Caterpillar)
|
18
|
+
|
19
|
+
title = 'Message Boards'
|
20
|
+
g = Group.find 15833
|
21
|
+
|
22
|
+
layout = g.public_layouts.select{
|
23
|
+
|l| l.portlets.find{|p| p.title=="#{title}"}}.first
|
24
|
+
|
25
|
+
puts layout.inspect
|
26
|
+
|
27
|
+
|
15
28
|
Copyright (c) 2008 Mikael Lammentausta, released under the MIT license
|
data/init.rb
CHANGED
data/lib/classname.rb
CHANGED
@@ -27,26 +27,26 @@ class Classname < ActiveRecord::Base
|
|
27
27
|
when 'com.liferay.portal.model.UserGroup'
|
28
28
|
Usergroup
|
29
29
|
|
30
|
+
when 'com.liferay.portlet.announcements.model.AnnouncementsEntry'
|
31
|
+
Announcement::Entry
|
32
|
+
|
30
33
|
when 'com.liferay.portlet.blogs.model.BlogsEntry'
|
31
34
|
BlogPost
|
32
35
|
|
33
|
-
when 'com.liferay.portlet.
|
34
|
-
|
36
|
+
when 'com.liferay.portlet.bookmarks.model.BookmarksEntry'
|
37
|
+
Bookmark::Entry
|
35
38
|
|
36
|
-
when 'com.liferay.portlet.
|
37
|
-
|
39
|
+
when 'com.liferay.portlet.bookmarks.model.BookmarksFolder'
|
40
|
+
Bookmark::Folder
|
38
41
|
|
39
42
|
when 'com.liferay.portlet.calendar.model.CalEvent'
|
40
43
|
Calevent
|
41
44
|
|
42
|
-
when 'com.liferay.portlet.
|
43
|
-
|
44
|
-
|
45
|
-
when 'com.liferay.portlet.bookmarks.model.BookmarksEntry'
|
46
|
-
Bookmark::Entry
|
45
|
+
when 'com.liferay.portlet.documentlibrary.model.DLFileEntry'
|
46
|
+
DlFile
|
47
47
|
|
48
|
-
when 'com.liferay.portlet.
|
49
|
-
|
48
|
+
when 'com.liferay.portlet.documentlibrary.model.DLFolder'
|
49
|
+
DlFolder
|
50
50
|
|
51
51
|
when 'com.liferay.portlet.imagegallery.model.IGFolder'
|
52
52
|
IG::Folder
|
@@ -60,12 +60,24 @@ class Classname < ActiveRecord::Base
|
|
60
60
|
when 'com.liferay.portlet.journal.model.JournalArticleResource'
|
61
61
|
Journal::ArticleResource
|
62
62
|
|
63
|
+
when 'com.liferay.portlet.journal.model.JournalFeed'
|
64
|
+
Journal::Feed
|
65
|
+
|
66
|
+
when 'com.liferay.portlet.journal.model.JournalStructure'
|
67
|
+
Journal::Structure
|
68
|
+
|
69
|
+
when 'com.liferay.portlet.journal.model.JournalTemplate'
|
70
|
+
Journal::Template
|
71
|
+
|
63
72
|
when 'com.liferay.portlet.messageboards.model.MBCategory'
|
64
73
|
MB::Category
|
65
74
|
|
66
75
|
when 'com.liferay.portlet.messageboards.model.MBMessage'
|
67
76
|
MB::Message
|
68
77
|
|
78
|
+
when 'com.liferay.portlet.polls.model.PollsQuestion'
|
79
|
+
Poll::Question
|
80
|
+
|
69
81
|
when 'com.liferay.portlet.wiki.model.WikiNode'
|
70
82
|
Wiki::Node
|
71
83
|
|
data/lib/company.rb
CHANGED
@@ -33,10 +33,14 @@ class Company < ActiveRecord::Base
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def administrators
|
36
|
-
adminrole = Role.
|
36
|
+
adminrole = Role.find(:first, :conditions => "companyid=#{self.id} AND name='Administrator'")
|
37
37
|
return self.users.select{|u| u.roles.include?(adminrole) }
|
38
38
|
end
|
39
|
+
alias :admins :administrators
|
39
40
|
|
41
|
+
def guest
|
42
|
+
User.find(:first, :conditions => "companyid=#{self.id} AND defaultuser = true" )
|
43
|
+
end
|
40
44
|
|
41
45
|
# has_one :frontpage,
|
42
46
|
# :class_name => "Web::LayoutSet",
|
data/lib/contact.rb
CHANGED
@@ -18,32 +18,55 @@ class Contact < ActiveRecord::Base
|
|
18
18
|
belongs_to :account,
|
19
19
|
:foreign_key => 'accountid'
|
20
20
|
|
21
|
+
# Creates new contact_
|
21
22
|
def initialize(params)
|
22
23
|
super(params)
|
24
|
+
|
25
|
+
if !self.companyid and self.user
|
26
|
+
self.companyid = self.user.companyid
|
27
|
+
end
|
28
|
+
self.username ||= ''
|
23
29
|
self.createdate = Time.now
|
24
30
|
self.modifieddate = Time.now
|
25
|
-
self.
|
26
|
-
|
31
|
+
if !self.accountid and self.company
|
32
|
+
self.accountid = self.company.accountid
|
33
|
+
end
|
27
34
|
self.parentcontactid ||= 0
|
28
|
-
self.
|
35
|
+
self.firstname ||= ''
|
36
|
+
self.middlename ||= ''
|
37
|
+
self.lastname ||= ''
|
29
38
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
# values for prefixid and suffixid are defined in table listtype
|
40
|
+
self.prefixid ||= 0
|
41
|
+
self.suffixid ||= 0
|
42
|
+
self.male=true if self.male.nil?
|
43
|
+
self.birthday ||= Time.mktime(1970,1,1)
|
44
|
+
self.smssn ||= ''
|
45
|
+
self.aimsn ||= ''
|
46
|
+
self.icqsn ||= ''
|
47
|
+
self.jabbersn ||= ''
|
48
|
+
self.msnsn ||= ''
|
49
|
+
self.skypesn ||= ''
|
50
|
+
self.ymsn ||= ''
|
51
|
+
self.employeestatusid ||= ''
|
52
|
+
self.employeenumber ||= ''
|
53
|
+
self.jobtitle ||= ''
|
54
|
+
self.jobclass ||= ''
|
55
|
+
self.hoursofoperation ||= ''
|
56
|
+
self.facebooksn ||= ''
|
57
|
+
self.myspacesn ||= ''
|
58
|
+
self.twittersn ||= ''
|
39
59
|
|
40
|
-
|
41
|
-
if !self.username and self.firstname and self.lastname
|
42
|
-
self.username = fullname
|
43
|
-
end
|
44
|
-
super
|
60
|
+
self.save
|
45
61
|
end
|
46
62
|
|
63
|
+
# def save
|
64
|
+
# if !self.username and self.firstname and self.lastname
|
65
|
+
# self.username = fullname
|
66
|
+
# end
|
67
|
+
# super
|
68
|
+
# end
|
69
|
+
|
47
70
|
def fullname
|
48
71
|
(self.firstname.empty? and self.lastname.empty?) ?
|
49
72
|
false : self.firstname+' '+self.lastname
|
data/lib/counter.rb
CHANGED
@@ -1,4 +1,22 @@
|
|
1
1
|
class Counter < ActiveRecord::Base
|
2
|
-
|
3
|
-
|
2
|
+
set_table_name :counter
|
3
|
+
set_primary_key :name
|
4
|
+
|
5
|
+
# Increments the counter
|
6
|
+
def self.increment(name, value)
|
7
|
+
if name.is_a?(Symbol)
|
8
|
+
name = (
|
9
|
+
case name
|
10
|
+
when :permission
|
11
|
+
'com.liferay.portal.model.Permission'
|
12
|
+
when :resource
|
13
|
+
'com.liferay.portal.model.Resource'
|
14
|
+
end
|
15
|
+
)
|
16
|
+
end
|
17
|
+
c = self.find(name)
|
18
|
+
c.currentid += value
|
19
|
+
c.save
|
20
|
+
end
|
21
|
+
|
4
22
|
end
|
data/lib/group.rb
CHANGED
@@ -10,13 +10,29 @@ class Group < ActiveRecord::Base
|
|
10
10
|
'com.liferay.portal.model.Group'
|
11
11
|
end
|
12
12
|
|
13
|
+
def initialize(params)
|
14
|
+
super(params)
|
15
|
+
self.parentgroupid ||= 0
|
16
|
+
self.livegroupid ||= 0
|
17
|
+
self.type_ ||= 0
|
18
|
+
self.active_ ||= true
|
19
|
+
self.name ||= ''
|
20
|
+
self.description ||= ''
|
21
|
+
self.typesettings ||= ''
|
22
|
+
|
23
|
+
self.save
|
24
|
+
end
|
25
|
+
|
13
26
|
belongs_to :company,
|
14
27
|
:foreign_key => 'companyid'
|
15
28
|
|
16
29
|
belongs_to :creator,
|
17
30
|
:class_name => 'User',
|
18
31
|
:foreign_key => 'creatoruserid'
|
19
|
-
|
32
|
+
|
33
|
+
belongs_to :parent,
|
34
|
+
:class_name => 'Group',
|
35
|
+
:foreign_key => 'parentgroupid'
|
20
36
|
|
21
37
|
# association to organizations
|
22
38
|
has_and_belongs_to_many :organizations,
|
@@ -85,16 +101,51 @@ class Group < ActiveRecord::Base
|
|
85
101
|
:foreign_key => 'groupid',
|
86
102
|
:conditions => 'privatelayout = true'
|
87
103
|
|
88
|
-
#
|
104
|
+
# find owner by classnameid + classpk
|
105
|
+
def owner
|
106
|
+
return nil if self.classnameid==0
|
107
|
+
_class = Classname.model(Classname.find(self.classnameid).value)
|
108
|
+
_class.find self.classpk
|
109
|
+
end
|
110
|
+
|
89
111
|
has_one :resource,
|
90
112
|
:foreign_key => 'primkey'
|
91
113
|
|
92
114
|
has_many :mbcategories,
|
93
|
-
:class_name
|
115
|
+
:class_name => 'MB::Category',
|
94
116
|
:foreign_key => 'groupid'
|
95
117
|
|
96
118
|
def is_active?
|
97
119
|
self.active_
|
98
120
|
end
|
99
121
|
|
122
|
+
def is_public?
|
123
|
+
self.type_ == 1
|
124
|
+
end
|
125
|
+
|
126
|
+
def is_protected?
|
127
|
+
self.type_ == 2
|
128
|
+
end
|
129
|
+
|
130
|
+
def is_private?
|
131
|
+
self.type_ == 3
|
132
|
+
end
|
133
|
+
|
134
|
+
# the URL to this Group's public or private page
|
135
|
+
def path(pl=:public)
|
136
|
+
case pl
|
137
|
+
when :public
|
138
|
+
self.public_layouts.any? ?
|
139
|
+
self.public_layoutset.url_prefix + self.friendlyurl : nil
|
140
|
+
|
141
|
+
when :private
|
142
|
+
self.private_layouts.any? ?
|
143
|
+
self.private_layoutset.url_prefix + self.friendlyurl : nil
|
144
|
+
|
145
|
+
else
|
146
|
+
nil
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
100
151
|
end
|
data/lib/journal/feed.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Journal
|
2
|
+
class Feed < ActiveRecord::Base
|
3
|
+
set_table_name :journalfeed
|
4
|
+
set_primary_key :id_
|
5
|
+
|
6
|
+
# com.liferay.portlet.journal.model.JournalFeed
|
7
|
+
def liferay_class
|
8
|
+
'com.liferay.portlet.journal.model.JournalFeed'
|
9
|
+
end
|
10
|
+
|
11
|
+
belongs_to :company,
|
12
|
+
:foreign_key => 'companyid'
|
13
|
+
|
14
|
+
belongs_to :user,
|
15
|
+
:foreign_key => 'userid'
|
16
|
+
|
17
|
+
belongs_to :group,
|
18
|
+
:foreign_key => 'groupid'
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Journal
|
2
|
+
class Structure < ActiveRecord::Base
|
3
|
+
set_table_name :journalstructure
|
4
|
+
set_primary_key :id_
|
5
|
+
|
6
|
+
# com.liferay.portlet.journal.model.JournalStructure
|
7
|
+
def liferay_class
|
8
|
+
'com.liferay.portlet.journal.model.JournalStructure'
|
9
|
+
end
|
10
|
+
|
11
|
+
belongs_to :company,
|
12
|
+
:foreign_key => 'companyid'
|
13
|
+
|
14
|
+
belongs_to :user,
|
15
|
+
:foreign_key => 'userid'
|
16
|
+
|
17
|
+
belongs_to :group,
|
18
|
+
:foreign_key => 'groupid'
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Journal
|
2
|
+
class Template < ActiveRecord::Base
|
3
|
+
set_table_name :journaltemplate
|
4
|
+
set_primary_key :id_
|
5
|
+
|
6
|
+
# com.liferay.portlet.journal.model.JournalTemplate
|
7
|
+
def liferay_class
|
8
|
+
'com.liferay.portlet.journal.model.JournalTemplate'
|
9
|
+
end
|
10
|
+
|
11
|
+
belongs_to :company,
|
12
|
+
:foreign_key => 'companyid'
|
13
|
+
|
14
|
+
belongs_to :user,
|
15
|
+
:foreign_key => 'userid'
|
16
|
+
|
17
|
+
belongs_to :group,
|
18
|
+
:foreign_key => 'groupid'
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/list_type.rb
ADDED
data/lib/organization.rb
CHANGED
data/lib/phone.rb
CHANGED
@@ -10,16 +10,17 @@ class Phone < ActiveRecord::Base
|
|
10
10
|
|
11
11
|
def initialize(params)
|
12
12
|
super(params)
|
13
|
-
|
14
|
-
self.createdate
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
|
14
|
+
self.createdate ||= Time.now
|
15
|
+
self.modifieddate = Time.now
|
16
|
+
self.companyid = self.user.companyid
|
17
|
+
self.username ||= self.user.fullname
|
18
|
+
self.classnameid = Classname.find_by_value('com.liferay.portal.model.Contact').id
|
19
|
+
self.classpk = self.user.contact.id
|
20
|
+
self.typeid ||= ListType.find_by_name('Mobile').id
|
21
|
+
self.primary_=true if self.primary_.nil?
|
22
|
+
|
23
|
+
self.save
|
23
24
|
end
|
24
25
|
|
25
26
|
def number
|
@@ -30,4 +31,8 @@ class Phone < ActiveRecord::Base
|
|
30
31
|
self.number_ = val
|
31
32
|
end
|
32
33
|
|
34
|
+
def is_primary?
|
35
|
+
self.primary_
|
36
|
+
end
|
37
|
+
|
33
38
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Poll
|
2
|
+
class Question < ActiveRecord::Base
|
3
|
+
set_table_name :pollsquestion
|
4
|
+
set_primary_key :questionid
|
5
|
+
|
6
|
+
# com.liferay.portlet.polls.model.PollsQuestion
|
7
|
+
def liferay_class
|
8
|
+
'com.liferay.portlet.polls.model.PollsQuestion'
|
9
|
+
end
|
10
|
+
|
11
|
+
belongs_to :company,
|
12
|
+
:foreign_key => 'companyid'
|
13
|
+
|
14
|
+
belongs_to :user,
|
15
|
+
:foreign_key => 'userid'
|
16
|
+
|
17
|
+
belongs_to :group,
|
18
|
+
:foreign_key => 'groupid'
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/user.rb
CHANGED
@@ -3,16 +3,35 @@ class User < ActiveRecord::Base
|
|
3
3
|
set_table_name :user_
|
4
4
|
set_primary_key :userid
|
5
5
|
|
6
|
+
validates_uniqueness_of :uuid_
|
7
|
+
validates_uniqueness_of :emailaddress
|
6
8
|
validates_uniqueness_of :screenname
|
7
9
|
|
8
10
|
public
|
9
11
|
|
12
|
+
# com.liferay.portal.model.User
|
10
13
|
def liferay_class
|
11
14
|
'com.liferay.portal.model.User'
|
12
15
|
end
|
13
16
|
|
17
|
+
# Creates a new user.
|
18
|
+
#
|
19
|
+
# It is a complicated process, as Liferay inserts new data into many tables.
|
20
|
+
# This process is figured by creating a new user with Liferay's (v. 5.1.1) tools and
|
21
|
+
# inspected by diff'ing the database dump.
|
14
22
|
def initialize(params)
|
23
|
+
raise 'No firstname' unless params[:firstname]
|
24
|
+
raise 'No lastname' unless params[:lastname]
|
25
|
+
# Do not create Contact before creating self!
|
26
|
+
firstname = params.delete(:firstname)
|
27
|
+
lastname = params.delete(:lastname)
|
28
|
+
# Do not create contact before creating self!
|
29
|
+
gsm = params.delete(:gsm)
|
30
|
+
male = params.delete(:male)
|
31
|
+
|
15
32
|
super(params)
|
33
|
+
|
34
|
+
# insert data into user_
|
16
35
|
unless self.uuid_
|
17
36
|
require 'rubygems'
|
18
37
|
require 'uuidtools'
|
@@ -21,14 +40,124 @@ class User < ActiveRecord::Base
|
|
21
40
|
self.createdate = Time.now
|
22
41
|
self.modifieddate = Time.now
|
23
42
|
self.defaultuser = false
|
43
|
+
unless self.password_
|
44
|
+
self.password_ = firstname
|
45
|
+
self.passwordencrypted = false
|
46
|
+
end
|
47
|
+
self.passwordreset=false if self.passwordreset.nil?
|
24
48
|
self.gracelogincount = 0
|
49
|
+
self.screenname ||= [firstname, lastname].join('-').downcase
|
50
|
+
self.emailaddress ||= ''
|
25
51
|
self.portraitid ||= 0
|
52
|
+
self.languageid ||= ''
|
26
53
|
self.timezoneid ||= 'Europe/Istanbul'
|
54
|
+
self.greeting ||= 'Welcome'
|
55
|
+
self.comments ||= ''
|
56
|
+
self.loginip ||= ''
|
57
|
+
self.lastloginip ||= ''
|
27
58
|
self.failedloginattempts = 0
|
28
59
|
self.lockout = false
|
29
60
|
self.agreedtotermsofuse = true
|
30
|
-
self.active_
|
61
|
+
self.active_ = true if self.active_.nil?
|
62
|
+
self.openid ||= ''
|
63
|
+
|
64
|
+
self.save
|
65
|
+
self.reload
|
66
|
+
|
67
|
+
# create new contact
|
68
|
+
if male.is_a?(String)
|
69
|
+
male = (male=='true')
|
70
|
+
end
|
71
|
+
self.contact = Contact.create({
|
72
|
+
:userid => self.id,
|
73
|
+
:username => '', # name of the user who created this user
|
74
|
+
:firstname => firstname,
|
75
|
+
:lastname => lastname,
|
76
|
+
:male => male
|
77
|
+
})
|
78
|
+
|
79
|
+
# organization membership
|
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
|
85
|
+
|
86
|
+
# can ActiveRecord handle 3-way associations?
|
87
|
+
ActiveRecord::Base.connection.execute(
|
88
|
+
"INSERT INTO usergrouprole (userid, groupid, roleid) VALUES (%i, %i, %i);" % [
|
89
|
+
self.id, org.group.id, org_role.id])
|
90
|
+
|
91
|
+
|
92
|
+
# Personal group
|
93
|
+
g = Group.create(
|
94
|
+
:companyid => self.companyid,
|
95
|
+
:creatoruserid => self.id,
|
96
|
+
:classnameid => Classname.find_by_value(self.liferay_class).id,
|
97
|
+
:classpk => self.id,
|
98
|
+
:friendlyurl => '/'+self.screenname
|
99
|
+
)
|
100
|
+
|
101
|
+
# assign "User" and "Power User" roles
|
102
|
+
self.roles << Role.find(:first, :conditions => "companyid=#{self.companyid} AND name='User'")
|
103
|
+
self.roles << Role.find(:first, :conditions => "companyid=#{self.companyid} AND name='Power User'")
|
104
|
+
|
105
|
+
# Group's layoutset (only for Power Users)
|
106
|
+
# public + private
|
107
|
+
[true, false].each do |privacy|
|
108
|
+
Web::LayoutSet.create(
|
109
|
+
:groupid => g.id,
|
110
|
+
:companyid => self.companyid,
|
111
|
+
:privatelayout => privacy
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
# scope=4 is a bit of a mystery..
|
116
|
+
rc = self.resource_code(4)
|
117
|
+
raise 'Required ResourceCode not found' unless rc
|
118
|
+
|
119
|
+
# insert data into counter_ so that Hibernate won't die
|
120
|
+
Counter.increment(:resource, 100)
|
121
|
+
resource = Resource.create(
|
122
|
+
:codeid => rc.id,
|
123
|
+
:primkey => self.id
|
124
|
+
)
|
125
|
+
|
126
|
+
permissions = []
|
127
|
+
# insert data into counter_ so that Hibernate won't die
|
128
|
+
Counter.increment(:permission, 100)
|
129
|
+
%w{ DELETE IMPERSONATE PERMISSIONS UPDATE VIEW }.each do |action|
|
130
|
+
self.user_permissions << Permission.create(
|
131
|
+
:companyid => self.companyid,
|
132
|
+
:actionid => action,
|
133
|
+
:resourceid => resource.id
|
134
|
+
)
|
135
|
+
end
|
31
136
|
|
137
|
+
# announcementsdelivery
|
138
|
+
%w{ general news test }.each do |type|
|
139
|
+
Announcement::Delivery.create(
|
140
|
+
:userid => self.id,
|
141
|
+
:companyid => self.companyid,
|
142
|
+
:type_ => type,
|
143
|
+
:email => false,
|
144
|
+
:sms => false,
|
145
|
+
:website => true
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
self.save
|
150
|
+
|
151
|
+
# insert data into phone
|
152
|
+
self.gsm=gsm if gsm
|
153
|
+
end
|
154
|
+
|
155
|
+
def save
|
156
|
+
super
|
157
|
+
|
158
|
+
raise self.errors[:uuid_] if self.errors[:uuid_]
|
159
|
+
raise self.errors[:emailaddress] if self.errors[:emailaddress]
|
160
|
+
raise self.errors[:screenname] if self.errors[:screenname]
|
32
161
|
end
|
33
162
|
|
34
163
|
has_one :account,
|
@@ -71,6 +200,40 @@ class User < ActiveRecord::Base
|
|
71
200
|
:foreign_key => 'userid',
|
72
201
|
:association_foreign_key => 'permissionid'
|
73
202
|
|
203
|
+
# association to usergroups
|
204
|
+
has_and_belongs_to_many :usergroups,
|
205
|
+
:class_name => 'Usergroup',
|
206
|
+
:join_table => 'users_usergroups',
|
207
|
+
:foreign_key => 'userid',
|
208
|
+
:association_foreign_key => 'usergroupid'
|
209
|
+
|
210
|
+
# User's own group
|
211
|
+
has_one :hive,
|
212
|
+
:class_name => 'Group',
|
213
|
+
:foreign_key => 'classpk'
|
214
|
+
|
215
|
+
# association to tags
|
216
|
+
has_many :tags,
|
217
|
+
:class_name => 'Tag::Entry',
|
218
|
+
:foreign_key => 'userid'
|
219
|
+
|
220
|
+
# association to assets
|
221
|
+
has_many :assets,
|
222
|
+
:order => 'publishdate',
|
223
|
+
:foreign_key => 'userid'
|
224
|
+
|
225
|
+
# association to wiki pages
|
226
|
+
has_many :wikipages,
|
227
|
+
:class_name => 'Wiki::Page',
|
228
|
+
:foreign_key => 'userid'
|
229
|
+
alias :articles :wikipages
|
230
|
+
|
231
|
+
# association to MessageBoardMessages
|
232
|
+
has_many :messages,
|
233
|
+
:class_name => 'MB::Message',
|
234
|
+
:foreign_key => 'userid'
|
235
|
+
|
236
|
+
|
74
237
|
def group_permissions
|
75
238
|
self.groups.map{|g| g.permissions }.flatten
|
76
239
|
end
|
@@ -79,18 +242,24 @@ class User < ActiveRecord::Base
|
|
79
242
|
self.roles.map{|g| g.permissions }.flatten
|
80
243
|
end
|
81
244
|
|
82
|
-
# permissions
|
245
|
+
# All permissions that the user has.
|
246
|
+
# Permissions are summed up from user, group and role permissions.
|
83
247
|
def permissions
|
84
248
|
user_permissions + group_permissions + role_permissions
|
85
249
|
end
|
86
250
|
|
87
|
-
|
88
|
-
|
251
|
+
# Fullname is fetched from Contact
|
252
|
+
def name
|
253
|
+
self.contact ?
|
89
254
|
self.contact.fullname : nil
|
90
255
|
end
|
256
|
+
alias :fullname :name
|
257
|
+
|
91
258
|
def firstname
|
92
|
-
self.contact
|
259
|
+
self.contact ?
|
260
|
+
self.contact.firstname : nil
|
93
261
|
end
|
262
|
+
# Creates a new Contact unless it exists
|
94
263
|
def firstname=(v)
|
95
264
|
if self.contact
|
96
265
|
c = self.contact
|
@@ -103,10 +272,13 @@ class User < ActiveRecord::Base
|
|
103
272
|
self.contact = c
|
104
273
|
self.save
|
105
274
|
end
|
275
|
+
true
|
106
276
|
end
|
107
277
|
def lastname
|
108
|
-
self.contact
|
278
|
+
self.contact ?
|
279
|
+
self.contact.lastname : nil
|
109
280
|
end
|
281
|
+
# Creates a new Contact unless it exists
|
110
282
|
def lastname=(v)
|
111
283
|
if self.contact
|
112
284
|
c = self.contact
|
@@ -119,8 +291,16 @@ class User < ActiveRecord::Base
|
|
119
291
|
self.contact = c
|
120
292
|
self.save
|
121
293
|
end
|
294
|
+
true
|
295
|
+
end
|
296
|
+
|
297
|
+
# Sex. 0=female, 1=male
|
298
|
+
def sex
|
299
|
+
self.contact.male==true ? 1 : 0
|
122
300
|
end
|
123
301
|
|
302
|
+
# Creates a new Contact unless it exists
|
303
|
+
#
|
124
304
|
# 1=female, 2=male
|
125
305
|
def sex=(v)
|
126
306
|
male = (v==2 ? true : false)
|
@@ -135,46 +315,15 @@ class User < ActiveRecord::Base
|
|
135
315
|
self.contact = c
|
136
316
|
self.save
|
137
317
|
end
|
318
|
+
true
|
138
319
|
end
|
139
320
|
|
140
|
-
# User's own group
|
141
|
-
has_one :hive,
|
142
|
-
:class_name => 'Group',
|
143
|
-
:foreign_key => 'classpk'
|
144
|
-
|
145
|
-
# association to usergroups
|
146
|
-
# has_and_belongs_to_many :usergroups,
|
147
|
-
# :class_name => 'Usergroup',
|
148
|
-
# :join_table => 'users_usergroups',
|
149
|
-
# :foreign_key => 'userid',
|
150
|
-
# :association_foreign_key => 'usergroupid'
|
151
|
-
|
152
|
-
# association to tags
|
153
|
-
has_many :tags,
|
154
|
-
:class_name => 'Tag::Entry',
|
155
|
-
:foreign_key => 'userid'
|
156
|
-
|
157
|
-
# association to assets
|
158
|
-
has_many :assets,
|
159
|
-
:order => 'publishdate',
|
160
|
-
:foreign_key => 'userid'
|
161
|
-
|
162
|
-
# association to wiki pages
|
163
|
-
has_many :wikipages,
|
164
|
-
:class_name => 'Wiki::Page',
|
165
|
-
:foreign_key => 'userid'
|
166
|
-
alias :articles :wikipages
|
167
|
-
|
168
|
-
# association to MessageBoardMessages
|
169
|
-
has_many :messages,
|
170
|
-
:class_name => 'MB::Message',
|
171
|
-
:foreign_key => 'userid'
|
172
|
-
|
173
321
|
|
174
322
|
# def address
|
175
323
|
# self.address || Address.new(:user=>self, :company=>self.company)
|
176
324
|
# end
|
177
325
|
|
326
|
+
# Creates a Address, unless one exists.
|
178
327
|
def address
|
179
328
|
return @address if @address
|
180
329
|
@address = Address.find_by_userid self.id
|
@@ -192,11 +341,13 @@ class User < ActiveRecord::Base
|
|
192
341
|
end
|
193
342
|
def lang=(value)
|
194
343
|
self.languageid=value
|
344
|
+
true
|
195
345
|
end
|
196
346
|
|
197
347
|
def gsm
|
198
348
|
self.phones.any? ? self.phones.first.number : nil
|
199
349
|
end
|
350
|
+
# Creates a new Phone unless it exists
|
200
351
|
def gsm=(number)
|
201
352
|
if self.phones.any?
|
202
353
|
phone = self.phones.first
|
@@ -205,15 +356,18 @@ class User < ActiveRecord::Base
|
|
205
356
|
else
|
206
357
|
Phone.create(
|
207
358
|
:userid => self.id,
|
208
|
-
:
|
359
|
+
:number_ => number,
|
209
360
|
:primary_ => true
|
210
361
|
)
|
362
|
+
self.phones.reload
|
211
363
|
end
|
364
|
+
true
|
212
365
|
end
|
213
366
|
|
214
367
|
def birthday
|
215
368
|
self.contact.birthday
|
216
369
|
end
|
370
|
+
# FIXME: should create a new Contact
|
217
371
|
def birthday=(val)
|
218
372
|
self.contact.birthday = val
|
219
373
|
self.contact.save
|
@@ -222,6 +376,7 @@ class User < ActiveRecord::Base
|
|
222
376
|
def streetaddress
|
223
377
|
self.address.street1
|
224
378
|
end
|
379
|
+
# FIXME: should create a new Address
|
225
380
|
def streetaddress=(val)
|
226
381
|
self.address.street1 = val
|
227
382
|
self.address.save
|
@@ -230,6 +385,7 @@ class User < ActiveRecord::Base
|
|
230
385
|
def zipcode
|
231
386
|
self.address.zip
|
232
387
|
end
|
388
|
+
# FIXME: should create a new Address
|
233
389
|
def zipcode=(val)
|
234
390
|
self.address.zip = val
|
235
391
|
self.address.save
|
@@ -238,11 +394,23 @@ class User < ActiveRecord::Base
|
|
238
394
|
def city
|
239
395
|
self.address.city
|
240
396
|
end
|
397
|
+
# FIXME: should create a new Address
|
241
398
|
def city=(val)
|
242
399
|
self.address.city = val
|
243
400
|
self.address.save
|
244
401
|
end
|
245
402
|
|
403
|
+
# ResourceCode associated to this instance (and scope)
|
404
|
+
def resource_code(scope=4)
|
405
|
+
ResourceCode.find(:first,
|
406
|
+
:conditions => "companyid=#{self.companyid} AND name='#{self.liferay_class}' AND scope=#{scope}")
|
407
|
+
end
|
408
|
+
|
409
|
+
# Resources associated to this instance
|
410
|
+
def resources
|
411
|
+
Resource.find(:all, :conditions => "primkey='#{self.id}'")
|
412
|
+
end
|
413
|
+
|
246
414
|
def is_active?
|
247
415
|
self.active_
|
248
416
|
end
|
@@ -250,6 +418,7 @@ class User < ActiveRecord::Base
|
|
250
418
|
def is_default?
|
251
419
|
self.defaultuser
|
252
420
|
end
|
421
|
+
alias :is_guest? :is_default?
|
253
422
|
|
254
423
|
|
255
424
|
end
|
data/lib/web/layout.rb
CHANGED
data/lib/web/layout_set.rb
CHANGED
@@ -9,6 +9,21 @@ module Web
|
|
9
9
|
'com.liferay.portal.model.LayoutSet'
|
10
10
|
end
|
11
11
|
|
12
|
+
def initialize(params)
|
13
|
+
super(params)
|
14
|
+
self.logo ||= false
|
15
|
+
self.logoid ||= 0
|
16
|
+
self.pagecount ||= 0
|
17
|
+
self.themeid ||= ''
|
18
|
+
self.colorschemeid ||= '01'
|
19
|
+
self.wapthemeid ||= 'mobile'
|
20
|
+
self.wapcolorschemeid ||= '01'
|
21
|
+
self.css ||= ''
|
22
|
+
self.virtualhost ||= ''
|
23
|
+
|
24
|
+
self.save
|
25
|
+
end
|
26
|
+
|
12
27
|
public
|
13
28
|
|
14
29
|
belongs_to :group,
|
@@ -33,6 +48,25 @@ module Web
|
|
33
48
|
Web::Layout.find(:all, :conditions => "groupid=#{self.groupid} AND privatelayout=#{self.privatelayout}" )
|
34
49
|
end
|
35
50
|
|
51
|
+
# lookup the path prefix for this LayoutSet
|
52
|
+
def url_prefix
|
53
|
+
return '/web' if self.is_public?
|
54
|
+
|
55
|
+
_class = Classname.model(Classname.find(self.group.classnameid).value)
|
56
|
+
if _class == User
|
57
|
+
return '/user' #if self.is_private?
|
58
|
+
#return '/web'
|
59
|
+
|
60
|
+
elsif _class == Group
|
61
|
+
return '/group' #if self.is_private?
|
62
|
+
#return '/web'
|
63
|
+
|
64
|
+
else
|
65
|
+
logger.debug 'FIXME: ' + _class
|
66
|
+
return nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
36
70
|
#?
|
37
71
|
# has_one :resource,
|
38
72
|
# :foreign_key => 'primkey'
|
data/lib/web/portlet.rb
CHANGED
@@ -9,6 +9,10 @@ module Web
|
|
9
9
|
belongs_to :company,
|
10
10
|
:foreign_key => "companyid"
|
11
11
|
|
12
|
+
def name
|
13
|
+
self.portletid
|
14
|
+
end
|
15
|
+
|
12
16
|
# primkey in resource_ table
|
13
17
|
def primkey(plid)
|
14
18
|
"#{plid}_LAYOUT_#{self.portletid}"
|
@@ -34,7 +38,7 @@ module Web
|
|
34
38
|
self.active_
|
35
39
|
end
|
36
40
|
|
37
|
-
# comply API with Web::
|
41
|
+
# comply API with Web::PortletPreferences
|
38
42
|
def preferences_
|
39
43
|
""
|
40
44
|
end
|
@@ -13,6 +13,10 @@ module Web
|
|
13
13
|
:class_name => 'User',
|
14
14
|
:foreign_key => 'ownerid'
|
15
15
|
|
16
|
+
def name
|
17
|
+
self.portletid.split(/_INSTANCE_/)[0]
|
18
|
+
end
|
19
|
+
|
16
20
|
# primkey in resource_ table
|
17
21
|
def primkey
|
18
22
|
"#{self.plid}_LAYOUT_#{self.portletid}"
|
@@ -37,6 +41,6 @@ module Web
|
|
37
41
|
end
|
38
42
|
return preferences
|
39
43
|
end
|
40
|
-
|
44
|
+
|
41
45
|
end
|
42
46
|
end
|
data/test/unit/tag/asset_test.rb
CHANGED
@@ -2,8 +2,9 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class Tag::AssetTest < ActiveSupport::TestCase
|
4
4
|
fixtures [
|
5
|
-
:tagsasset,
|
5
|
+
:tagsasset, :tagsassets_tagsentries,
|
6
6
|
:resource_, :resourcecode,
|
7
|
+
:classname_,
|
7
8
|
:igimage,
|
8
9
|
:mbmessage,
|
9
10
|
:blogsentry,
|
@@ -14,7 +15,7 @@ class Tag::AssetTest < ActiveSupport::TestCase
|
|
14
15
|
]
|
15
16
|
|
16
17
|
def setup
|
17
|
-
@assets = Asset.all
|
18
|
+
@assets = Tag::Asset.all
|
18
19
|
end
|
19
20
|
|
20
21
|
# each asset _must_ belong to a company
|
data/test/unit/tag/entry_test.rb
CHANGED
data/test/unit/user_test.rb
CHANGED
@@ -3,13 +3,20 @@ require 'test_helper'
|
|
3
3
|
class UserTest < ActiveSupport::TestCase
|
4
4
|
fixtures [
|
5
5
|
:organization_,
|
6
|
-
:
|
6
|
+
:address,
|
7
|
+
:phone,
|
8
|
+
:contact_,
|
9
|
+
:classname_,
|
10
|
+
:layoutset
|
7
11
|
]
|
8
12
|
|
9
13
|
def setup
|
10
14
|
@users = User.all
|
11
15
|
end
|
12
16
|
|
17
|
+
def test_create
|
18
|
+
end
|
19
|
+
|
13
20
|
# each user must belong to a company
|
14
21
|
def test_company
|
15
22
|
@users.each do |x|
|
@@ -73,6 +80,16 @@ class UserTest < ActiveSupport::TestCase
|
|
73
80
|
end
|
74
81
|
end
|
75
82
|
|
83
|
+
def test_gsm
|
84
|
+
@users.each do |u|
|
85
|
+
gsm = '+35840' + rand(10000000).to_s
|
86
|
+
u.gsm = gsm
|
87
|
+
phones = Phone.find(:all, :conditions => "userid = #{u.id}")
|
88
|
+
assert !phones.empty?
|
89
|
+
assert phones.collect(&:number).include?(gsm)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
76
93
|
def test_rigidity
|
77
94
|
# each group must exist!
|
78
95
|
groups = @users.map{|x| x.groups}.uniq
|
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.7
|
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:
|
12
|
+
date: 2009-01-05 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -50,8 +50,11 @@ files:
|
|
50
50
|
- lib/dl_folder.rb
|
51
51
|
- lib/blog_post.rb
|
52
52
|
- lib/journal
|
53
|
+
- lib/journal/template.rb
|
54
|
+
- lib/journal/structure.rb
|
53
55
|
- lib/journal/article_resource.rb
|
54
56
|
- lib/journal/article.rb
|
57
|
+
- lib/journal/feed.rb
|
55
58
|
- lib/journal/article_image.rb
|
56
59
|
- lib/user.rb
|
57
60
|
- lib/organization.rb
|
@@ -63,11 +66,14 @@ files:
|
|
63
66
|
- lib/ig
|
64
67
|
- lib/ig/image.rb
|
65
68
|
- lib/ig/folder.rb
|
69
|
+
- lib/poll
|
70
|
+
- lib/poll/question.rb
|
66
71
|
- lib/phone.rb
|
67
72
|
- lib/company.rb
|
68
73
|
- lib/calevent.rb
|
69
74
|
- lib/announcement
|
70
75
|
- lib/announcement/entry.rb
|
76
|
+
- lib/announcement/delivery.rb
|
71
77
|
- lib/account.rb
|
72
78
|
- lib/tag
|
73
79
|
- lib/tag/entry.rb
|
@@ -91,6 +97,7 @@ files:
|
|
91
97
|
- lib/bookmark
|
92
98
|
- lib/bookmark/entry.rb
|
93
99
|
- lib/bookmark/folder.rb
|
100
|
+
- lib/list_type.rb
|
94
101
|
- lib/contact.rb
|
95
102
|
- lib/resource.rb
|
96
103
|
- lib/role.rb
|
@@ -129,8 +136,11 @@ test_files:
|
|
129
136
|
- test/unit/role_test.rb
|
130
137
|
- test/unit/usergroup_test.rb
|
131
138
|
- test/unit/blog_post_test.rb
|
139
|
+
- test/unit/journal/structure_test.rb
|
132
140
|
- test/unit/journal/article_resource_test.rb
|
133
141
|
- test/unit/journal/article_test.rb
|
142
|
+
- test/unit/journal/feed_test.rb
|
143
|
+
- test/unit/journal/template_test.rb
|
134
144
|
- test/unit/journal/article_image_test.rb
|
135
145
|
- test/unit/wiki/node_test.rb
|
136
146
|
- test/unit/wiki/page_test.rb
|
@@ -139,6 +149,7 @@ test_files:
|
|
139
149
|
- test/unit/dl_folder_test.rb
|
140
150
|
- test/unit/ig/image_test.rb
|
141
151
|
- test/unit/ig/folder_test.rb
|
152
|
+
- test/unit/poll/question_test.rb
|
142
153
|
- test/unit/account_test.rb
|
143
154
|
- test/unit/announcement/entry_test.rb
|
144
155
|
- test/unit/resource_test.rb
|