Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,22 @@ private String saveTopicSettings(boolean draft)
if(selectedForum.getForum().getRestrictPermissionsForGroups() && ServerConfigurationService.getBoolean("msgcntr.restricted.group.perms", false)){
topic.setRestrictPermissionsForGroups(true);
}

if (!isNew
&& Boolean.TRUE.equals(topic.getAvailabilityRestricted())
&& Boolean.TRUE.equals(topic.getLockedAfterClosed())
&& Boolean.TRUE.equals(topic.getLocked())) {
DiscussionTopic persistedTopic = forumManager.getTopicById(topic.getId());
Date persistedCloseDate = persistedTopic != null ? persistedTopic.getCloseDate() : null;
Date closeDate = topic.getCloseDate();
if (persistedCloseDate != null
&& persistedCloseDate.before(new Date())
&& closeDate != null
&& closeDate.after(new Date())) {
topic.setLocked(false);
selectedTopic.setTopicLocked(false);
}
}
if(topic.getCreatedBy()==null&&this.forumManager.getAnonRole()==true){
topic.setCreatedBy(".anon");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,7 @@ public void setLocked(String locked)
public Boolean getForumLocked()
{
log.debug("getForumLocked()");
if (locked == null || "".equals(locked)){
if (forum == null || forum.getLocked() == null
|| forum.getLocked().booleanValue() == false)
{
locked = Boolean.FALSE.toString();
}
else
{
locked = Boolean.TRUE.toString();
}
}

handleLockedAfterClosedCondition();

return Boolean.parseBoolean(locked);
return forum != null && forum.getLocked() != null && forum.getLocked();
}

/**
Expand All @@ -203,17 +189,16 @@ public void setForumLocked(Boolean locked)
{
log.debug("setForumLocked(String"+ locked+")");
forum.setLocked(locked);
this.locked = String.valueOf(Boolean.TRUE.equals(locked));
}

private void handleLockedAfterClosedCondition() {
Boolean availabilityRestricted = getForum().getAvailabilityRestricted();

if(availabilityRestricted && locked.equals(Boolean.FALSE.toString())) {
if (Boolean.TRUE.equals(availabilityRestricted) && Boolean.FALSE.toString().equals(locked)) {
Date closeDate = getForum().getCloseDate();
if(closeDate != null) {
// this seems so dirty.
if (getForum().getLockedAfterClosed() && closeDate.before(new Date())) {
setForumLocked(true);
if (Boolean.TRUE.equals(getForum().getLockedAfterClosed()) && closeDate.before(new Date())) {
locked = Boolean.TRUE.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,20 +385,7 @@ public void setLocked(String locked)
public Boolean getTopicLocked()
{
log.debug("getTopicLocked()");
if (StringUtils.isBlank(locked)){
if (topic == null || topic.getLocked() == null || !topic.getLocked())
{
locked = Boolean.FALSE.toString();
}
else
{
locked = Boolean.TRUE.toString();
}
}

handleLockedAfterClosedCondition();

return Boolean.parseBoolean(locked);
return topic != null && topic.getLocked() != null && topic.getLocked();
}

/**
Expand All @@ -408,15 +395,15 @@ public void setTopicLocked(Boolean locked)
{
log.debug("setTopicLocked(Boolean {})", locked);
topic.setLocked(locked);
this.locked = String.valueOf(Boolean.TRUE.equals(locked));
}

private void handleLockedAfterClosedCondition(){
Boolean availabilityRestricted = getTopic().getAvailabilityRestricted();

if(availabilityRestricted && locked.equals(Boolean.FALSE.toString())) {
if (Boolean.TRUE.equals(availabilityRestricted) && Boolean.FALSE.toString().equals(locked)) {
Date closeDate = getTopic().getCloseDate();
if (closeDate != null && getTopic().getLockedAfterClosed() && closeDate.before(new Date())) {
setTopicLocked(true);
if (closeDate != null && Boolean.TRUE.equals(getTopic().getLockedAfterClosed()) && closeDate.before(new Date())) {
locked = Boolean.TRUE.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<h:outputText styleClass="highlight title" id="draft" value="#{msgs.cdfm_draft}" rendered="#{ForumTool.selectedForum.forum.draft == 'true'}"/>
<h:outputText id="draft_space" value=" - " rendered="#{ForumTool.selectedForum.forum.draft == 'true'}" styleClass="title"/>
<h:outputText styleClass="bi bi-calendar-x" rendered="#{ForumTool.selectedForum.forum.availability == 'false'}" style="margin-right:.5em"/>
<h:outputText styleClass="bi bi-lock-fill" rendered="#{ForumTool.selectedForum.forum.locked == 'true'}" style="margin-right:.5em"/>
<h:outputText styleClass="bi bi-lock-fill" rendered="#{ForumTool.selectedForum.locked == 'true'}" style="margin-right:.5em"/>
<%-- Rubrics marker --%>
<h:panelGroup rendered="#{ForumTool.selectedForum.hasRubric == 'true'}">
<sakai-rubric-student-preview-button
Expand Down Expand Up @@ -130,7 +130,7 @@
<h:outputText styleClass="highlight title" id="draft" value="#{msgs.cdfm_draft}" rendered="#{topic.topic.draft == 'true'}"/>
<h:outputText id="draft_space" value=" - " rendered="#{topic.topic.draft == 'true'}" styleClass="title"/>
<h:outputText styleClass="bi bi-calendar-x" title="#{msgs.topic_restricted_message}" style="margin-right:.5em" rendered="#{topic.availability == 'false'}" escape="false" />
<h:outputText styleClass="bi bi-lock-fill" title="#{msgs.cdfm_forum_locked}" style="margin-right:.5em" rendered="#{ForumTool.selectedForum.forum.locked == 'true' || topic.locked == 'true'}" escape="false" />
<h:outputText styleClass="bi bi-lock-fill" title="#{msgs.cdfm_forum_locked}" style="margin-right:.5em" rendered="#{ForumTool.selectedForum.locked == 'true' || topic.locked == 'true'}" escape="false" />
<%-- Rubrics marker --%>
<h:panelGroup rendered="#{topic.hasRubric == 'true'}">
<sakai-rubric-student-preview-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
<span class="bi bi-calendar-x" aria-hidden="true" style="margin-right:.5em"></span>
<h:outputText value="#{msgs.topic_restricted_message}" />
</h:panelGroup>
<h:panelGroup rendered="#{ForumTool.selectedForum.forum.locked == 'true' || ForumTool.selectedTopic.topic.locked == 'true'}">
<h:panelGroup rendered="#{ForumTool.selectedForum.locked == 'true' || ForumTool.selectedTopic.locked == 'true'}">
<span class="bi bi-lock-fill" aria-hidden="true" style="margin-right:.5em"></span>
</h:panelGroup>
<%-- Rubrics marker --%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<div class="topicBloc" style="padding:0 .5em"><h:messages styleClass="sak-banner-warn" id="errorMessages" rendered="#{! empty facesContext.maximumSeverity}" />
<p>
<span class="title">
<h:panelGroup rendered="#{ForumTool.selectedTopic.topic.locked=='true'}">
<h:panelGroup rendered="#{ForumTool.selectedTopic.locked=='true'}">
<span class="bi bi-lock-fill" aria-hidden="true" style="margin-right:.3em"></span>
</h:panelGroup>
<h:panelGroup rendered="#{ForumTool.selectedTopic.topic.locked=='false'}">
<h:panelGroup rendered="#{ForumTool.selectedTopic.locked=='false'}">
<span class="bi bi-unlock-fill" aria-hidden="true" style="margin-right:.3em"></span>
</h:panelGroup>
<h:outputText value="#{ForumTool.selectedTopic.topic.title}" rendered="#{!ForumTool.selectedTopic.markForDuplication}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import org.sakaiproject.api.app.messageforums.MessageForumsMessageManager;
import org.sakaiproject.api.app.messageforums.MessageForumsTypeManager;
import org.sakaiproject.api.app.messageforums.MessageMoveHistory;
import org.sakaiproject.api.app.messageforums.OpenForum;
import org.sakaiproject.api.app.messageforums.OpenTopic;
import org.sakaiproject.api.app.messageforums.PrivateMessage;
import org.sakaiproject.api.app.messageforums.SynopticMsgcntrManager;
import org.sakaiproject.api.app.messageforums.Topic;
Expand All @@ -63,6 +65,8 @@
import org.sakaiproject.component.app.messageforums.dao.hibernate.AttachmentImpl;
import org.sakaiproject.component.app.messageforums.dao.hibernate.MessageImpl;
import org.sakaiproject.component.app.messageforums.dao.hibernate.MessageMoveHistoryImpl;
import org.sakaiproject.component.app.messageforums.dao.hibernate.OpenForumImpl;
import org.sakaiproject.component.app.messageforums.dao.hibernate.OpenTopicImpl;
import org.sakaiproject.component.app.messageforums.dao.hibernate.PrivateMessageImpl;
import org.sakaiproject.component.app.messageforums.dao.hibernate.UnreadStatusImpl;
import org.sakaiproject.component.app.messageforums.dao.hibernate.Util;
Expand Down Expand Up @@ -1757,19 +1761,33 @@ private boolean isForumOrTopicLocked(final Long forumId, final Long topicId) {

log.debug("isForumLocked executing with forumId: " + forumId + ":: topicId: " + topicId);

final Date now = new Date();

HibernateCallback<Boolean> hcb = session -> {
Query q = session.getNamedQuery("findForumLockedAttribute");
q.setParameter("id", forumId, LongType.INSTANCE);
return (Boolean) q.uniqueResult();
OpenForumImpl forum = session.get(OpenForumImpl.class, forumId);
OpenTopicImpl topic = session.get(OpenTopicImpl.class, topicId);
return isLocked(forum, now) || isLocked(topic, now);
};

HibernateCallback<Boolean> hcb2 = session -> {
Query q = session.getNamedQuery("findTopicLockedAttribute");
q.setParameter("id", topicId, LongType.INSTANCE);
return (Boolean) q.uniqueResult();
};

return getHibernateTemplate().execute(hcb) || getHibernateTemplate().execute(hcb2);
return getHibernateTemplate().execute(hcb);
}

private boolean isLocked(OpenForum forum, Date now) {
if (forum == null) return true;
if (Boolean.TRUE.equals(forum.getLocked())) return true;
if (!Boolean.TRUE.equals(forum.getAvailabilityRestricted())) return false;
if (!Boolean.TRUE.equals(forum.getLockedAfterClosed())) return false;
Date closeDate = forum.getCloseDate();
return closeDate != null && closeDate.before(now);
}

private boolean isLocked(OpenTopic topic, Date now) {
if (topic == null) return true;
if (Boolean.TRUE.equals(topic.getLocked())) return true;
if (!Boolean.TRUE.equals(topic.getAvailabilityRestricted())) return false;
if (!Boolean.TRUE.equals(topic.getLockedAfterClosed())) return false;
Date closeDate = topic.getCloseDate();
return closeDate != null && closeDate.before(now);
}

// helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -161,9 +162,9 @@ public boolean isNewResponse(DiscussionTopic topic, DiscussionForum forum, Strin

if (forum != null
&& !forum.getDraft()
&& !forum.getLocked()
&& !isLocked(forum)
&& !topic.getDraft()
&& !topic.getLocked()) {
&& !isLocked(topic)) {
return getTopicItemsByUser(topic, userId, contextId).stream().anyMatch(ifNewResponse);
}
return false;
Expand All @@ -180,9 +181,9 @@ public boolean isNewResponseToResponse(DiscussionTopic topic, DiscussionForum fo

if (forum != null
&& !forum.getDraft()
&& !forum.getLocked()
&& !isLocked(forum)
&& !topic.getDraft()
&& !topic.getLocked()) {
&& !isLocked(topic)) {
return getTopicItemsByUser(topic, userId, contextId).stream().anyMatch(ifNewResponseToResponse);
}
return false;
Expand All @@ -194,9 +195,9 @@ public boolean isMovePostings(DiscussionTopic topic, DiscussionForum forum) {

if (forum != null
&& !forum.getDraft()
&& !forum.getLocked()
&& !isLocked(forum)
&& !topic.getDraft()
&& !topic.getLocked()) {
&& !isLocked(topic)) {

return getTopicItemsByCurrentUser(topic).stream().anyMatch(ifMovePosting.or(ifReviseAny).or(ifReviseOwn));
}
Expand Down Expand Up @@ -292,9 +293,9 @@ public boolean isReviseAny(DiscussionTopic topic, DiscussionForum forum, String
if (checkBaseConditions(topic, forum, userId, contextId)) return true;

return (forum.getDraft() == null || !forum.getDraft())
&& (forum.getLocked() == null || !forum.getLocked())
&& !isLocked(forum)
&& (topic.getDraft() == null || !topic.getDraft())
&& (topic.getLocked() == null || !topic.getLocked())
&& !isLocked(topic)
&& getTopicItemsByUser(topic, userId, contextId).stream().anyMatch(ifReviseAny);
}

Expand All @@ -307,12 +308,12 @@ public boolean isReviseOwn(DiscussionTopic topic, DiscussionForum forum) {
public boolean isReviseOwn(DiscussionTopic topic, DiscussionForum forum, String userId, String contextId) {
if (checkBaseConditions(topic, forum, userId, contextId)) return true;

if (topic.getLocked() == null || topic.getLocked()) return false;
if (isLocked(topic)) return false;

if (!forum.getDraft()
&& !forum.getLocked()
&& !isLocked(forum)
&& !topic.getDraft()
&& !topic.getLocked()) {
&& !isLocked(topic)) {
return getTopicItemsByUser(topic, userId, contextId).stream().anyMatch(ifReviseOwn);
}
return false;
Expand All @@ -327,12 +328,12 @@ public boolean isDeleteAny(DiscussionTopic topic, DiscussionForum forum) {
public boolean isDeleteAny(DiscussionTopic topic, DiscussionForum forum, String userId, String contextId) {
if (checkBaseConditions(topic, forum, userId, contextId)) return true;

if (topic.getLocked() == null || topic.getLocked()) return false;
if (isLocked(topic)) return false;

if (!forum.getDraft()
&& !forum.getLocked()
&& !isLocked(forum)
&& !topic.getDraft()
&& !topic.getLocked()) {
&& !isLocked(topic)) {
return getTopicItemsByUser(topic, userId, contextId).stream().anyMatch(ifDeleteAny);
}
return false;
Expand All @@ -347,12 +348,12 @@ public boolean isDeleteOwn(DiscussionTopic topic, DiscussionForum forum) {
public boolean isDeleteOwn(DiscussionTopic topic, DiscussionForum forum, String userId, String contextId) {
if (checkBaseConditions(topic, forum, userId, contextId)) return true;

if (topic.getLocked() == null || topic.getLocked().equals(Boolean.TRUE)) return false;
if (isLocked(topic)) return false;

if (!forum.getDraft()
&& !forum.getLocked()
&& !isLocked(forum)
&& !topic.getDraft()
&& !topic.getLocked()) {
&& !isLocked(topic)) {
return getTopicItemsByUser(topic, userId, contextId).stream().anyMatch(ifDeleteOwn);
}
return false;
Expand All @@ -362,12 +363,12 @@ public boolean isDeleteOwn(DiscussionTopic topic, DiscussionForum forum, String
public boolean isMarkAsRead(DiscussionTopic topic, DiscussionForum forum) {
if (checkBaseConditions(topic, forum)) return true;

if (topic.getLocked() == null || topic.getLocked().equals(Boolean.TRUE)) return false;
if (isLocked(topic)) return false;

if (!forum.getDraft()
&& !forum.getLocked()
&& !isLocked(forum)
&& !topic.getDraft()
&& !topic.getLocked()) {
&& !isLocked(topic)) {
return getTopicItemsByCurrentUser(topic).stream().anyMatch(ifMarkAsRead);
}
return false;
Expand Down Expand Up @@ -581,8 +582,8 @@ public BulkPermission getBulkPermissions(DiscussionTopic topic, DiscussionForum
}

boolean ifTopicOwner = topic != null && forumManager.isTopicOwner(topic, userId);
boolean ifLockedTopic = topic != null && (topic.getLocked() == null || topic.getLocked());
boolean ifLockedForum = forum != null && (forum.getLocked() == null || forum.getLocked());
boolean ifLockedTopic = isLocked(topic);
boolean ifLockedForum = isLocked(forum);
boolean ifDraftTopic = topic != null && (topic.getDraft() != null && topic.getDraft());
boolean ifDraftForum = forum != null && (forum.getDraft() != null && forum.getDraft());

Expand Down Expand Up @@ -692,6 +693,34 @@ private boolean checkBaseConditions(DiscussionTopic topic, DiscussionForum forum
|| (topic != null && topic.getRestrictPermissionsForGroups() && isInstructorForAllowedGroup(topic.getId(), false, contextSiteId, userId));
}

private boolean isLockedAfterClose(DiscussionForum forum) {
if (forum == null) return false;
if (!Boolean.TRUE.equals(forum.getAvailabilityRestricted())) return false;
if (!Boolean.TRUE.equals(forum.getLockedAfterClosed())) return false;
Date closeDate = forum.getCloseDate();
return closeDate != null && closeDate.before(new Date());
}

private boolean isLockedAfterClose(DiscussionTopic topic) {
if (topic == null) return false;
if (!Boolean.TRUE.equals(topic.getAvailabilityRestricted())) return false;
if (!Boolean.TRUE.equals(topic.getLockedAfterClosed())) return false;
Date closeDate = topic.getCloseDate();
return closeDate != null && closeDate.before(new Date());
}

private boolean isLocked(DiscussionForum forum) {
if (forum == null) return true;
if (Boolean.TRUE.equals(forum.getLocked())) return true;
return isLockedAfterClose(forum);
}

private boolean isLocked(DiscussionTopic topic) {
if (topic == null) return true;
if (Boolean.TRUE.equals(topic.getLocked())) return true;
return isLockedAfterClose(topic);
}

public void clearMembershipsFromCacheForArea(Area area) {
if (area == null || area.getId() == null) return;
String areaId = area.getId().toString();
Expand Down
Loading