We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19388
    • 297 Posts
    Hi,
    Maybe this question has been answered before but I can’t find the answer sad
    I have a "member zone", wich is a resource wich contains many childrens
    - member zone
    --- news
    ------ article 1
    ------ article 2
    --- member list
    ---pictures

    I added "member zone" to the resource group, but the permissions only affect to this document (member zone) and not to the children. Is there any way to it? As "inherit" in TVs or simmilar... Same for news, If an article is created it shold get the parent permissions automatically...
    Is that possible? I’m sure that it’s possible and i’m doing something wrong
    Best regards,
    Miguel
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Think of the childrens!

      That’s a good point, Miguel... I think the permissions are not inherited. I wrote a script that would copy a folder and update permissions on each child document in the folder. This is kinda heady stuff, and I simplified it a lot so I could post it here, but it should at least give you an idea of which API functions you need to research:
      <?php
      	private function _duplicate($args)
      	{
      		// Load up the master doc (e.g. a folder) to be copied
      	    $masterdoc = $modx->getObject('modResource', 123);
      		
      		// This will actually CREATE the doc. 
      		$new_doc = $masterdoc->duplicate();
      		
      		if ( !is_object($new_doc) )
      		{
      			die('There was a problem duplicating the resource.');
      		}
      		
      		$homepage_id = $new_doc->get('id');
      		
      		// Special handling for the homepage
      
      		$new_doc->set('pagetitle', 'Some name' );
      	    $new_doc->set('menutitle', 'Some menu title' );
      	    $new_doc->set('alias', urlify('my-alias') );
      	    $new_doc->set('published', 1); // 0 || 1
      
      	    $new_doc->save();
      	    
      		// add resource group  (class var used in another function)
      		$this->userResourceGroup = $modx->getObject('modResourceGroup', array('name'=> 'Name of my Resource Group') );	    
      	    // add user group
      	    $userUserGroup = $modx->getObject('modUserGroup', array('name'=> 'Name of my User Group' )
      	
      	    //add resource group access
      	    $resourceGroupAccess = $modx->newObject('modAccessResourceGroup');
      	    $resourceGroupAccess->set('target', $this->userResourceGroup->get('id'));
      	    $resourceGroupAccess->set('principal_class', 'modUserGroup');
      	    $resourceGroupAccess->set('principal', $userUserGroup->get('id'));
      	    $resourceGroupAccess->set('authority', 9999); 
      	    $resourceGroupAccess->set('policy', 4 ); // 4 for Load, List and View
      	    $resourceGroupAccess->set('context_key', 'web');
      	    $resourceGroupAccess->save();
      	    
      
      		// Process the children
      		$this->_process_children_resources($new_doc);
      	 	
      	}
      	
      	/*------------------------------------------------------------------------------
      	INPUT: MODx resource object, loops in on itself
      	------------------------------------------------------------------------------*/
      	private function _process_children_resources($resource)
      	{
      	    $children = $resource->getMany('Children');
      		foreach ($children as $child) {
      			
      			$child->set('published', 1);	// Children docs published by default
      			$child->save();
      			
      			$this->_join_resource_groups($child);
      			// down the rabit hole
      			$this->_process_children_resources($child);
      		}	
      	}
      
      	/*------------------------------------------------------------------------------
      	Removes a $doc from any resource groups it currently is in, then adds it to
      	the whatever group was defined/created above via $this->userResourceGroup
      	------------------------------------------------------------------------------*/
      	private function _join_resource_groups($doc)
      	{
      		// Clear all existing access permissions
      		$existing_resourceGroupResource = $modx->getCollection('modResourceGroupResource', array('document'=>$doc->get('id') ) );
      		if ($existing_resourceGroupResource)
      		{
      			foreach ($existing_resourceGroupResource as $r)
      			{
      				$r->remove();
      			}		
      		}
      		//add resource to resource group
      		$resourceGroupResource = $modx->newObject('modResourceGroupResource');
      		$resourceGroupResource->set('document', $doc->get('id'));
      		$resourceGroupResource->set('document_group', $this->userResourceGroup->get('id'));
      		$resourceGroupResource->save();
      	}	
      

        • 19388
        • 297 Posts
        Thank you so much! I’ll take a look. But I think MODX team should start thinking in inheritance, not only for permissions but for other stuff too.
        For example, in Typo3 everthing is inhereted. If you set a value on a parent, all childrens has this value too. This is specially usefull por permissions. I’ll send it as a suggestion but I’d like to know the opinion of the dev team.
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          I agree with you completely. I have filed one or two features/bugs related to this specifically, so I think they’re aware of it. MODx’s architecture is built really well, so it’s possible to configure it or tweak it to get the behavior you want.

          Two hugely helpful links:
          http://modxcms.com/forums/index.php/topic,60343.msg343213.html
          http://modxcms.com/forums/index.php/topic,58224.msg332574.html
            • 19388
            • 297 Posts
            Improvement posted here: http://bugs.modx.com/issues/4424