Item permissisons were not copied when publishing an item.

pull/10/head
Jens Pelzetter 2021-12-08 19:45:12 +01:00
parent 4f48eb9354
commit 5bafec04a3
3 changed files with 73 additions and 16 deletions

View File

@ -40,6 +40,7 @@ import org.libreccm.categorization.ObjectNotAssignedToCategoryException;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.AuthorizationRequired;
import org.libreccm.security.Permission;
import org.libreccm.security.RequiresPrivilege;
import org.libreccm.workflow.Workflow;
import org.libreccm.workflow.WorkflowManager;
@ -945,8 +946,14 @@ public class ContentItemManager {
liveItem = getLiveVersion(item, ContentItem.class).get();
} else {
try {
liveItem = draftItem.getClass().newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
liveItem = draftItem
.getClass()
.getDeclaredConstructor()
.newInstance();
} catch (IllegalAccessException
| InstantiationException
| InvocationTargetException
| NoSuchMethodException ex) {
throw new RuntimeException(ex);
}
}
@ -1149,9 +1156,15 @@ public class ContentItemManager {
targetAsset = sourceAttachment.getAsset();
} else {
try {
targetAsset = sourceAttachment.getAsset().getClass()
targetAsset = sourceAttachment
.getAsset()
.getClass()
.getDeclaredConstructor()
.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
} catch (IllegalAccessException
| InstantiationException
| InvocationTargetException
| NoSuchMethodException ex) {
throw new UnexpectedErrorException(ex);
}
copyAsset(sourceAsset, targetAsset);
@ -1172,6 +1185,48 @@ public class ContentItemManager {
}
}
final List<Permission> permissionsOnDraftItem = draftItem
.getPermissions();
final List<Permission> grantOnLiveItem = permissionsOnDraftItem
.stream()
.filter(
permission -> !permissionChecker
.isPermitted(
permission.getGrantedPrivilege(),
liveItem,
permission.getGrantee()
)
)
.collect(Collectors.toList());
final List<Permission> revokeFromLiveItem = liveItem
.getPermissions()
.stream()
.filter(
permission -> !permissionChecker
.isPermitted(
permission.getGrantedPrivilege(),
draftItem,
permission.getGrantee()
)
)
.collect(Collectors.toList());
for (final Permission permission : grantOnLiveItem) {
permissionManager.grantPrivilege(
permission.getGrantedPrivilege(),
permission.getGrantee(),
liveItem
);
}
for (final Permission permission : revokeFromLiveItem) {
permissionManager.revokePrivilege(
permission.getGrantedPrivilege(),
permission.getGrantee(),
liveItem
);
}
return liveItem;
}
@ -1258,7 +1313,8 @@ public class ContentItemManager {
}
private void unpublishAttachmentList(final AttachmentList attachmentList) {
for(final ItemAttachment<?> attachment : attachmentList.getAttachments()) {
for (final ItemAttachment<?> attachment : attachmentList
.getAttachments()) {
unpublishAttachment(attachment);
}

View File

@ -44,8 +44,10 @@ public abstract class AbstractContentItemListItemModelBuilder<T extends ContentI
contentItem.getDescription()
)
);
model.setName(
globalizationHelper.getValueFromLocalizedString(
contentItem.getName()
)
);
model.setDisplayName(contentItem.getDisplayName());
model.setTitle(

View File

@ -162,7 +162,7 @@ public class ItemListModel {
@Transactional(Transactional.TxType.REQUIRED)
public List<? extends AbstractContentItemListItemModel> getItems() {
if (itemList == null) {
// if (itemList == null) {
buildList(
buildLimitToType(limitToType),
collectCategories(
@ -182,7 +182,7 @@ public class ItemListModel {
listOrder,
pageSize
);
}
// }
return Collections.unmodifiableList(itemList);
}
@ -196,8 +196,7 @@ public class ItemListModel {
final CriteriaBuilder criteriaBuilder = entityManager
.getCriteriaBuilder();
final CriteriaQuery<? extends ContentItem> criteriaQuery
= criteriaBuilder
.createQuery(limitToType);
= criteriaBuilder.createQuery(limitToType);
final Root<? extends ContentItem> from = criteriaQuery
.from(limitToType);
final Join<? extends ContentItem, Categorization> catJoin = from
@ -211,7 +210,7 @@ public class ItemListModel {
criteriaBuilder.and(
catJoin.get("category").in(categories),
criteriaBuilder.equal(catJoin.get("indexObject"), false),
criteriaBuilder.equal(catJoin.get("type"), ""),
criteriaBuilder.isNull(catJoin.get("type")),
criteriaBuilder.equal(
from.get("version"), ContentItemVersion.LIVE
),