You are here: Foswiki>Tasks Web>Item13889 (08 Feb 2016, GeorgeClark)Edit Attach

Item13889: Processing of dynamically generated META in a new topic template is displayed as plain text until saved.

pencil
Priority: Normal
Current State: Closed
Released In: 2.1.0
Target Release: minor
Applies To: Engine
Component: FoswikiUIEdit
Branches: master Release02x00
Reported By: VadimBelman
Waiting For:
Last Change By: GeorgeClark
When creating a new topic I would expect a META generated within %STARTSECTION{type="expandvariables"}% to be processed by the edit script and used in the process of topic creation.

For example, for the following template I would expect the Permissions tab 'Users who may edit' section to be set to groups where current user belongs:

%STARTSECTION{type="expandvariables"}%
%USERINFO{format="$percentMETA:PREFERENCE{name=$quotALLOWTOPICCHANGE$quot title=$quotALLOWTOPICCHANGE$quot type=$quotSet$quot value=$quot$groups$quot}$percent$n()$percentMETA:PREFERENCE{name=$quotPERMSET_CHANGE$quot title=$quotPERMSET_CHANGE$quot type=$quotLocal$quot value=$quotdetails$quot}$percent$n$percentMETA:PREFERENCE{name=$quotPERMSET_CHANGE_DETAILS$quot title=$quotPERMSET_CHANGE_DETAILS$quot type=$quotLocal$quot value=$quot$groups$quot}$percent$n"}%
%ENDSECTION{type="expandvariables"}%

But in fact the META generated by this code simply makes it into the edit box of a newly created topic as is. I.e. it's not being parsed and is visible to the user in clear text with no impact on the Preferences tab.

The issue is not limited to the permissions only but also makes it impossible to dynamically set data form fields, for instances, in cases where passing form fields as URL parameters might be considered unacceptable. There might be other reasons to generate field values or any other META data inside the template.

-- VadimBelman - 08 Dec 2015

The issue is that META statements appearing in the topic text are processed when the topic is deserialised on initial read, and are not processed again until the topic is saved and read. So the embedded META in the template is ignored in the "first pass" and becomes active after save.

Fix is simple. After the template is expanded and all the meta applied, serialise and de-serialise the object to re-process any embedded meta.

diff --git a/core/lib/Foswiki/UI/Edit.pm b/core/lib/Foswiki/UI/Edit.pm
index 8e15e25..7646df9 100644
--- a/core/lib/Foswiki/UI/Edit.pm
+++ b/core/lib/Foswiki/UI/Edit.pm
@@ -318,6 +318,12 @@ sub init_edit {
         }
     }
 
+    # The template might contain embedded META data,  so serialize it
+    # and deserialize it to pick up the embedded meta.
+    Foswiki::Serialise::deserialise(
+        Foswiki::Serialise::serialise( $topicObject, 'Embedded' ),
+        'Embedded', $topicObject );
+
     $tmpl =~ s/%TEMPLATETOPIC%/$templateTopic/;
     $tmpl =~ s/%REDIRECTTO%/$redirectTo/;
 

-- GeorgeClark - 08 Dec 2015

Crawford, Could you review this. I think it's pretty safe, it's only doing what would happen in the round-trip through save.

-- GeorgeClark - 08 Dec 2015

Got a review on IRC. Checked into 2.0 & master. Waiting for release.

-- GeorgeClark - 09 Dec 2015
 

ItemTemplate edit

Summary Processing of dynamically generated META in a new topic template is displayed as plain text until saved.
ReportedBy VadimBelman
Codebase 2.0.3, trunk
SVN Range
AppliesTo Engine
Component FoswikiUIEdit
Priority Normal
CurrentState Closed
WaitingFor
Checkins distro:f989708e76dd distro:f3ee3f6c4cca
TargetRelease minor
ReleasedIn 2.1.0
CheckinsOnBranches master Release02x00
trunkCheckins
masterCheckins distro:f989708e76dd
ItemBranchCheckins
Release02x00Checkins distro:f3ee3f6c4cca
Release01x01Checkins
Topic revision: r5 - 08 Feb 2016, GeorgeClark - This page was cached on 18 Nov 2017 - 17:37.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License