Hi Sergiu,
i am writing it as part of groovy code i.e inside the groovy scriplets.
You said You should write a script service in Java that does all the
restricted work, and then you can just call it from Velocity without
programming rights.
Do i need to write any service script in java to execute the groovy code.
If yes can point me to some example.For your information this is my code
inside page on wiki
{{include document="FAQ1.FAQ1ClassSheet"/}}
{{groovy}}
import org.xwiki.observation.*
import org.xwiki.observation.event.*
import com.xpn.xwiki.web.*
import com.xpn.xwiki.*
import java.util.HashMap
import java.util.List
import java.util.Map
class OrgDataEventListener implements EventListener
{
def xwiki
def context
OrgDataEventListener(xwiki, context)
{
this.xwiki = xwiki
this.context = context
}
String getName()
{
// The unique name of this event listener
return "orgDataListener"
}
List<Event> getEvents()
{
// The list of events this listener listens to
return Arrays.asList(new DocumentUpdateEvent(), new
DocumentSaveEvent())
}
// Called by the Observation Manager when an event matches the list of
events returned
// by getEvents()
void onEvent(Event event, Object source, Object data)
{
String orgAdminUser="XWiki.Question1AdminUser"
String displayAdminUser= "Question1AdminDisplayUser"
String xwikiUser1 = xwiki.getUser(orgAdminUser)
String wikiname = xwiki.getXWiki().clearName(orgAdminUser, true,
true, xcontext.getContext())
Map<String, String> map = new HashMap<String, String>()
map.put("active", "1")
map.put("first_name", displayAdminUser)
xwiki.getXWiki().createUser(wikiname , map, "edit",
xcontext.getContext()
}
}
// Register against the Observation Manager
def observation = Utils.getComponent(ObservationManager.class)
observation.removeListener("orgDataListener")
def listener = new OrgDataEventListener(xwiki, xcontext)
observation.addListener(listener)
{{/groovy}}
On Thu, May 17, 2012 at 8:24 PM, Sergiu Dumitriu <sergiu(a)xwiki.com> wrote:
On 05/17/2012 05:13 AM, mohit gupta wrote:
I am trying to execute below groovy script thru
one of the UI Page
String xwikiUser = xwiki.getUser("Scott")//line1 executing
String wikiname = xwiki.getXWiki().clearName("**Scott", true, true,
xcontext.getContext())//line2
// other code which is also not executing
but line 2 never executes becoz i dont get control in clearName method.
After debugging it i found while
xwiki.getXWiki() it checks whether user has programming right rights
which returns null. But i have explicitly given the admin user program
rights at
wiki administartion level.
For more debugging information control goes to method i.e public
boolean
hasProgrammingRights(**XWikiContext context) of xwikiAuthServiceImpl.java
and line 3 returns false
// Once dropPermissions has been called, the document in the
// context cannot have programming permission.
if (context.**hasDroppedPermissions()) {
If the code enters here, it means that you're trying to execute code
outside the page content, which isn't allowed. You should write a script
service in Java that does all the restricted work, and then you can just
call it from Velocity without programming rights.
return false;//;line 3
}
Not getting how to give proper programming rights to admin user here?
--
Sergiu Dumitriu
http://purl.org/net/sergiu/
______________________________**_________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/**mailman/listinfo/users<http://lists.xwiki.org/m…