How to grant Delete Right for all registered users via java API?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to grant Delete Right for all registered users via java API?

abtv
Default value of Delete right is DENY. How programmatically change it to ALLOW? Or how to give all the registered xwiki users right to delete xwiki spaces and pages?
Reply | Threaded
Open this post in threaded view
|

Re: How to grant Delete Right for all registered users via java API?

vmassol
Administrator
Hi,

> On 16 May 2016, at 14:51, abtv <[hidden email]> wrote:
>
> Default value of Delete right is DENY. How programmatically change it to
> ALLOW? Or how to give all the registered xwiki users right to delete xwiki
> spaces and pages?

See http://extensions.xwiki.org/xwiki/bin/view/Extension/Setting+Rights

Thanks
-Vincent

> View this message in context: http://xwiki.475771.n2.nabble.com/How-to-grant-Delete-Right-for-all-registered-users-via-java-API-tp7599456.html
> Sent from the XWiki- Dev mailing list archive at Nabble.com.

_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: How to grant Delete Right for all registered users via java API?

abtv
It's unclear how to translate it into java API. Should I use DocumentAccessBridge or something else?
Reply | Threaded
Open this post in threaded view
|

Re: How to grant Delete Right for all registered users via java API?

vmassol
Administrator

> On 16 May 2016, at 15:27, abtv <[hidden email]> wrote:
>
> It's unclear how to translate it into java API. Should I use
> DocumentAccessBridge or something else?

Maybe this will help a bit: http://platform.xwiki.org/xwiki/bin/view/DevGuide/APIGuide which explains how to modify xobjects.

Rights are xobjects.

Thanks
-Vincent

> View this message in context: http://xwiki.475771.n2.nabble.com/How-to-grant-Delete-Right-for-all-registered-users-via-java-API-tp7599456p7599458.html
> Sent from the XWiki- Dev mailing list archive at Nabble.com.

_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: How to grant Delete Right for all registered users via java API?

abtv
This post was updated on .
Still unclear how to do it. I've found  XWiki class  which has getDocument method. But it's unclear how to retrieve an instance of this class. The second problem is that getDocument method and BaseObject.set take XWikiContext instance. I'm trying to call my code on startup, so there is no context. How to do retrieve XWiki object and XWikiContext object? I call it in ApplicationReadyEventListener.
Reply | Threaded
Open this post in threaded view
|

Re: How to grant Delete Right for all registered users via java API?

abtv
This post was updated on .
Maybe there is a way to execute a string with velocity code from java code? I need to do it on application startup.
Reply | Threaded
Open this post in threaded view
|

Re: How to grant Delete Right for all registered users via java API?

Eduard Moraru
Hi,

You need to get an @Inject Provider<XWikiContext> contextProvider; declared
in your component on which you can then do inside a method
contxtProvider.get().getWiki().getDocument(...);

Hope this helps,
Eduard

On Mon, May 16, 2016 at 6:02 PM, abtv <[hidden email]> wrote:

> Maybe there is a way to execute a string with velocity code from java code?
>
>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/How-to-grant-Delete-Right-for-all-registered-users-via-java-API-tp7599456p7599461.html
> Sent from the XWiki- Dev mailing list archive at Nabble.com.
> _______________________________________________
> devs mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/devs
>
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: How to grant Delete Right for all registered users via java API?

abtv

I have the following problem: Exception in macro #handleDocumentTreeRequest called at 13:xwiki:XWiki.DocumentTree[line 3, column 1 What rights I need to add? I set view,comment,edit,delete,script rights. I use the following code:

XWikiContext context = contextProvider.get();
                if (context != null) {
                    XWiki xwiki = context.getWiki();

                    DocumentReference dr = new DocumentReference("xwiki", "XWiki", "XWikiPreferences");
                    XWikiDocument doc = xwiki.getDocument(dr, context);

                    BaseObject bo = doc.getObject("XWiki.XWikiGlobalRights", true, context);
                    bo.set("groups", "XWiki.XWikiAllGroup", context);
                    bo.set("levels", "view,comment,edit,delete,script", context);
                    bo.set("users", "", context);
                    bo.set("allow", 1, context);

                    xwiki.saveDocument(doc, context);
                }
Reply | Threaded
Open this post in threaded view
|

Re: How to grant Delete Right for all registered users via java API?

abtv
This post was updated on .
I've found that order is important "view,comment,edit,script,delete" (not "view,comment,edit,delete,script" but I still have problems: no data, just a spinning wheel.
Reply | Threaded
Open this post in threaded view
|

Re: How to grant Delete Right for all registered users via java API?

Eduard Moraru
In reply to this post by abtv
Hi,

On Tue, May 17, 2016 at 8:11 PM, abtv <[hidden email]> wrote:

> <http://xwiki.475771.n2.nabble.com/file/n7599471/xwiki_problem.jpg>
> I have the following problem: Exception in macro #handleDocumentTreeRequest
> called at 13:xwiki:XWiki.DocumentTree[line 3, column 1 What rights I need
> to
> add? I set view,comment,edit,delete,script rights. I use the following
> code:
>
> XWikiContext context = contextProvider.get();
>                 if (context != null) {
>                     XWiki xwiki = context.getWiki();
>
>                     DocumentReference dr = new DocumentReference("xwiki",
> "XWiki", "XWikiPreferences");
>                     XWikiDocument doc = xwiki.getDocument(dr, context);
>
>                     BaseObject bo =
> doc.getObject("XWiki.XWikiGlobalRights",
> true, context);
>                     bo.set("groups", "XWiki.XWikiAllGroup", context);
>                     bo.set("levels", "view,comment,edit,delete,script",
> context);
>                     bo.set("users", "", context);
>                     bo.set("allow", 1, context);
>
>                     xwiki.saveDocument(doc, context);
>                 }
>
>
Yes, this looks good. It seems you now have the answer to your initial
question.

I`m not sure I understand your second question and/or how is it related to
the delete right. You might want to start a new thread and explain the
issue better there if it`s not related.

Thanks,
Eduard

>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/How-to-grant-Delete-Right-for-all-registered-users-via-java-API-tp7599456p7599471.html
> Sent from the XWiki- Dev mailing list archive at Nabble.com.
> _______________________________________________
> devs mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/devs
>
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: How to grant Delete Right for all registered users via java API?

abtv
Before I called the code above all trees are expandable. When I callled bo.set("levels", "view,comment,edit,delete,script",context); (script right goes after delete) all macroses were unworking (can't find a macro error). Then I changed this call to bo.set("levels", "view,comment,edit,script,delete",context); (script right goes before delete) and all macroses are working except this document tree - I see spinning wheel. I think it's directly related to my code above. If I comment out the code above, document tree macro works as expected but I don't have delete right by default.