001
014
015 package com.liferay.portal.upgrade.v6_0_12;
016
017 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
018 import com.liferay.portal.model.ResourceConstants;
019 import com.liferay.portal.model.Role;
020 import com.liferay.portal.model.RoleConstants;
021 import com.liferay.portal.security.permission.ResourceActionsUtil;
022 import com.liferay.portal.service.ResourceActionLocalServiceUtil;
023 import com.liferay.portal.service.ResourcePermissionLocalServiceUtil;
024 import com.liferay.portal.service.RoleLocalServiceUtil;
025
026 import java.util.List;
027
028
031 public class UpgradePermission extends UpgradeProcess {
032
033 @Override
034 protected void doUpgrade() throws Exception {
035
036
037
038
039 runSQL("alter table Company add active_ BOOLEAN");
040 runSQL("update Company set active_ = TRUE");
041
042 runSQL(
043 "update Role_ set name = 'Site Administrator' where name = " +
044 "'Community Administrator'");
045 runSQL(
046 "update Role_ set name = 'Site Member' where name = 'Community " +
047 "Member'");
048 runSQL(
049 "update Role_ set name = 'Site Owner' where name = 'Community " +
050 "Owner'");
051 runSQL(
052 "update Role_ set name = 'Organization User' where name = " +
053 "'Organization Member'");
054
055
056
057 List<String> modelActions = ResourceActionsUtil.getModelResourceActions(
058 Role.class.getName());
059
060 ResourceActionLocalServiceUtil.checkResourceActions(
061 Role.class.getName(), modelActions);
062
063
064
065 RoleLocalServiceUtil.checkSystemRoles();
066
067 updatePermissions("com.liferay.portlet.bookmarks", true, true);
068 updatePermissions("com.liferay.portlet.documentlibrary", false, true);
069 updatePermissions("com.liferay.portlet.imagegallery", true, true);
070 updatePermissions("com.liferay.portlet.messageboards", true, true);
071 updatePermissions("com.liferay.portlet.shopping", true, true);
072 }
073
074 protected void updatePermissions(
075 String name, boolean community, boolean guest)
076 throws Exception {
077
078 List<String> modelActions = ResourceActionsUtil.getModelResourceActions(
079 name);
080
081 ResourceActionLocalServiceUtil.checkResourceActions(name, modelActions);
082
083 int scope = ResourceConstants.SCOPE_INDIVIDUAL;
084 long actionIdsLong = 1;
085
086 if (community) {
087 ResourcePermissionLocalServiceUtil.addResourcePermissions(
088 name, RoleConstants.SITE_MEMBER, scope, actionIdsLong);
089 ResourcePermissionLocalServiceUtil.addResourcePermissions(
090 name, RoleConstants.ORGANIZATION_USER, scope, actionIdsLong);
091 }
092
093 if (guest) {
094 ResourcePermissionLocalServiceUtil.addResourcePermissions(
095 name, RoleConstants.GUEST, scope, actionIdsLong);
096 }
097
098 ResourcePermissionLocalServiceUtil.addResourcePermissions(
099 name, RoleConstants.OWNER, scope, actionIdsLong);
100 }
101
102 }