Skip to content

Commit dfb1cde

Browse files
committed
XWIKI-19906: Render the AppWithinMinutes Content field as its author
1 parent bff69d1 commit dfb1cde

File tree

2 files changed

+41
-15
lines changed
  • xwiki-platform-core/xwiki-platform-appwithinminutes
    • xwiki-platform-appwithinminutes-test/xwiki-platform-appwithinminutes-test-docker/src/test/it/org/xwiki/appwithinminutes/test/ui
    • xwiki-platform-appwithinminutes-ui/src/main/resources/AppWithinMinutes

2 files changed

+41
-15
lines changed

xwiki-platform-core/xwiki-platform-appwithinminutes/xwiki-platform-appwithinminutes-test/xwiki-platform-appwithinminutes-test-docker/src/test/it/org/xwiki/appwithinminutes/test/ui/DocumentFieldsIT.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.apache.commons.lang3.RandomStringUtils;
2525
import org.junit.jupiter.api.BeforeAll;
26+
import org.junit.jupiter.api.Order;
2627
import org.junit.jupiter.api.Test;
2728
import org.xwiki.appwithinminutes.test.po.ApplicationClassEditPage;
2829
import org.xwiki.appwithinminutes.test.po.ApplicationCreatePage;
@@ -51,14 +52,15 @@
5152
* @since 13.10RC1
5253
*/
5354
@UITest(properties = {
54-
// Exclude the AppWithinMinutes.ClassEditSheet and AppWithinMinutes.DynamicMessageTool from the PR checker since
55+
// Exclude the AppWithinMinutes.ClassEditSheet and AppWithinMinutes.DynamicMessageTool from the PR checker since
5556
// they use the groovy macro which requires PR rights.
5657
// TODO: Should be removed once XWIKI-20529 is closed.
5758
// Exclude AppWithinMinutes.LiveTableEditSheet because it calls com.xpn.xwiki.api.Document.saveWithProgrammingRights
58-
"xwikiPropertiesAdditionalProperties=test.prchecker.excludePattern=.*:AppWithinMinutes\\.(ClassEditSheet|DynamicMessageTool|LiveTableEditSheet)"
59-
})
59+
"xwikiPropertiesAdditionalProperties=test.prchecker.excludePattern=.*:AppWithinMinutes\\.(ClassEditSheet|DynamicMessageTool|LiveTableEditSheet)"})
6060
class DocumentFieldsIT
6161
{
62+
private String appName = RandomStringUtils.randomAlphabetic(6);
63+
6264
@BeforeAll
6365
static void beforeAll(TestUtils setup)
6466
{
@@ -73,14 +75,12 @@ static void beforeAll(TestUtils setup)
7375
}
7476

7577
@Test
78+
@Order(1)
7679
void titleAndContent(TestUtils setup)
7780
{
78-
setup.loginAsAdmin();
79-
8081
// Create a new application.
81-
String appName = RandomStringUtils.randomAlphabetic(6);
8282
ApplicationCreatePage appCreatePage = ApplicationCreatePage.gotoPage();
83-
appCreatePage.setApplicationName(appName);
83+
appCreatePage.setApplicationName(this.appName);
8484
ApplicationClassEditPage classEditPage = appCreatePage.clickNextStep();
8585

8686
// Add a standard field.
@@ -126,30 +126,53 @@ void titleAndContent(TestUtils setup)
126126
assertTrue(entryViewPage.getContent().contains("Bar"));
127127

128128
// Verify that we can edit the document fields in-place.
129-
String propertyReference = String.format("%s.Code.%1$sClass[0].title1", appName);
129+
String propertyReference = String.format("%s.Code.%1$sClass[0].title1", this.appName);
130130
EditablePropertyPane<String> titleProperty = new EditablePropertyPane<>(propertyReference);
131131
assertEquals("Foo", titleProperty.clickEdit().getValue());
132132
titleProperty.setValue("Book").clickSave();
133133
assertEquals("Book", titleProperty.getDisplayValue());
134134

135135
// Check the entries live table.
136-
entryViewPage.clickBreadcrumbLink(appName);
136+
entryViewPage.clickBreadcrumbLink(this.appName);
137137
LiveTableElement liveTable = new ApplicationHomePage().getEntriesLiveTable();
138138
liveTable.waitUntilReady();
139139
assertEquals(1, liveTable.getRowCount());
140140
assertTrue(liveTable.hasRow("My Title", "Book"));
141141
assertTrue(liveTable.hasRow("My Content", "Bar"));
142142

143143
// Check that the title and the content of the class have not been changed.
144-
setup.gotoPage(new LocalDocumentReference(Arrays.asList(appName, "Code"), appName + "Class"), "edit",
144+
setup.gotoPage(new LocalDocumentReference(Arrays.asList(this.appName, "Code"), this.appName + "Class"), "edit",
145145
"editor=wiki");
146146
WikiEditPage editPage = new WikiEditPage();
147-
assertEquals(appName + " Class", editPage.getTitle());
147+
assertEquals(this.appName + " Class", editPage.getTitle());
148148
assertEquals("", editPage.getContent());
149149

150150
// Now edit the class and check if the default values for title and content are taken from the template.
151151
editPage.edit();
152152
assertEquals(defaultTitle, new ClassFieldEditPane("title1").getDefaultValue());
153153
assertEquals(defaultContent, new ClassFieldEditPane("content1").getDefaultValue());
154154
}
155+
156+
@Test
157+
@Order(2)
158+
void contentFromSimpleUser(TestUtils setup)
159+
{
160+
// Create an application entry with a simple user that doesn't have script rights.
161+
setup.createUserAndLogin("Alice", "pass");
162+
163+
ApplicationHomePage appHomePage = ApplicationHomePage.gotoPage(this.appName);
164+
appHomePage.getEntriesLiveTable().waitUntilReady();
165+
166+
EntryNamePane entryNamePage = appHomePage.clickAddNewEntry();
167+
entryNamePage.setName("ByAlice");
168+
169+
EntryEditPage entryEditPage = entryNamePage.clickAdd();
170+
entryEditPage.setTitle("Title by $services.localization.render('Alice')");
171+
entryEditPage.setContent("Content by {{velocity}}$services.localization.render('Alice'){{/velocity}}");
172+
173+
ViewPage entryViewPage = entryEditPage.clickSaveAndView();
174+
assertEquals("Title by $services.localization.render('Alice')", entryViewPage.getDocumentTitle());
175+
assertTrue(entryViewPage.getContent().contains("Content by"));
176+
assertTrue(entryViewPage.getContent().contains("The execution of the [velocity] script macro is not allowed"));
177+
}
155178
}

xwiki-platform-core/xwiki-platform-appwithinminutes/xwiki-platform-appwithinminutes-ui/src/main/resources/AppWithinMinutes/Content.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
2121
-->
2222

23-
<xwikidoc version="1.2" reference="AppWithinMinutes.Content" locale="">
23+
<xwikidoc version="1.5" reference="AppWithinMinutes.Content" locale="">
2424
<web>AppWithinMinutes</web>
2525
<name>Content</name>
2626
<language/>
@@ -76,9 +76,12 @@
7676
#end
7777
{{/html}}
7878
#elseif ("$!type" != '')
79-
## Include the content of the current document.
80-
## Escape {{ in the rendered content to be sure that the HTML macro is not closed unintentionally.
81-
{{html}}$tdoc.getRenderedContent($tdoc.content, $tdoc.syntax.toIdString()).replace('{{', '&amp;amp;#123;&amp;amp;#123;'){{/html}}
79+
## Display the content of the current document without using any sheet. We can't use the include macro here (with the
80+
## author parameter) because the content may have unsaved changes (e.g. on preview action). We make sure that the HTML
81+
## macro is not closed unintentionally, even though the XHTML printer protects us against this, just to be extra safe.
82+
{{html}}$services.display.content($tdoc, {
83+
'displayerHint': 'default'
84+
}).replace('{{/html}}', '&amp;amp;#123;&amp;amp;#123;/html&amp;amp;#125;&amp;amp;#125;'){{/html}}
8285
#else
8386
The display mode is not specified!
8487
#end

0 commit comments

Comments
 (0)