Sorry, I should have given more details.
The 2 dumps in my previous post are from Public, users repo.
User u4 was activated using the code mentioned in the previous post and u3 was 
activated using the interface of Magnolia (which relies on the 
ActivationCommand class).
The difference is that, on Public, u3 retains its assigned groups, while u4 
doesn't, although they both belong to the same group in Author and, aside from 
names and dates, look identical in an Author repo dump.

The activator user is "superuser" so my guess is that it should see al 
sub-nodes of the activated user, since I also used it from the interface.
The piece of code is called from a custom filter, so I'm probably not 
initializing the context correctly.
I searched for an example/description of properly using the ActivationCommand 
or the Syndicator, but couldn't find any.
I'll keep digging.
Thanks for your reply.

Ovidiu


-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Jan Haderka
Sent: Monday, March 08, 2010 1:09 PM
To: Magnolia User-List
Subject: Re: [magnolia-user] Activating content from code using SimpleSyndicator



On Mon, 2010-03-08 at 11:19 +0100, Ovidiu Chirita wrote:
> Hello,
> 
> I'm trying to activate users from my code and can't seem to get it right.
> My problem is that I add a user, add some groups to it and then activate it, 
> but upon activation the user on the public site does not retain the groups 
> assigned to it.
> I have to mention that the groups have been created and activated beforehand 
> and, if I try the same operation from the interface, it works.
> 
> My code looks like this:
> 
> public void activate(Content content, String repoName, String 
> activatorUserName) //repoName == "users", content == the node(user) to 
> activate
> {
>         // get parent path
>         String parentPath = 
> StringUtils.substringBeforeLast(content.getHandle(), "/");
>         if (StringUtils.isEmpty(parentPath))
>         {
>             parentPath = "/";
>         }
>         log.debug("Activate - parentPath: " + parentPath);
>         String wkspaceName = ContentRepository.getDefaultWorkspace(repoName);
>         log.debug("Activate - wkspaceName: " + wkspaceName);
>         // instantiate the user with activation permissions
>         UserManager usrMgr = Security.getUserManager();
>         User activatorUser = usrMgr.getUser(activatorUserName); 
> //activatorUserName == "superuser"
>         // initialize syndicator and activate
>         SimpleSyndicator ss = new SimpleSyndicator();
>         ss.init(activatorUser, repoName, wkspaceName, new Rule());
>         ss.activate(parentPath, content);
> }

Looks alright ... almost ... Personally, I would not create new
syndicator but rather get one from the Factory/Components. Also I would
probably try to avoid having to do anything with the syndicator directly
at all, but use the ActivationCommand instead.

> 
> The result is something like this (from the users repo):

Well, that's nice but not saying much. What is the difference between
such user on the author and on public? Is there any difference?

My best guess is that the user used to activate doesn't see all the
subnodes of the activated user node and therefore can't activate all of
them. Are you executing this piece of code in system context?

> /system/u3/groups/0=3045e661-eb7c-4633-a465-6d4ba7a3369d

As far as I can tell from the export there is only one group assigned,
but as to whether this is expected or not, it's up to you to know. Is
this the uuid of the group you have assigned? If so then that info was
not lost during activation and you need to look for the problem
elsewhere.

Jan




----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------


----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to