From 7def661604d3ffaad3d034803369d7f6b1a85266 Mon Sep 17 00:00:00 2001 From: Sam Ottenhoff Date: Wed, 14 Jul 2021 08:42:05 -0400 Subject: [PATCH] SAK-43648 msgcntr duplicate topic not saving custom permissions (#9442) Co-authored-by: Earle Nietzel --- .../messageforums/DiscussionForumTool.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/msgcntr/messageforums-app/src/java/org/sakaiproject/tool/messageforums/DiscussionForumTool.java b/msgcntr/messageforums-app/src/java/org/sakaiproject/tool/messageforums/DiscussionForumTool.java index 36c6096f3067..87d088afbc99 100644 --- a/msgcntr/messageforums-app/src/java/org/sakaiproject/tool/messageforums/DiscussionForumTool.java +++ b/msgcntr/messageforums-app/src/java/org/sakaiproject/tool/messageforums/DiscussionForumTool.java @@ -7718,23 +7718,16 @@ private DiscussionTopicBean duplicateTopic(Long originalTopicId, DiscussionForum newTopic.setAutoMarkThreadsRead(fromTopic.getAutoMarkThreadsRead()); // Get/set the topic's permissions - - Set topicMembershipItemSet = uiPermissionsManager.getTopicItemsSet(fromTopic); - - if (topicMembershipItemSet != null && !topicMembershipItemSet.isEmpty() ) { //&& allowedPermNames != null && !allowedPermNames.isEmpty() - log.debug("About to assign topicMembershipItemSet's iterator"); - Iterator membershipIter = topicMembershipItemSet.iterator(); - while (membershipIter.hasNext()) { - log.debug("About to get a member of membershipIter"); - DBMembershipItem oldItem = (DBMembershipItem)membershipIter.next(); - log.debug("About to getMembershipItemCopy()"); - DBMembershipItem newItem = getMembershipItemCopy(oldItem); - if (newItem != null) { - newItem = permissionLevelManager.saveDBMembershipItem(newItem); - newTopic.addMembershipItem(newItem); - } - } + Set fromTopicMembershipItems = uiPermissionsManager.getTopicItemsSet(fromTopic); + if (fromTopicMembershipItems != null) { + for (DBMembershipItem fromTopicMembershipItem : fromTopicMembershipItems) { + DBMembershipItem membershipItemCopy = getMembershipItemCopy(fromTopicMembershipItem); + DBMembershipItem savedMembershipItem = permissionLevelManager.saveDBMembershipItem(membershipItemCopy); + newTopic.addMembershipItem(savedMembershipItem); + ((DBMembershipItemImpl) savedMembershipItem).setTopic(newTopic); + } } + // Add the attachments List fromTopicAttach = forumManager.getTopicByIdWithAttachments(originalTopicId).getAttachments(); if (fromTopicAttach != null && !fromTopicAttach.isEmpty()) { @@ -7836,9 +7829,19 @@ private DiscussionForumBean duplicateForum(Long originalForumId) { String oldExtendedDescription = oldForum.getExtendedDescription(); if (oldExtendedDescription == null) oldExtendedDescription = ""; forum.setExtendedDescription(oldExtendedDescription); - forum.setTitle(oldTitle); + forum.setTitle(oldTitle); + + Set fromForumMembershipItems = uiPermissionsManager.getForumItemsSet(oldForum); + if (fromForumMembershipItems != null) { + for (DBMembershipItem fromForumMembershipItem : fromForumMembershipItems) { + DBMembershipItem membershipItemCopy = getMembershipItemCopy(fromForumMembershipItem); + DBMembershipItem savedMembershipItem = permissionLevelManager.saveDBMembershipItem(membershipItemCopy); + forum.addMembershipItem(savedMembershipItem); + ((DBMembershipItemImpl) savedMembershipItem).setForum(forum); + } + } - List fromForumAttach = oldForum.getAttachments(); + List fromForumAttach = oldForum.getAttachments(); if (fromForumAttach != null && !fromForumAttach.isEmpty()) { for (int topicAttach=0; topicAttach < fromForumAttach.size(); topicAttach++) { Attachment thisAttach = (Attachment)fromForumAttach.get(topicAttach);