Foros de discusión

Model resource default permissions issue

Christophe Noel, modificado hace 9 años.

Model resource default permissions issue

Junior Member Mensajes: 99 Fecha de incorporación: 28/09/12 Mensajes recientes
Hello,

Everything works fine with my model resources permissions excepted for the assignment of default permissions.
Note also for information that nowhere the documentation states that the ResourceLocalServiceUtil.addModelResources API has changed (guest/group permissions parameter changed from boolean to String[]).

For ease of use, I have created a ServiceContext like this:
ServiceContext serviceContext =  ServiceContextFactory.getInstance(MyModelClass.class.getName(), req);

and I can see that serviceContext.getGroupPermissions() is empty

Of course, I have defined my model resource in appropriate file:
<model-resource>
		<model-name>xxx.yyyy.MyModelClass</model-name>
		<portlet-ref>
			<portlet-name>MyPortlet</portlet-name>
		</portlet-ref>
		<permissions>
			<supports>
				<action-key>VIEW</action-key>
				<action-key>SUBMIT</action-key>
			</supports>
			<site-member-defaults>
			<action-key>VIEW</action-key>
			<action-key>SUBMIT</action-key>
			</site-member-defaults>
			<guest-defaults>
			<action-key>VIEW</action-key>
			</guest-defaults>
			<guest-unsupported>
			</guest-unsupported>
		</permissions>
	</model-resource>


For debug, I can also see that the following also returns null
String[] groupPermissions = PortalUtil.getGroupPermissions(req, MyModelClass.class.getName());{


Should it not return the groupPermissions configured in the action-resources file ?
Thanks for any help.

Config : Liferay 6.2 bundled with Tomcat / Liferay Faces 3.2.4-ga5
thumbnail
David H Nebinger, modificado hace 9 años.

RE: Model resource default permissions issue

Liferay Legend Mensajes: 14914 Fecha de incorporación: 2/09/06 Mensajes recientes
There's a comment in ResourceLocalServiceImpl with the following:

	 * If the service context specifies that default group or default guest
	 * permissions are to be added, then only default permissions are added. See
	 * {@link com.liferay.portal.service.ServiceContext#setAddGroupPermissions(
	 * boolean)} and {@link
	 * com.liferay.portal.service.ServiceContext#setAddGuestPermissions(
	 * boolean)}.


So does your service context have the flag set?
Christophe Noel, modificado hace 9 años.

RE: Model resource default permissions issue

Junior Member Mensajes: 99 Fecha de incorporación: 28/09/12 Mensajes recientes
Thanks for your help David.

But this Flag is used for the method signature "addModelResources(AuditedModel auditedModel, ServiceContext serviceContext)".

In my case (public void addModelResources(long companyId, long groupId, long userId, String name,long primKey, String[] groupPermissions, String[] guestPermissions)), I call with serviceContext.getGroupPermissions() and serviceContext.getGuestPermissions() which are empty.

Maybe I misunderstood something ?
Thanks.
thumbnail
Juan Gonzalez, modificado hace 9 años.

RE: Model resource default permissions issue

Liferay Legend Mensajes: 3089 Fecha de incorporación: 28/10/08 Mensajes recientes
Hi Christophe,

can you try adding these two hidden fields in your form when adding that entity?

<aui:input type="hidden" name="addGuestPermissions" value="true" />
<aui:input type="hidden" name="addGroupPermissions" value="true" />


Does that work for you?
thumbnail
Kyle Joseph Stiemann, modificado hace 9 años.

RE: Model resource default permissions issue

Liferay Master Mensajes: 760 Fecha de incorporación: 14/01/13 Mensajes recientes
I don't know if this is related to your problem, but I recommend that you get the instance of ServiceContext by calling LiferayFacesContext.getInstance().getServiceContext() instead. If you want to see what the code does, you can look at LiferayPortletHelperImpl.getServiceContext(). It is important that the companyId and scopeGroupId are set properly in the ServiceContext in order for the Liferay permissions system to work correctly.

- Kyle
Christophe Noel, modificado hace 9 años.

RE: Model resource default permissions issue

Junior Member Mensajes: 99 Fecha de incorporación: 28/09/12 Mensajes recientes
Thanks, all. I will try all of this as soon as possible, but unfortunately for me, the following weeks will be full of documentation writing.
Christophe Noel, modificado hace 9 años.

RE: Model resource default permissions issue

Junior Member Mensajes: 99 Fecha de incorporación: 28/09/12 Mensajes recientes
I have read more in details the implementation and I have found answers on how to add default permissions defined in action-resources model file:

CASE 1
In the case of an auditedModel, simply use the already known solution shown below:
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
ResourceLocalServiceUtil.addModelResources(AuditedModel auditedModel, ServiceContext serviceContext) 



CASE 2
In case you're not using an auditedModel, it is strange but you have to manually retrieve the actions using ResourceActionsUtil
List<string> groupList = ResourceActionsUtil.getModelResourceGroupDefaultActions(WProcess.class.getName());
 String[] group = groupList.toArray(new String[groupList.size()]);
List<string> guestList= ResourceActionsUtil.getModelResourceGroupDefaultActions(WProcess.class.getName());
 String[] guest= groupList.toArray(new String[groupList.size()]);
ResourceLocalServiceUtil.addModelResources(companyId,groupId,userId,name,long primKey,group,guest);</string></string>
thumbnail
David H Nebinger, modificado hace 9 años.

RE: Model resource default permissions issue

Liferay Legend Mensajes: 14914 Fecha de incorporación: 2/09/06 Mensajes recientes
Thanks for sharing, Christophe.

I see though in case 2 that you are using ResourceActionsUtil.getModelResourceGroupDefaultActions(WProcess.class.getName()) for both guest and group. I'm guessing that there's probably a typo in there, but wanted to see if that's what you really had to go with...
Christophe Noel, modificado hace 8 años.

RE: Model resource default permissions issue

Junior Member Mensajes: 99 Fecha de incorporación: 28/09/12 Mensajes recientes
Oups sorry. It is my custom resource class.