Class Group
In: lib/group.rb
Parent: ActiveRecord::Base

This model represents the user groups (communities) in the lportal database.

Methods

External Aliases

organizations -> orgs

Public Class methods

Actions for Permissions.

[Source]

    # File lib/group.rb, line 14
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

Creates a new group (community).

Some instances are created based on the Classname of the Group. User‘s own group, for instance, has to be created with classnameid and classpk.

The Group may also have public and private Web::LayoutSet s.

This process is engineered by creating a new role with Liferay‘s (v. 5.1.1) tools and inspecting the database dump diffs.

Mandatory parameters:

 - companyid
 - creatoruserid

[Source]

     # File lib/group.rb, line 44
 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: 
 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 # -"-
 57:     self.parentgroupid ||= 0
 58:     self.livegroupid   ||= 0
 59:     self.name          ||= ''
 60:     self.description   ||= ''
 61:     self.type_         ||= 1
 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
 75: 
 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
144:   end

Public Instance methods

Assign User to be a member of this Group

[Source]

     # File lib/group.rb, line 248
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

[Source]

     # File lib/group.rb, line 267
267:   def is_active?
268:     self.active_
269:   end

[Source]

     # File lib/group.rb, line 279
279:   def is_private?
280:     self.type_ == 3
281:   end

[Source]

     # File lib/group.rb, line 275
275:   def is_protected?
276:     self.type_ == 2
277:   end

[Source]

     # File lib/group.rb, line 271
271:   def is_public?
272:     self.type_ == 1
273:   end

Does any of the layouts include this portlet? See select_layouts_with

[Source]

     # File lib/group.rb, line 326
326:   def layouts_include?(portlet,pl=nil)
327:     self.select_layouts_with(portlet,pl).any?
328:   end

com.liferay.portal.model.Group

[Source]

    # File lib/group.rb, line 9
 9:   def liferay_class
10:     'com.liferay.portal.model.Group'
11:   end

Members by the group type, ie. if the group is of type Organization, return Organization members.

[Source]

     # File lib/group.rb, line 238
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

[Source]

     # File lib/group.rb, line 225
225:   def name
226:     self.classnameid != 0 ?
227:       self.owner.name : super
228:   end

find owner by classnameid + classpk

[Source]

     # File lib/group.rb, line 231
231:   def owner
232:     return nil if self.classnameid==0
233:     _class = Classname.model(Classname.find(self.classnameid).value)
234:     _class.find self.classpk
235:   end

URL path to this Group‘s public or private page

[Source]

     # File lib/group.rb, line 284
284:   def path(pl=:public)
285:     case pl
286:     when :public
287:       self.public_layouts.any? ?
288:         self.public_layoutset.url_prefix + self.friendlyurl : nil
289: 
290:     when :private
291:       self.private_layouts.any? ?
292:         self.private_layoutset.url_prefix + self.friendlyurl : nil
293: 
294:     else
295:       nil
296:     end
297:   end

ResourceCode associated to this instance (and scope)

[Source]

     # File lib/group.rb, line 300
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

Selects the layout (from both public and private) that has the portlet. Parameters:

 - portlet     can be either a String of portlet name (eg. 'message_boards') or a Web::PortletName instance.
 - pl          only check public or private layouts? defaults to both. ( nil | :public | :private )

[Source]

     # File lib/group.rb, line 309
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

[Validate]