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