- adds missing condition to permissions conversion for export, if roleCollection in groups is empty;
- replaces false id setting in ng-class for role with acsObjects generateId method

git-svn-id: https://svn.libreccm.org/ccm/trunk@4651 8810af33-2d31-482b-a856-94f89814c4df
master
tosmers 2017-03-29 16:05:49 +00:00
parent 3c71f60e4d
commit 7891fb7371
2 changed files with 79 additions and 43 deletions

View File

@ -18,11 +18,11 @@
*/ */
package com.arsdigita.portation.conversion.core.security; package com.arsdigita.portation.conversion.core.security;
import com.arsdigita.kernel.Group;
import com.arsdigita.kernel.Party;
import com.arsdigita.kernel.RoleCollection; import com.arsdigita.kernel.RoleCollection;
import com.arsdigita.portation.conversion.NgCollection; import com.arsdigita.portation.conversion.NgCollection;
import com.arsdigita.portation.modules.core.core.CcmObject; import com.arsdigita.portation.modules.core.core.CcmObject;
import com.arsdigita.portation.modules.core.security.Group;
import com.arsdigita.portation.modules.core.security.Party;
import com.arsdigita.portation.modules.core.security.Permission; import com.arsdigita.portation.modules.core.security.Permission;
import com.arsdigita.portation.modules.core.security.Role; import com.arsdigita.portation.modules.core.security.Role;
import com.arsdigita.portation.modules.core.security.RoleMembership; import com.arsdigita.portation.modules.core.security.RoleMembership;
@ -120,28 +120,38 @@ public class PermissionConversion {
*/ */
private static void setGranteeDependency(List<com.arsdigita.kernel private static void setGranteeDependency(List<com.arsdigita.kernel
.permissions.Permission> trunkPermissions) { .permissions.Permission> trunkPermissions) {
for (com.arsdigita.kernel.permissions.Permission trunkPermission : for (com.arsdigita.kernel.permissions.Permission
trunkPermissions) { trunkPermission : trunkPermissions) {
long permissionId = PermissionIdMapper.map.get( long permissionId = PermissionIdMapper.map.get(
((BigDecimal) trunkPermission.getACSObject().get("id")).longValue() ((BigDecimal) trunkPermission.getACSObject().get("id")).
+ ((BigDecimal) trunkPermission.getPartyOID().get("id")).longValue() longValue()
+ ((BigDecimal) trunkPermission.getPartyOID().get("id")).
longValue()
); );
Permission permission = NgCollection.permissions.get(permissionId); Permission permission = NgCollection.permissions.get(permissionId);
// get all parties serving as the grantee of this permission
BigDecimal trunkGranteeId = (BigDecimal) trunkPermission BigDecimal trunkGranteeId = (BigDecimal) trunkPermission
.getPartyOID().get("id"); .getPartyOID().get("id");
List<Party> trunkParties = Party.getAllObjectParties(); List<com.arsdigita.kernel.Party> trunkParties =
com.arsdigita.kernel.Party.getAllObjectParties();
trunkParties.stream().filter(p -> Objects.equals(p.getID(), trunkParties.stream().filter(p -> Objects.equals(p.getID(),
trunkGranteeId)).collect(Collectors.toList()); trunkGranteeId)).collect(Collectors.toList());
for (Party trunkGranteeParty : trunkParties) { for (com.arsdigita.kernel.Party trunkGranteeParty : trunkParties) {
// grantee instance of Group, possibly multiple roles
if (trunkGranteeParty instanceof Group) { // grantee instance of Group, possibly multiple roles or none
RoleCollection granteeCollection = ((Group) if (trunkGranteeParty instanceof com.arsdigita.kernel.Group) {
trunkGranteeParty).getRoles(); com.arsdigita.kernel.Group trunkGranteeGroup =
(com.arsdigita.kernel.Group) trunkGranteeParty;
RoleCollection roleCollection = ((com.arsdigita.kernel.
Group) trunkGranteeParty).getRoles();
// if group contains 1 or more roles
if (!roleCollection.isEmpty()) {
boolean multipleGrantees = false; boolean multipleGrantees = false;
while (granteeCollection.next()) { while (roleCollection.next()) {
Role grantee = NgCollection.roles.get(granteeCollection Role grantee = NgCollection.roles.get(roleCollection
.getRole().getID().longValue()); .getRole().getID().longValue());
// set grantee and opposed associations // set grantee and opposed associations
@ -166,22 +176,28 @@ public class PermissionConversion {
duplicatePermission.getPermissionId()); duplicatePermission.getPermissionId());
} }
} }
// if group contains no roles, new Role necessary
} else {
Group member = NgCollection.groups.get
(trunkGranteeParty.getID().longValue());
Role granteeRole = createNewRole(member);
// set grantee and opposed association
permission.setGrantee(granteeRole);
granteeRole.addPermission(permission);
}
// grantee instance of User, new Role necessary // grantee instance of User, new Role necessary
} else if (trunkGranteeParty instanceof com.arsdigita.kernel } else if (trunkGranteeParty instanceof com.arsdigita.kernel
.User) { .User) {
com.arsdigita.kernel.User trunkGranteeUser = (com com.arsdigita.kernel.User trunkGranteeUser = (com
.arsdigita.kernel.User) trunkGranteeParty; .arsdigita.kernel.User) trunkGranteeParty;
// create new role for this user and its membership
User member = NgCollection.users.get User member = NgCollection.users.get
(trunkGranteeUser.getID().longValue()); (trunkGranteeUser.getID().longValue());
// might cause problems cause the
// task assignments are missing Role granteeRole = createNewRole(member);
Role granteeRole = new Role(member.getName() + "_role");
RoleMembership roleMembership = new RoleMembership
(granteeRole, member);
member.addRoleMembership(roleMembership);
granteeRole.addMembership(roleMembership);
// set grantee and opposed association // set grantee and opposed association
permission.setGrantee(granteeRole); permission.setGrantee(granteeRole);
@ -190,4 +206,23 @@ public class PermissionConversion {
} }
} }
} }
/**
* Creates a new role for a given member and sets its membership.
*
* @param member Member of the newly created role
*
* @return A role for the specified member
*/
private static Role createNewRole(Party member) {
// might cause problems cause the
// task assignments are missing
Role granteeRole = new Role(member.getName() + "_role");
RoleMembership roleMembership = new RoleMembership(granteeRole, member);
member.addRoleMembership(roleMembership);
granteeRole.addMembership(roleMembership);
return granteeRole;
}
} }

View File

@ -18,6 +18,7 @@
*/ */
package com.arsdigita.portation.modules.core.security; package com.arsdigita.portation.modules.core.security;
import com.arsdigita.kernel.ACSObject;
import com.arsdigita.portation.AbstractMarshaller; import com.arsdigita.portation.AbstractMarshaller;
import com.arsdigita.portation.Portable; import com.arsdigita.portation.Portable;
import com.arsdigita.portation.conversion.NgCollection; import com.arsdigita.portation.conversion.NgCollection;
@ -69,7 +70,7 @@ public class Role implements Portable {
} }
public Role(final String name) { public Role(final String name) {
this.roleId = NgCollection.roles.size() + 1; this.roleId = ACSObject.generateID().longValue();
this.name = name; this.name = name;
this.memberships = new HashSet<>(); this.memberships = new HashSet<>();