MODX Community

FRED - only edit by the user who created the resource

Hi guys,

Is it possible to have FRED installed and only logged in users who created the resource, can edit it?

Basicly, users can create pages and they can only edit their own page and not pages others created.

I made something similar with formit2resource before, but cant seem to find out how to check ‘if loggedin user = createdby’ with FRED.

Any thoughts?

Could create a plugin that hooks into FredBeforeRender that grabs the ID of the logged in user and compares it to the edited by ID.

Thanks for your reply, writing this is a bit tricky for me, i hope i’m on the right path here.

So far i got a plugin ‘FredLoadCheck’ with FredBeforeRender checked, and this code:

//get current resource id and createdby id
$id = $modx->resource->get('id');
$page = $modx->getObject('modResource', $id);
$createdby = $page->get('createdby');

//get current logged in user id
$userid = $modx->user->get('id');

// check if createdby = userid
if ($createdby == $userid){return "true";}else{ return "false";}

I first tried this code as a snippet and that works.

Now how can i ‘Load’ / ‘Not Load’ - Fred?

Ok, not sure if this is the right way to do this, but I got it to work.

I added my If/then after the case ‘OnWebPagePrerender’: inside the Fred Plugin code.
And it seems to work so far.

Be aware, this will get replaced on an ugrade of Fred.
You should rather create your own plugin.

Ty Bruno, i thought of that too.

I tried to follow inside-creative’s approach by creating my own plugin with FredBeforeRender, but then i dont know how to Load or Not Load Fred inside that plugin.

Or maybe i’m thinking wrong?