Forums / Setup & design / User-Specific caching

User-Specific caching

Author Message

Marco Zinn

Saturday 21 May 2005 5:49:56 am

Hi,
I'm setting up a site, where users can create objects and are allowed to edit these "self-owner" objects. It's just the same as the forum here, i guess.
Issue: AFAIK, the content caching works based on the role combination. That won't help me, as all users share the some policy set.
So, by ez's default, all users can see the "edit"-button for all user-created objects, no matter, if they own it or not. They can't actuelly edit the content, but i want to hide the edit button, if they can't edit the object anyway.
I'm using a section checking for "object.can_edit" in line and full views.

Of course, i have a caching issue here: If the first user visiting the page CAN edit the content, i'll have that button in the cached content file, and others users (with the same roles) will see that button!

What's the right way to do user-specific content caching. I'm NOT talking about pagelayout; in pagelayout, i can use cache-blocks with user-id-specific key. But how to do this in the "content area"?

Marco
http://www.hyperroad-design.com

Paul Borgermans

Saturday 21 May 2005 2:40:43 pm

Hi Marco,

1) You need to fetch the current user in the content {$module.result} related templates and use that to setup a cache block key

or

2) disable caching for that template.

But

3) I don't have that problem in my sites (all on 3.4.x though), so maybe you stumbled upon a bug. Can you provide more details (what policies are enabled and post the section statements where you check for $object.can_edit)

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Marco Zinn

Sunday 22 May 2005 10:58:54 am

Hi,
Hm. I'm talking about "node view full" and "node view line" templates, not the pagelayout.tpl.
I thought, i cannot create cache-block within content templates?, so i didn't get your 1) .
Currently, i use 2) ;)

So, these are the most important policy parts:

content  	 create  	 Node( Mitglieder ) , Class( Character ) , Section( Standard )
content 	edit 	Owner( Self )

This should allow users to create objects of the "Character" class as children of the (Folder) Node "Mitglieder". This works fine.
The second line should allow the users to edit "his own" objects ("character" objects or others).

Templates:
For the "Mitglieder" Node, there is an full view override.
Most important part:

<table>
<tr halign="top">
{section name=Child loop=$children sequence=array(bglight,bgdark)}
<td>
{node_view_gui view=line content_node=$Child:item}
</td>
{delimiter modulo=3}
</tr><tr>
{/delimiter}
{/section}
</tr>
</table>

As you see, i call the line template.

In that line template, used this code

{section show=$node.object.can_edit} (Daten bearbeiten: <a href={concat("content/edit/",$node.contentobject_id)|ezurl}><img src={"edit.gif"|ezimage} alt="Bearbeiten" /></a>){/section}

As this didn't work (the Edit-Button appeared for objects, which the current user was not allowed to edit), i moved this code into the full-view-template and disabled caching for this full view template with

{set-block scope=root variable=cache_ttl}0{/set-block}

Marco
http://www.hyperroad-design.com