Author
|
Message
|
Clemens T
|
Tuesday 24 May 2005 1:38:27 am
Hey all, 1 - Is it possible for me to programmatically create a section and add a folder to it? 2 - I have a bunch of roles, a few users and a couple of sections. Now I want to be able to assign a role to a user and limit him to a section programmatically. Anyone on this one?
Thank you for your time,
Greets, Clemens
|
kracker (the)
|
Tuesday 24 May 2005 2:00:20 am
All good ideas.. You have just switched around the hierarchy of their relationships. Users are associated with roles not the other way around Folders are associated with sections not the other way around. Any user can edit roles, just assign them the required permissions in a role the user is associated with. Not sure of the exact permissions required ...
cheers, //kracker <i>Counting Crows : Rain King</i>
Member since: 2001.07.13 || http://ezpedia.se7enx.com/
|
Clemens T
|
Tuesday 24 May 2005 2:08:08 am
Yeah ok, I meant it like:
User has a role limited to a section. I don't want to use the admin interface, but do it in my own interface in 1 step. So a drop down is filled with sections and a drop down (for instance) with users.. and a drop down with roles. The admin clicks 'assign' and then I would like to create all the necessary relation/user-rights. Any hints? :)
Greetings,
Clemens ps: thanks for your fast reply!!
|
kracker (the)
|
Tuesday 24 May 2005 2:47:44 am
Get ready for the ride of your life, seriously. Anything you can imagine is possible with eZ publish but more and more I hear you users looking to do a lot of customizing but don't have a clue how to achieve this on your own. It's eZ publish but that doesn't mean its going to be handed to you without a lot of work and learning. Short answer is a custom extension (possibly a workflow, i don't know). You can do it but your going to have to do a fair amount of work that most people around here simply do not even try to reply to general aka vague questions about what is possible. Instead I suggest asking very specific and small questions as stepping stones to your goal. Those might get answers, not what I've seen of most users in you situation over the past 6 months, sorry we are still a fairly small community with very view users contributing this level of example implementations back into the community. ./kracker <i>Counting Crows : Long December ...</i>
Member since: 2001.07.13 || http://ezpedia.se7enx.com/
|
Clemens T
|
Tuesday 24 May 2005 4:49:59 am
Thanks Kracker, I know this is a community that needs to be built op by every programmer. I already bought the book, but it hasn't arrived yet. I'm sorry for the vague questions, I was only looking for pointers, so I could study the material related to it. Thanks for your honest anwswer!
Greets Clemens edit: Once I know how this system works (and yes, I'm still a newbie), I'll try and assist people on this forum. Just like you are doing, I'm seeing a lot of excellent responses from your side. Good job, keep it up! :)
|
Lex 007
|
Tuesday 24 May 2005 7:34:28 am
Hi,
You should check the files in kernel/section and "reverse engineer" what's going on in there. Check also the classes :
- eZContentObjectTreeNode : kernel/classes/ezcontentobjecttreenode.php - eZSection : kernel/classes/ezsection.php The main logic for your programming shouldn't be too hard to do (by re-using core eZ Publish functions), but designing a GUI will be harder. If you need a GUI, I strongly suggest you create an extension with a new module. If not, just program a cronjob with a proper INI file (fast and easy to debug ;) Lex
|
kracker (the)
|
Tuesday 24 May 2005 8:23:14 pm
@Clemens, Thank you for saying so, I do what I can as I can, Time will tell it's value to the eZ community :) Enjoy you copy of the eZ publish book, I look forward to your contributions, ideas and insight. I often over look that the first place a new user of eZ publish might turn is the most active part of the current ez.no/community (site). When in truth, the most productive place for a new user to direct the first few weeks of regular attention is into the eZ publish documentation resources (IMHO).
<i>http://www.ez.no/ez_publish/documentation http://www.ez.no/ez_publish/documentation/faq
http://www.ez.no/ez_publish/documentation/development/extensions/module/hello_world http://www.ez.no/ez_publish/documentation/development/extensions/building_an_ez_publish_module</i> @Lex 007 Thank you for pointing / nudging Clemens in the right direction. It really helps us all when we seasoned users share our experiences to users who do not yet have those experiences and knowledge to rely on.
happy hacking, //kracker <i>FSF : Richard Stallman : Copyright vs Community in the age of computer networks </i>
Member since: 2001.07.13 || http://ezpedia.se7enx.com/
|
Bruce Morrison
|
Tuesday 24 May 2005 11:23:40 pm
The answer to both questions is yes :) The following code is from a workflow I wrote to create a user group and assign a role to it. While it's not exactly what your after it should give you a starting point.
Cheers Bruce
<?php
/*!
\class CREATEPERMS CREATEPERMStype.php
\brief Event type for user approvals
*/
include_once( "kernel/classes/ezworkflowtype.php" );
include_once( 'kernel/classes/ezrole.php' );
define( "EZ_WORKFLOW_TYPE_CREATEPERMS_ID", "createperms" );
class CreatePermsType extends eZWorkflowEventType
{
function CreatePermsType()
{
$this->eZWorkflowEventType( EZ_WORKFLOW_TYPE_CREATEPERMS_ID, ezi18n( 'kernel/workflow/event', "Create Group and Apply Role" ) );
$this->setTriggerTypes( array( 'content' => array( 'publish' => array( 'after' ) ) ) );
}
function execute( &$process, &$event )
{
$ini =& eZINI::instance('createperms.ini');
$runForClassIDs = $ini->variable( 'CreateClassInfo', 'RunFor' );
$parameters = $process->attribute( 'parameter_list' );
$versionID =& $parameters['version'];
$object =& eZContentObject::fetch( $parameters['object_id'] );
$classIdentifier = $object->attribute('class_identifier');
$objectName = $object->attribute('name');
if ($versionID == 1 &&
is_array($runForClassIDs) &&
in_array($classIdentifier, $runForClassIDs))
{
// Create group with the same name as Object
$siteini =& eZINI::instance();
$UserGroupClassID = $siteini->variable( 'UserSettings', 'UserGroupClassID' );
$userCreatorID = $siteini->variable( "UserSettings", "UserCreatorID" );
$defaultSectionID = $siteini->variable( "UserSettings", "DefaultSectionID" );
$class =& eZContentClass::fetch( $UserGroupClassID );
$contentObject =& $class->instantiate( $userCreatorID, $defaultSectionID );
//$objectID = $contentObject->attribute( 'id' );
$createParentNodeID = $ini->variable( "CreateDetails", "ParentNodeID" );
$nodeAssignment =& eZNodeAssignment::create(
array(
'contentobject_id' => $contentObject->attribute( 'id' ),
'contentobject_version' => 1,
'parent_node' => $createParentNodeID,
'is_main' => 1
)
);
$nodeAssignment->store();
$version =& $contentObject->version( 1 );
$version->setAttribute( 'modified', time() );
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
$version->store();
$contentObjectID = $contentObject->attribute( 'id' );
$contentObjectAttributes =& $version->contentObjectAttributes();
$contentObjectAttributes[0]->setAttribute( 'data_text', $objectName );
$contentObjectAttributes[0]->store();
$contentObjectAttributes[1]->setAttribute( 'data_text', $objectName.' Group' );
$contentObjectAttributes[1]->store();
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID,
'version' => 1 ) );
// Assign Role to new group
$roleID = $ini->variable( "CreateDetails", "RoleID" );
$role = eZRole::fetch( $roleID );
$role->assignToUser($contentObjectID,'subtree',$object->attribute('main_node_id'));
// Assign new group object to client group attribute
$contentObjectAttributes =& $object->contentObjectAttributes();
$contentObjectAttributes[1]->setAttribute( 'data_int', $contentObjectID );
$contentObjectAttributes[1]->store();
//eZDebug::writeDebug($UserGroupClassID);
}
return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
}
}
eZWorkflowEventType::registerType( EZ_WORKFLOW_TYPE_CREATEPERMS_ID, "CreatePermsType" );
?>
My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish
|
Xavier Dutoit
|
Tuesday 24 May 2005 11:53:21 pm
Hi Bruce, You example uses ini variables/files that you have created, right ? Could you consider "packaging" your event and put it on the contrib area, as they are very few events contributed ? Better yet, ask Paul Borgermans to create you an account on pubsvn and put it there. X+ P.S. Technical/logic question: why are your using ini files to set the RunFor ? Wouldn't it be easier to read/setup to put that as an element to setup from the back office ?
http://www.sydesy.com
|
Bruce Morrison
|
Wednesday 25 May 2005 12:13:33 am
Hi Xavier
> You example uses ini variables/files that you have > created, right ? Yep createperms.ini
[CreateClassInfo]
RunFor[]=client
[CreateDetails]
ParentNodeID=69
RoleID=7
> Could you consider "packaging" your event and put it on
> the contrib area, as they are very few events contributed > ? I'll add it to my list :) I'm flat out at the moment and looks like it will be that way for the next couple of months (ez Forums are my procrastination :) But seriously it's on the list :) At the moment it's quite specific and I'm looking at ways to make it more generic.
> P.S. Technical/logic question: why are your using ini
> files to set the RunFor ? Wouldn't it be easier to
> read/setup to put that as an element to setup from the > back office ? I'm not sure what you mean by the question. As I said the code is quite specific at the moment the ini files usage is a first attempt to make it more generic. I'm using the extension in an extranet situatation. When a new client object is created a corresponding user group and role is also created. The RunFor ini var determines the class id of the client object.
Cheers Bruce
My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish
|
Clemens T
|
Wednesday 25 May 2005 1:59:55 am
WOW... Thanks a LOT all.. I'm going to do some research now, read/understand the code... and try to give some useful comment! You're all life savers :D
|
Xavier Dutoit
|
Thursday 26 May 2005 2:43:52 am
Hi Bruce,
Let me try to clarify: When you create an attribute, you can let the user customise it when he edits the class (eg, the default text on a string attribute or more complex with an selection attribute). With an event, you can also let the user add parameters when he edits the event on its workflow (eg with the payment event, he can choose if he wants paypal). The idea is instead of puting that into a ini file, let the admin do that when he edits the workflow (easier IMO). Does it make sense ? X+
http://www.sydesy.com
|
Bruce Morrison
|
Saturday 28 May 2005 5:49:28 pm
Hi Xavier I'm with you now. Sounds like a plan. At the moment it's a very initial bit of code and personally I'm more interested in making it a more generic than making it easier to configure. Mind you, what you have suggested would get around the issue of having different settings if the event was used multiple times. BTW I spent 10 years as a unix sysadmin and I like ini file ;)
Cheers Bruce
My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish
|