hhuijser/liferay-plugins — pull request #251 by yuhai (2014-11-21 02:15:21+00:00)
Title: LPS-51693 Old calendar model-resource permission are not migrating properly when define role

Hi Hugo,

I have created one thread to ask for some helps from engineer team.

https://in.liferay.com/web/global.engineering/forums/-/message_boards/message/3930223

The issue is ""model-resource:com.liferay.portlet.calendar and com.liferay.portlet.calendar.model.CalEvent" can't be migrating properly when upgrade from 6.1 to 6.2.".

The root issue is that we have different model-resource defination between 6.1 and 6.2. Please refer to the below model-resource:
6.1: model-resource:com.liferay.portlet.calendar and com.liferay.portlet.calendar.model.CalEvent
6.2: model-resource:com.liferay.calendar.model.Calendar, com.liferay.calendar.model.CalendarBooking,com.liferay.calendar.model.CalendarResource and com.liferay.calendar

In the progress of upgrading, we didn't convert all permission defination for role regarding model-resource: com.liferay.portlet.calendar and com.liferay.portlet.calendar.model.CalEvent from 6.1.

**Please refer to the below fix logic.**

I should make sure "**com.liferay.portlet.calendar**"(6.1) matches with "**com.liferay.calendar.model.Calendar**"(6.2), and "**com.liferay.portlet.calendar.model.CalEvent**" matches with "**com.liferay.calendar.model.CalendarBooking**"(6.2) by checking CalendarImporterLocalServiceImpl.importCalEvent() method.

Through referring to CalendarImporterLocalServiceImpl.importCalEvent() {importCalendarBookingResourcePermissions(calEvent, calendarBookingId);}, it import every calendarBooking's permission action from old to new. In this process, **it discarded those actionIds which don't exist in 6.2 calendar**. This logic is in CalendarImporterLocalServiceImpl.getActionId() {}

For example,
in 6.1

com.liferay.portlet.calendar
ADD_EVENT
EXPORT_ALL_EVENTS
**PERMISSIONS**

in 6.2

com.liferay.calendar.model.Calendar

DELETE
MANAGE_BOOKINGS
**PERMISSIONS**
UPDATE
VIEW
VIEW_BOOKING_DETAILS

If one regular role own all "com.liferay.portlet.calendar" action-key, after upgrading to 6.2, this role should only own **PERMISSIONS** action-key, ADD_EVENT and EXPORT_ALL_EVENTS should be not added to this role. We also shouldn't convert ADD_EVENT to other actions.

In addition, Go to->Control panel->Role->define permission, when define "com.liferay.calendar.model.Calendar and com.liferay.calendar.model.CalendarBooking" actionIds to the deatiled role, the two model used resource blocks (**ResourceBlockLocalServiceUtil.isSupported**("com.liferay.calendar.model.Calendar or com.liferay.calendar.model.CalendarBooking") == true, in EditRolePermissionsAction.updateActions()) in EditRolePermissionsAction.updateActions() in **6.2**, we can know when define permission to Role, we will only save scope = "1,2,3" to role.

**For the two model resources, in EditRolePermissionsAction.updateActions_Blocks(), when scope = "1,3", it will invoke ResourceBlockServiceUtil.addCompanyScopePermission(scopeGroupId, companyId, selResource, roleId, actionId); when scope="2", it will invoke ResourceBlockServiceUtil.addGroupScopePermission(scopeGroupId, companyId, GetterUtil.getLong(groupId),selResource, roleId, actionId)**. So my fix used the same logic.

After import every resource permission item, the fix deletes the original data from resourcepermission table. This will avoid duplicated import data from resourcepermission table when deploy caledar portlet repeatly. That is to say, we only import once in the first deployment.

Please kindly help check it.

Thanks,
Hai