Forums de discussion
Doesn't work to set permissions on journal article
Jack Palm, modifié il y a 8 années.
Doesn't work to set permissions on journal article
New Member Publications: 4 Date d'inscription: 29/01/16 Publications récentes
I am adding a journal article in code in one of my portlets. It all works fine. But I only want a few organizations to see the article and because of this I try to set Resource Permissions "View" for these Organizations and remove the actions from Guest and User roles.
Each Organization has its own role. I do not get what I am doing wrong here. Is it because I am trying to set an empty string[] with action ids for guest and user? Or am I doing the hole thing wrong?
Problem is everyone can see the article and the code runs without errors but I do not want everyone to see the article. orgsArray = is an array with the organizations ids.
Code:
Thanks
Each Organization has its own role. I do not get what I am doing wrong here. Is it because I am trying to set an empty string[] with action ids for guest and user? Or am I doing the hole thing wrong?
Problem is everyone can see the article and the code runs without errors but I do not want everyone to see the article. orgsArray = is an array with the organizations ids.
Code:
JournalArticleLocalServiceUtil.updateJournalArticle(ja);
for(int i = 0; i < orgsArray.length; i++){
long orgID = Long.valueOf(orgsArray[i]).longValue();
String[] actionIds = new String[1];
actionIds[0] = "VIEW";
Organization org = OrganizationLocalServiceUtil.getOrganization(orgID);
String primKey = ja.getPrimaryKey() + "";
if(i == 0){
String[] actionIdsUser = new String[0];
Role user = RoleLocalServiceUtil.getRole(ja.getCompanyId(), RoleConstants.USER);
ResourcePermissionLocalServiceUtil.setResourcePermissions(ja.getCompanyId(), "com.liferay.portlet.journal.model.JournalArticle", 4, primKey, user.getRoleId(), actionIdsUser);
Role guest = RoleLocalServiceUtil.getRole(ja.getCompanyId(), RoleConstants.GUEST);
ResourcePermissionLocalServiceUtil.setResourcePermissions(ja.getCompanyId(), "com.liferay.portlet.journal.model.JournalArticle", 4, primKey, guest.getRoleId(), actionIdsUser);
}
Role role = RoleLocalServiceUtil.getRole(ja.getCompanyId(), org.getName());
ResourcePermissionLocalServiceUtil.setResourcePermissions(ja.getCompanyId(), "com.liferay.portlet.journal.model.JournalArticle", 4, primKey, role.getRoleId(), actionIds);
}
AssetEntry ae = AssetEntryLocalServiceUtil.getEntry(JournalArticle.class.getName(), ja.getResourcePrimKey());
List<assetcategory> l = AssetCategoryLocalServiceUtil.getCategories("com.liferay.portlet.journal.model.JournalArticle", ja.getResourcePrimKey());
for (AssetCategory ac : l){
AssetEntryUtil.removeAssetCategory(ae.getPrimaryKey(), ac);
}
AssetCategory assetCategory = AssetCategoryLocalServiceUtil.getAssetCategory(Long.valueOf(securityClass));
AssetEntryUtil.addAssetCategory(ae.getPrimaryKey(), assetCategory);
}</assetcategory>
Thanks
Juan Gonzalez, modifié il y a 8 années.
RE: Doesn't work to set permissions on journal article
Liferay Legend Publications: 3089 Date d'inscription: 28/10/08 Publications récentes
Hi Jack,
did you try setting this property to "true"? (false by default):
did you try setting this property to "true"? (false by default):
#
# Set this to true to check that a user has the VIEW permission on a
# Journal article when its content is rendered.
#
journal.article.view.permission.check.enabled=true
Jack Palm, modifié il y a 8 années.
RE: Doesn't work to set permissions on journal article
New Member Publications: 4 Date d'inscription: 29/01/16 Publications récentes
Hi!
Yes, it is in my portal-ext.properties.
Should I change anything in my code?
Thanks
Yes, it is in my portal-ext.properties.
Should I change anything in my code?
Thanks
Jack Palm, modifié il y a 8 années.
RE: Doesn't work to set permissions on journal article
New Member Publications: 4 Date d'inscription: 29/01/16 Publications récentes
I have done some more research and it looks like something in my code is wrong but I cant figure out what. I tried to print the roles for the resource permissions from the Journal Article after I added them but the only Resource Permission printed is "Owner". Even though in the first loop I print all the Roles and they look all fine.
I hope someone can tell me what is wrong with this new information! Thnx
First print when setting the Resource permissions:
ROLE UNDER WORK: Alingsas
ROLE UNDER WORK: Austin
ROLE UNDER WORK: Arvika
Second print when getting the resource permission (no errors but they were never added):
ROLE NAME: Owner
I hope someone can tell me what is wrong with this new information! Thnx
First print when setting the Resource permissions:
ROLE UNDER WORK: Alingsas
ROLE UNDER WORK: Austin
ROLE UNDER WORK: Arvika
Second print when getting the resource permission (no errors but they were never added):
ROLE NAME: Owner
for(int i = 0; i < orgsArray.length; i++){
long orgID = Long.valueOf(orgsArray[i]).longValue();
String[] actionIds = new String[1];
actionIds[0] = "VIEW";
Organization org = OrganizationLocalServiceUtil.getOrganization(orgID);
String primKey = ja.getPrimaryKey() + "";
if(i == 0){
String[] actionIdsUser = new String[0];
Role user = RoleLocalServiceUtil.getRole(ja.getCompanyId(), RoleConstants.USER);
ResourcePermissionLocalServiceUtil.setResourcePermissions(ja.getCompanyId(), "com.liferay.portlet.journal.model.JournalArticle", 4, primKey, user.getRoleId(), actionIdsUser);
Role guest = RoleLocalServiceUtil.getRole(ja.getCompanyId(), RoleConstants.GUEST);
ResourcePermissionLocalServiceUtil.setResourcePermissions(ja.getCompanyId(), "com.liferay.portlet.journal.model.JournalArticle", 4, primKey, guest.getRoleId(), actionIdsUser);
}
Role role = RoleLocalServiceUtil.getRole(ja.getCompanyId(), org.getName());
System.out.println("ROLE UNDER WORK: " + role.getName());
ResourcePermissionLocalServiceUtil.setResourcePermissions(ja.getCompanyId(), "com.liferay.portlet.journal.model.JournalArticle", 4, primKey, role.getRoleId(), actionIds);
}
JournalArticleLocalServiceUtil.updateJournalArticle(ja);
List<resourcepermission> list = ResourcePermissionLocalServiceUtil.getResourcePermissions(ja.getCompanyId(), JournalArticle.class.getName(), 4, String.valueOf(ja.getResourcePrimKey()));
for(ResourcePermission rp : list)
{
Role role = RoleLocalServiceUtil.getRole(rp.getRoleId());
String roleName = role.getName().trim();
System.out.println("ROLE NAME: " + roleName);
}</resourcepermission>
Rautureau Jérôme, modifié il y a 8 années.
RE: Doesn't work to set permissions on journal article
Junior Member Publications: 52 Date d'inscription: 22/02/08 Publications récentes
Same problem on my installation (Worked on LFR 6.2.2, broken on LFR 6.2.5)
i want to add automatically guest view permission in a listener (onAfterUpdate)
Apparently,
returns always false...
I have told to my users to add content from Frontend website (witch adds the permission correctly)
i want to add automatically guest view permission in a listener (onAfterUpdate)
Apparently,
ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, JournalArticle.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(model.getPrimaryKey()), roleId, ActionKeys.VIEW)
returns always false...
final long roleId = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST).getRoleId();
final Map<long, string[]> roles = new HashMap<long, string[]>();
roles.put(roleId, new String[] { ActionKeys.VIEW });
if (!ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, JournalArticle.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(model.getPrimaryKey()), roleId, ActionKeys.VIEW)) {
ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, JournalArticle.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(model.getPrimaryKey()), roles);
}</long,></long,>
I have told to my users to add content from Frontend website (witch adds the permission correctly)
Rautureau Jérôme, modifié il y a 8 années.
RE: Doesn't work to set permissions on journal article
Junior Member Publications: 52 Date d'inscription: 22/02/08 Publications récentes
OK in the DB i have seen that we have to take the model.getResourcePrimKey() for JournalArticle and not the model.getPrimKey()
despite that always not seen Guest view permission correctly set...
Full code :
despite that always not seen Guest view permission correctly set...
Full code :
final long roleId = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST).getRoleId();
final Map<long, string[]> roles = new HashMap<long, string[]>();
roles.put(roleId, new String[] { ActionKeys.VIEW });
if (!ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, JournalArticle.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(model.getResourcePrimKey()), roleId, ActionKeys.VIEW)) {
ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, JournalArticle.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(model.getResourcePrimKey()), roles);
}</long,></long,>