Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-29677 #6827

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion portal-impl/src/com/liferay/portal/service.xml
Expand Up @@ -1897,7 +1897,7 @@

<!-- PK fields -->

<column name="teamId" type="long" primary="true" />
<column name="teamId" type="long" primary="true" accessor="true" />

<!-- Audit fields -->

Expand Down
Expand Up @@ -70,6 +70,7 @@
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.UnicodeProperties;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil;
Expand Down Expand Up @@ -405,6 +406,8 @@ public void addGroupUsers(long groupId, long[] userIds)
indexer.reindex(userIds);

PermissionCacheUtil.clearCache();

addDefaultRolesAndTeams(groupId, userIds);
}

/**
Expand Down Expand Up @@ -4963,6 +4966,72 @@ public void verifyEmailAddress(String ticketKey)
ticketLocalService.deleteTicket(ticket);
}

protected void addDefaultRolesAndTeams(long groupId, long[] userIds)
throws PortalException, SystemException {

Group group = groupLocalService.getGroup(groupId);

UnicodeProperties groupTypeSettings = group.getTypeSettingsProperties();

List<Role> defaultGroupRoles = new ArrayList();
List<Team> defaultGroupTeams = new ArrayList();

String[] rolesIds = StringUtil.split(
groupTypeSettings.getProperty("defaultGroupRoles"),
StringPool.COMMA);
String[] teamIds = StringUtil.split(
groupTypeSettings.getProperty("defaultGroupTeams"),
StringPool.COMMA);

for (int i = 0; i < rolesIds.length; i++) {
try {
defaultGroupRoles.add(
roleLocalService.getRole(Long.valueOf(rolesIds[i])));
}
catch (Exception e) {
_log.warn("The role " + rolesIds[i] + " was not found.");
}
}

for (int i = 0; i < teamIds.length; i++) {
try {
defaultGroupTeams.add(
teamLocalService.getTeam(Long.valueOf(teamIds[i])));
}
catch (Exception e) {
_log.warn("The team " + teamIds[i] + " was not found.");
}
}

for (long userId : userIds) {
Set<Long> roleIdSet = new HashSet<Long>();
Set<Long> teamIdSet = new HashSet<Long>();

for (Role role : defaultGroupRoles) {
if (!userPersistence.containsRole(userId, role.getRoleId())) {
roleIdSet.add(role.getRoleId());
}
}

long[] userRoleIds = ArrayUtil.toArray(
roleIdSet.toArray(new Long[roleIdSet.size()]));

userGroupRoleLocalService.addUserGroupRoles(
userId, groupId, userRoleIds);

for (Team team : defaultGroupTeams) {
if (!userPersistence.containsTeam(userId, team.getTeamId())) {
teamIdSet.add(team.getTeamId());
}
}

long[] userTeamIds = ArrayUtil.toArray(
teamIdSet.toArray(new Long[teamIdSet.size()]));

userPersistence.addTeams(userId, userTeamIds);
}
}

/**
* Attempts to authenticate the user by their login and password, while
* using the AuthPipeline.
Expand Down
Expand Up @@ -34,10 +34,14 @@
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.HttpUtil;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.PrefsPropsUtil;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.UnicodeProperties;
import com.liferay.portal.kernel.util.UniqueList;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.liveusers.LiveUsers;
import com.liferay.portal.model.Group;
Expand All @@ -47,15 +51,19 @@
import com.liferay.portal.model.LayoutSet;
import com.liferay.portal.model.MembershipRequest;
import com.liferay.portal.model.MembershipRequestConstants;
import com.liferay.portal.model.Role;
import com.liferay.portal.model.Team;
import com.liferay.portal.security.auth.PrincipalException;
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.GroupServiceUtil;
import com.liferay.portal.service.LayoutLocalServiceUtil;
import com.liferay.portal.service.LayoutSetServiceUtil;
import com.liferay.portal.service.MembershipRequestLocalServiceUtil;
import com.liferay.portal.service.MembershipRequestServiceUtil;
import com.liferay.portal.service.RoleLocalServiceUtil;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portal.service.TeamLocalServiceUtil;
import com.liferay.portal.struts.PortletAction;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
Expand All @@ -64,11 +72,13 @@
import com.liferay.portlet.asset.AssetTagException;
import com.liferay.portlet.sites.util.SitesUtil;

import java.util.ArrayList;
import java.util.List;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletRequest;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

Expand Down Expand Up @@ -459,6 +469,19 @@ protected Object[] updateGroup(ActionRequest actionRequest)
typeSettingsProperties.remove("trashEntriesMaxAge");
}

// Default Group Roles and Teams

List<Role> defaultGroupRoles = getRoles(actionRequest);
List<Team> defaultGroupTeams = getTeams(actionRequest);

typeSettingsProperties.setProperty(
"defaultGroupRoles", ListUtil.toString(
defaultGroupRoles, Role.ROLE_ID_ACCESSOR, StringPool.COMMA));

typeSettingsProperties.setProperty(
"defaultGroupTeams", ListUtil.toString(
defaultGroupTeams, Team.TEAM_ID_ACCESSOR, StringPool.COMMA));

// Virtual hosts

LayoutSet publicLayoutSet = liveGroup.getPublicLayoutSet();
Expand Down Expand Up @@ -604,6 +627,48 @@ protected Object[] updateGroup(ActionRequest actionRequest)
liveGroup, oldFriendlyURL, oldStagingFriendlyURL, refererPlid};
}

protected List<Role> getRoles(PortletRequest portletRequest)
throws PortalException, SystemException {

List<Role> roles = new ArrayList<Role>();

long[] groupRolesRoleIds= StringUtil.split(ParamUtil.getString(
portletRequest, "groupRolesRoleIds"), 0L);

for (int i = 0; i < groupRolesRoleIds.length; i++) {
if (groupRolesRoleIds[i] == 0) {
continue;
}

Role role = RoleLocalServiceUtil.getRole(groupRolesRoleIds[i]);

roles.add(role);
}

return roles;
}

protected List<Team> getTeams(PortletRequest portletRequest)
throws PortalException, SystemException {

List<Team> teams = new UniqueList<Team>();

long[] groupTeamsTeamIds= StringUtil.split(ParamUtil.getString(
portletRequest, "groupTeamsTeamIds"), 0L);

for (int i = 0; i < groupTeamsTeamIds.length; i++) {
if (groupTeamsTeamIds[i] == 0) {
continue;
}

Team team = TeamLocalServiceUtil.getTeam(groupTeamsTeamIds[i]);

teams.add(team);
}

return teams;
}

private static final int _LAYOUT_SET_VISIBILITY_PRIVATE = 1;

}
2 changes: 2 additions & 0 deletions portal-impl/src/content/Language.properties
Expand Up @@ -422,6 +422,8 @@ action.VIEW_USER=View User
## Messages
##

default-roles-assignment-help-message=Select the roles that the newly assigned site members will have
default-team-assignment-help-message=Select the teams that the newly assigned site members will be member of
1-day=1 Day
1-minute=1 Minute
1-month=1 Month
Expand Down
2 changes: 1 addition & 1 deletion portal-impl/src/portal.properties
Expand Up @@ -9017,7 +9017,7 @@
#
sites.form.update.main=details,categorization,site-url,site-template
sites.form.update.seo=sitemap,robots
sites.form.update.advanced=staging,analytics,recycle-bin
sites.form.update.advanced=default-user-associations,staging,analytics,recycle-bin
sites.form.update.miscellaneous=custom-fields

#
Expand Down
8 changes: 8 additions & 0 deletions portal-service/src/com/liferay/portal/model/Team.java
Expand Up @@ -14,6 +14,8 @@

package com.liferay.portal.model;

import com.liferay.portal.kernel.util.Accessor;

/**
* The extended model interface for the Team service. Represents a row in the &quot;Team&quot; database table, with each column mapped to a property of this class.
*
Expand All @@ -29,6 +31,12 @@ public interface Team extends TeamModel, PersistedModel {
*
* Never modify this interface directly. Add methods to {@link com.liferay.portal.model.impl.TeamImpl} and rerun ServiceBuilder to automatically copy the method declarations to this interface.
*/
public static final Accessor<Team, Long> TEAM_ID_ACCESSOR = new Accessor<Team, Long>() {
public Long get(Team team) {
return team.getTeamId();
}
};

public com.liferay.portal.model.Role getRole()
throws com.liferay.portal.kernel.exception.PortalException,
com.liferay.portal.kernel.exception.SystemException;
Expand Down
4 changes: 4 additions & 0 deletions portal-web/docroot/WEB-INF/struts-config.xml
Expand Up @@ -1837,6 +1837,10 @@

<action path="/sites_admin/select_site" forward="portlet.sites_admin.select_site" />

<action path="/sites_admin/select_site_role" forward="portlet.roles_admin.select_site_role" />

<action path="/sites_admin/select_team" forward="portlet.sites_admin.select_team" />

<action path="/sites_admin/view" forward="portlet.sites_admin.view" />

<action path="/sites_admin/view_membership_requests" type="com.liferay.portlet.sites.action.ViewMembershipRequestsAction">
Expand Down
4 changes: 4 additions & 0 deletions portal-web/docroot/WEB-INF/tiles-defs.xml
Expand Up @@ -1481,6 +1481,10 @@
<put name="portlet_content" value="/portlet/sites_admin/select_site.jsp" />
</definition>

<definition name="portlet.sites_admin.select_team" extends="portlet.sites_admin">
<put name="portlet_content" value="/portlet/sites_admin/select_team.jsp" />
</definition>

<definition name="portlet.sites_admin.view" extends="portlet.sites_admin">
<put name="portlet_content" value="/portlet/sites_admin/view.jsp" />
</definition>
Expand Down
Expand Up @@ -171,6 +171,8 @@ if (step == 1) {
RoleSearchTerms searchTerms = (RoleSearchTerms)searchContainer.getSearchTerms();
%>

<div class="separator"><!-- --></div>

<liferay-ui:search-container-results>

<%
Expand Down
109 changes: 109 additions & 0 deletions portal-web/docroot/html/portlet/sites_admin/select_team.jsp
@@ -0,0 +1,109 @@
<%--
/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
--%>

<%@ include file="/html/portlet/sites_admin/init.jsp" %>

<%
String redirect = ParamUtil.getString(request, "redirect");
long groupId = ParamUtil.getLong(request, "groupId");

Group group = GroupLocalServiceUtil.getGroup(groupId);

PortletURL portletURL = renderResponse.createRenderURL();

portletURL.setParameter("struts_action", "/sites_admin/select_team");
portletURL.setParameter("groupId", String.valueOf(groupId));

pageContext.setAttribute("portletURL", portletURL);
%>

<liferay-ui:header
title="teams"
/>

<aui:form action="<%= portletURL.toString() %>" method="get" name="fm">
<liferay-portlet:renderURLParams varImpl="portletURL" />

<%
TeamSearch searchContainer = new TeamSearch(renderRequest, portletURL);
%>

<liferay-ui:search-form
page="/html/portlet/sites_admin/team_search.jsp"
searchContainer="<%= searchContainer %>"
/>

<%
TeamSearchTerms searchTerms = (TeamSearchTerms)searchContainer.getSearchTerms();

int total = TeamLocalServiceUtil.searchCount(groupId, searchTerms.getName(), searchTerms.getDescription(), new LinkedHashMap<String, Object>());

searchContainer.setTotal(total);

List results = TeamLocalServiceUtil.search(groupId, searchTerms.getName(), searchTerms.getDescription(), new LinkedHashMap<String, Object>(), searchContainer.getStart(), searchContainer.getEnd(), searchContainer.getOrderByComparator());

searchContainer.setResults(results);

portletURL.setParameter(searchContainer.getCurParam(), String.valueOf(searchContainer.getCur()));
%>

<div class="separator"><!-- --></div>

<%
List resultRows = searchContainer.getResultRows();

for (int i = 0; i < results.size(); i++) {
Team team = (Team)results.get(i);

team = team.toEscapedModel();

ResultRow row = new ResultRow(team, team.getTeamId(), i);

StringBundler sb = new StringBundler(14);

sb.append("javascript:opener.");
sb.append(renderResponse.getNamespace());
sb.append("selectTeam('");
sb.append(team.getTeamId());
sb.append("', '");
sb.append(UnicodeFormatter.toString(team.getName()));
sb.append("', '");
sb.append("groupTeams");
sb.append("', '");
sb.append(UnicodeFormatter.toString(team.getDescription()));
sb.append("', '");
sb.append(group.getGroupId());
sb.append("');");
sb.append("window.close();");

String rowHREF = sb.toString();

// Name

row.addText(team.getName(), rowHREF);

// Description

row.addText(team.getDescription(), rowHREF);

// Add result row

resultRows.add(row);
}
%>

<liferay-ui:search-iterator searchContainer="<%= searchContainer %>" />
</aui:form>