Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Alain Dresse
Setting permissions on JournalArticle
April 2, 2012 1:02 PM
Answer

Alain Dresse

Rank: Junior Member

Posts: 95

Join Date: July 18, 2011

Recent Posts

Hi,

I am trying to create a journalarticle and set edit permissions for an organisation role on that article.
I use Liferay 6.1 GA1 with mysql on unix.
Please find the code I use below:

 1
 2JournalArticle journalArticle = JournalArticleLocalServiceUtil.addArticle(
 3        userId, groupId, 0, 0,
 4        StringPool.BLANK, true, JournalArticleConstants.VERSION_DEFAULT,
 5        titleMap, null, content, "general", structureId, templateId,
 6        StringPool.BLANK, 1, 1, 2008, 0, 0, 0, 0, 0, 0, 0,
 7        true, 0, 0, 0, 0, 0, true, true, false, StringPool.BLANK,
 8        null, null, StringPool.BLANK, serviceContext);
 9
10long roleId = RoleLocalServiceUtil.getRole(companyId, "Board Member").getRoleId();
11
12ResourcePermissionLocalServiceUtil.addResourcePermission(companyId,
13        JournalArticle.class.getName(),
14        ResourceConstants.SCOPE_INDIVIDUAL,
15        Long.toString(journalArticle.getPrimaryKey()), roleId,
16        ActionKeys.UPDATE);


On the addResourcePermission call, a com.liferay.portal.NoSuchResourcePermissionException exception is thrown. I tried to add the resources with the following code right before the addResourcePermission call, with no succuess:

1
2if (ResourcePermissionLocalServiceUtil.getResourcePermissionsCount(
3        companyId, JournalArticle.class.getName(),
4        ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(journalArticle.getPrimaryKey())) == 0) {
5    JournalArticleLocalServiceUtil.addArticleResources(journalArticle, true, true);
6}


If I remove the permission setting, the journal article is correctly created, and I can set the permissions from the interface as an administrator.

Could somebody point me in the right direction ?

Many thanks and best regards,
Alain
Joan Gelonch
RE: Setting permissions on JournalArticle
November 29, 2013 6:24 AM
Answer

Joan Gelonch

Rank: New Member

Posts: 7

Join Date: August 8, 2011

Recent Posts

Hi Alain,

I know this is quite an old thread, but I ran into the same issue and I was able to solve it.

The 'addResourcePermission' method cannot be used to add permissions on the INDIVIDUAL scope, and it throws the com.liferay.portal.NoSuchResourcePermissionException exception.

At the same time, if you want to add a permission to a single JournalArticle you need to use the resourePrimKey instead of the primaryKey attribute.

So, the correct code would be:

1ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId,
2        JournalArticle.class.getName(),
3        ResourceConstants.SCOPE_INDIVIDUAL,
4        Long.toString(journalArticle.getResourcePrimKey()), roleId,
5        new String[] {ActionKeys.UPDATE)};


This is working for me.
Alain Dresse
RE: Setting permissions on JournalArticle
November 30, 2013 6:54 AM
Answer

Alain Dresse

Rank: Junior Member

Posts: 95

Join Date: July 18, 2011

Recent Posts

Thanks Joan !