Content Slot Editing Permissions in CMS Cockpit
Situation
Content slots are named areas in the page for CMS components. These area are not movable or removable, but you are allowed to edit a set of components inside the slots. The default hybris doesn’t allow to manage editing permissions for the specific content slots (e.g. Header or Footer). The access management in WCMS is available only on the component and page/page template level, but not on the content slot level. It is required to restrict the access for specific users or user groups.Example
- All administrators from the group “ContentAdmins” shouldn’t have access to any components of the content slot “Footer”.
Solution
WCMS is poorly extendable, so for this solution I extended the existing service,CMSPageLockingService
CMSPageLockingService
isContentSlotLockedForUser
getSlotLockers
isContentSlotLockedForUser
getSlotLockers
isContentSlotLockedForUser
getSlotLockers
getSlotLockers
isContentSlotLockedForUser
isContentSlotLockedForUser
getSlotLockers
public class MyCMSPageLockingService extends DefaultCMSPageLockingService {
@Resource
private UserService userService;
private HashMap<ContentSlotModel, UserModel> lockedContentSlot = new HashMap<>();
public boolean isContentSlotLockedForUser(ContentSlotModel contentSlotModel, UserModel userModel) {
boolean result = super.isContentSlotLockedForUser(contentSlotModel, userModel);
UserModel systemUser = userService.getUserForUID("PermissionManager");
List<PrincipalModel> principals = new ArrayList<>();
Set<PrincipalGroupModel> groupsOfTheCurrentUser = userModel.getAllGroups();
principals.add(userModel);
principals.addAll(groupsOfTheCurrentUser);
for (PrincipalModel p : contentSlotModel.getNotAllowedFor()) {
if (principals.contains(p)) {
lockedContentSlot.put(contentSlotModel, systemUser);
return true;
}
}
return result;
}
@Override
public Collection<UserModel> getSlotLockers(ContentSlotModel contentSlotModel) {
if (lockedContentSlot.get(contentSlotModel) != null) {
return Collections.singletonList(lockedContentSlot.remove(contentSlotModel));
}
return super.getSlotLockers(contentSlotModel);
}
}
@Resource
private UserService userService;
private HashMap<ContentSlotModel, UserModel> lockedContentSlot = new HashMap<>();
public boolean isContentSlotLockedForUser(ContentSlotModel contentSlotModel, UserModel userModel) {
boolean result = super.isContentSlotLockedForUser(contentSlotModel, userModel);
UserModel systemUser = userService.getUserForUID("PermissionManager");
List<PrincipalModel> principals = new ArrayList<>();
Set<PrincipalGroupModel> groupsOfTheCurrentUser = userModel.getAllGroups();
principals.add(userModel);
principals.addAll(groupsOfTheCurrentUser);
for (PrincipalModel p : contentSlotModel.getNotAllowedFor()) {
if (principals.contains(p)) {
lockedContentSlot.put(contentSlotModel, systemUser);
return true;
}
}
return result;
}
@Override
public Collection<UserModel> getSlotLockers(ContentSlotModel contentSlotModel) {
if (lockedContentSlot.get(contentSlotModel) != null) {
return Collections.singletonList(lockedContentSlot.remove(contentSlotModel));
}
return super.getSlotLockers(contentSlotModel);
}
}
- Redeclare a bean
cmsPageLockingService
- Add a system user, with uid = “PermissionManager”
Video
© Rauf Aliev, January 2017
gclub casino
8 May 2017 at 21:32
thank for posting is great