Hello guys,
I am working on some kind of difficult workflow. So far everything is working except for one little tiny piece. But no matter what I try or do, I can't figure it out. Here it is:
I am using the modActiveDirectory plugin to authenticate my users against ldap. Besides that I am running another custom plugin that adds the new user to a certain user group, creates resource groups etc. and finally creating a unique resource for this particular user. This custom plugin is fired OnUserFormSave and is working without any problems when creating the user directly in the MODx backend. Of course when using the modActiveDirectory plugin for creating new users the OnUserFormSave event is not being fired and my custom plugin doesn't do anything. So what I did to bypass this problem, I added the following line to the modActiveDirectory plugin to invoke this event manually:
$modx->invokeEvent('OnUserFormSave', array(
'mode'=>'new',
'id'=>$user->get('id')
));
All steps from my custom plugin (create new user group, resource group, join the new user to these groups) are working except for the creation of a resource. I always receive the error message:
[2015-08-06 09:54:06] (ERROR @ /manager/index.php) Permission denied!
Here's the code excerpt for creating the resource:
/* Create corresponding resource */
$fields['createdby'] = 1;
$fields['parent'] = $parentId;
$fields['template'] = $templateId;
$fields['pagetitle'] = $title;
$fields['published'] = 1;
$response = $modx->runProcessor('resource/create', $fields);
if ($response->isError()) {
$modx->log(xPDO::LOG_LEVEL_ERROR,'Error Message: '.$response->getMessage());
return;
}
Now my question: Why is the resource creation working when the OnUserFormSave is fired natively and why is it
not working when I fire the event manually within the modActiveDirectory plugin? Any ideas?
Thanks in advance!