I finally got it :)
Defining a rule which explicitly allows content is mandatory.
This worked for me:
public void activate(Content content, String repoName, String activatorUserName)
{
// 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
Syndicator ss = (Syndicator) FactoryUtil.newInstance(Syndicator.class);
ss.init(activatorUser, repoName, wkspaceName, getRule(content));
//repoName == "users" (or the repo to which this content belongs), content ==
the node(user) to activate
ss.activate(parentPath, content, getOrderingInfo(content));
}
protected Rule getRule(Content cnt)
{
Rule rule = new Rule();
try
{
rule.addAllowType(cnt.getNodeTypeName());
rule.addAllowType(ItemType.CONTENTNODE.toString()); // also a must
// magnolia resource and metadata must always be included
rule.addAllowType(ItemType.NT_METADATA);
rule.addAllowType(ItemType.NT_RESOURCE);
}
catch (RepositoryException e)
{
log.error(e.getMessage());
}
return rule;
}
Regards,
Ovidiu
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ovidiu Chirita
Sent: Monday, March 08, 2010 3:40 PM
To: Magnolia User-List
Subject: RE: [magnolia-user] Activating content from code using SimpleSyndicator
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
----------------------------------------------------------------
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]>
----------------------------------------------------------------