LPS-51693

The PR extends from https://github.com/hhuijser/liferay-plugins/pull/251

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
<model-resource>
<model-name>com.liferay.portlet.calendar</model-name>
<action-key>ADD_EVENT</action-key>
<action-key>EXPORT_ALL_EVENTS</action-key>
<action-key>**PERMISSIONS**</action-key>
</model-resource>

in 6.2
<model-resource>
<model-name>com.liferay.calendar.model.Calendar</model-name>
<supports>
<action-key>DELETE</action-key>
<action-key>MANAGE_BOOKINGS</action-key>
<action-key>**PERMISSIONS**</action-key>
<action-key>UPDATE</action-key>
<action-key>VIEW</action-key>
<action-key>VIEW_BOOKING_DETAILS</action-key>
<model-resource>

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