Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### Behaviour changes worth reading before upgrading

- **Templates see only published entries when they look one up by anchor.**
`$weblog.getWeblogEntry(anchor)` in a custom template, and the same call on
a weblog reached through `$site`, now returns null for draft, pending and
scheduled entries.
- **Only global admins manage Admin on the aggregated front-page weblog.**
With `site.frontpage.weblog.aggregated=true`, that weblog's templates can
read the whole site, so granting, removing or inviting an Admin there now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.stream.Collectors;
import org.apache.roller.weblogger.pojos.ThemeTemplate.ComponentType;
import org.apache.roller.weblogger.pojos.Weblog;
import org.apache.roller.weblogger.pojos.WeblogEntry;


/**
Expand Down Expand Up @@ -273,8 +274,16 @@ public String getAbsoluteURL() {
}


/**
* The published entry with this anchor, or null. Templates never see
* draft, pending or scheduled entries through this lookup.
*/
public WeblogEntryWrapper getWeblogEntry(String anchor) {
return WeblogEntryWrapper.wrap(this.pojo.getWeblogEntry(anchor), urlStrategy);
WeblogEntry entry = this.pojo.getWeblogEntry(anchor);
if (entry == null || !entry.isPublished()) {
return null;
}
return WeblogEntryWrapper.wrap(entry, urlStrategy);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. The ASF licenses this file to You
* under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. For additional information regarding
* copyright in this work, please see the NOTICE file in the top level
* directory of this distribution.
*/

package org.apache.roller.weblogger.pojos.wrapper;

import org.apache.roller.weblogger.pojos.Weblog;
import org.apache.roller.weblogger.pojos.WeblogEntry;
import org.apache.roller.weblogger.pojos.WeblogEntry.PubStatus;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* Templates look up entries by anchor through the weblog wrapper. Only
* published entries come back.
*/
public class WeblogWrapperEntryLookupTest {

private static WeblogWrapper weblogWithEntry(PubStatus status) {
WeblogEntry entry = new WeblogEntry();
entry.setAnchor("the-anchor");
entry.setStatus(status);
Weblog weblog = mock(Weblog.class);
when(weblog.getWeblogEntry("the-anchor")).thenReturn(entry);
return WeblogWrapper.wrap(weblog, null);
}

@Test
public void publishedEntryIsReturned() {
WeblogEntryWrapper found = weblogWithEntry(PubStatus.PUBLISHED).getWeblogEntry("the-anchor");
assertNotNull(found);
assertEquals("the-anchor", found.getAnchor());
}

@Test
public void unpublishedEntriesAreNotReturned() {
for (PubStatus status : new PubStatus[] {PubStatus.DRAFT, PubStatus.PENDING, PubStatus.SCHEDULED}) {
assertNull(weblogWithEntry(status).getWeblogEntry("the-anchor"), status.name());
}
}

@Test
public void missingEntryIsNull() {
assertNull(weblogWithEntry(PubStatus.PUBLISHED).getWeblogEntry("other"));
}
}
Loading