[xwiki-devs] How to check if a specific document has programming rights?
Hi devs, I tried to use: $someDoc.hasProgrammingRights() but unfortunately this method checks the current/context document, not the one on which it is called. The code is in com.xpn.xwiki.api.Api: /** * Check if the current document has programming rights, meaning that it was last saved by a user with the * programming right globally granted. * * @return <tt>true</tt> if the current document has the Programming right or <tt>false</tt> otherwise. */ public boolean hasProgrammingRights() { com.xpn.xwiki.XWiki xwiki = this.context.getWiki(); return xwiki.getRightService().hasProgrammingRights(this.context); } So how do you check if a specific document has programming rights? AFAICS I need to either access the rights service or change the context document, but both require programming rights.. How can I check programming rights without needing them? Thanks, Marius
Hi Marius, Would hasAccessLevel("programming", "Some.Doc") work ? On Wed, Aug 31, 2011 at 11:45 AM, Marius Dumitru Florea <[email protected]> wrote:
Hi devs,
I tried to use:
$someDoc.hasProgrammingRights()
but unfortunately this method checks the current/context document, not the one on which it is called. The code is in com.xpn.xwiki.api.Api:
/** * Check if the current document has programming rights, meaning that it was last saved by a user with the * programming right globally granted. * * @return <tt>true</tt> if the current document has the Programming right or <tt>false</tt> otherwise. */ public boolean hasProgrammingRights() { com.xpn.xwiki.XWiki xwiki = this.context.getWiki(); return xwiki.getRightService().hasProgrammingRights(this.context); }
So how do you check if a specific document has programming rights? AFAICS I need to either access the rights service or change the context document, but both require programming rights.. How can I check programming rights without needing them?
Thanks, Marius _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Jerome Velociter Winesquare http://www.winesquare.net/
On Wed, Aug 31, 2011 at 1:45 PM, Jerome Velociter <[email protected]> wrote:
Hi Marius,
Would hasAccessLevel("programming", "Some.Doc") work ?
Nop. I tried: $someDoc.hasAccessLevel('programming') but it tells me if the current user can save with programming rights the specified document. That's not what I need. Programming rights check on a document shouldn't depend on the current user, but on the last author. I could use: $someDoc.hasAccessLevel('programming', $someDoc.contentAuthor) but it's not enough because XWikiRightsServiceImpl#hasProgrammingRights(XWikiDocument, XWikiContext) does a few checks before making the above call. For instance it checks if the content author is from the main wiki. I don't want to duplicate this code.. Thanks, Marius
On Wed, Aug 31, 2011 at 11:45 AM, Marius Dumitru Florea <[email protected]> wrote:
Hi devs,
I tried to use:
$someDoc.hasProgrammingRights()
but unfortunately this method checks the current/context document, not the one on which it is called. The code is in com.xpn.xwiki.api.Api:
/** * Check if the current document has programming rights, meaning that it was last saved by a user with the * programming right globally granted. * * @return <tt>true</tt> if the current document has the Programming right or <tt>false</tt> otherwise. */ public boolean hasProgrammingRights() { com.xpn.xwiki.XWiki xwiki = this.context.getWiki(); return xwiki.getRightService().hasProgrammingRights(this.context); }
So how do you check if a specific document has programming rights? AFAICS I need to either access the rights service or change the context document, but both require programming rights.. How can I check programming rights without needing them?
Thanks, Marius _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Jerome Velociter Winesquare http://www.winesquare.net/ _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Since all PR checks are run against the document xwiki:XWiki.XWikiPreferences you would need to do: $xwiki.getDocument('xwiki:XWiki.XWikiPreferences').hasAccessLevel('programming', $doc.getContentAuthor()) Caleb On 08/31/2011 07:22 AM, Marius Dumitru Florea wrote:
On Wed, Aug 31, 2011 at 1:45 PM, Jerome Velociter <[email protected]> wrote:
Hi Marius,
Would hasAccessLevel("programming", "Some.Doc") work ?
Nop. I tried:
$someDoc.hasAccessLevel('programming')
but it tells me if the current user can save with programming rights the specified document. That's not what I need. Programming rights check on a document shouldn't depend on the current user, but on the last author.
I could use:
$someDoc.hasAccessLevel('programming', $someDoc.contentAuthor)
but it's not enough because XWikiRightsServiceImpl#hasProgrammingRights(XWikiDocument, XWikiContext) does a few checks before making the above call. For instance it checks if the content author is from the main wiki. I don't want to duplicate this code..
Thanks, Marius
On Wed, Aug 31, 2011 at 11:45 AM, Marius Dumitru Florea <[email protected]> wrote:
Hi devs,
I tried to use:
$someDoc.hasProgrammingRights()
but unfortunately this method checks the current/context document, not the one on which it is called. The code is in com.xpn.xwiki.api.Api:
/** * Check if the current document has programming rights, meaning that it was last saved by a user with the * programming right globally granted. * * @return <tt>true</tt> if the current document has the Programming right or <tt>false</tt> otherwise. */ public boolean hasProgrammingRights() { com.xpn.xwiki.XWiki xwiki = this.context.getWiki(); return xwiki.getRightService().hasProgrammingRights(this.context); }
So how do you check if a specific document has programming rights? AFAICS I need to either access the rights service or change the context document, but both require programming rights.. How can I check programming rights without needing them?
Thanks, Marius _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Jerome Velociter Winesquare http://www.winesquare.net/ _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On Wed, Aug 31, 2011 at 2:58 PM, Caleb James DeLisle <[email protected]> wrote:
Since all PR checks are run against the document xwiki:XWiki.XWikiPreferences you would need to do:
$xwiki.getDocument('xwiki:XWiki.XWikiPreferences').hasAccessLevel('programming', $doc.getContentAuthor())
I don't think you understood my question. I want to test if a specific document, different from the current document, has programming rights. I don't see how $doc.contentAuthor could help me. Also, in my previous mail I said that hasAccessLevel('programming', ...) is not enough because XWikiRightsServiceImpl#hasProgrammingRights(XWikiDocument, XWikiContext) does a few checks before making the above call. For instance it checks if the content author is from the main wiki. I don't want to duplicate that code.. Thanks, Marius
Caleb
On 08/31/2011 07:22 AM, Marius Dumitru Florea wrote:
On Wed, Aug 31, 2011 at 1:45 PM, Jerome Velociter <[email protected]> wrote:
Hi Marius,
Would hasAccessLevel("programming", "Some.Doc") work ?
Nop. I tried:
$someDoc.hasAccessLevel('programming')
but it tells me if the current user can save with programming rights the specified document. That's not what I need. Programming rights check on a document shouldn't depend on the current user, but on the last author.
I could use:
$someDoc.hasAccessLevel('programming', $someDoc.contentAuthor)
but it's not enough because XWikiRightsServiceImpl#hasProgrammingRights(XWikiDocument, XWikiContext) does a few checks before making the above call. For instance it checks if the content author is from the main wiki. I don't want to duplicate this code..
Thanks, Marius
On Wed, Aug 31, 2011 at 11:45 AM, Marius Dumitru Florea <[email protected]> wrote:
Hi devs,
I tried to use:
$someDoc.hasProgrammingRights()
but unfortunately this method checks the current/context document, not the one on which it is called. The code is in com.xpn.xwiki.api.Api:
/** * Check if the current document has programming rights, meaning that it was last saved by a user with the * programming right globally granted. * * @return <tt>true</tt> if the current document has the Programming right or <tt>false</tt> otherwise. */ public boolean hasProgrammingRights() { com.xpn.xwiki.XWiki xwiki = this.context.getWiki(); return xwiki.getRightService().hasProgrammingRights(this.context); }
So how do you check if a specific document has programming rights? AFAICS I need to either access the rights service or change the context document, but both require programming rights.. How can I check programming rights without needing them?
Thanks, Marius _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Jerome Velociter Winesquare http://www.winesquare.net/ _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On Wed, Aug 31, 2011 at 11:45 AM, Marius Dumitru Florea <[email protected]> wrote:
Hi devs,
I tried to use:
$someDoc.hasProgrammingRights()
but unfortunately this method checks the current/context document, not the one on which it is called. The code is in com.xpn.xwiki.api.Api:
/** * Check if the current document has programming rights, meaning that it was last saved by a user with the * programming right globally granted. * * @return <tt>true</tt> if the current document has the Programming right or <tt>false</tt> otherwise. */ public boolean hasProgrammingRights() { com.xpn.xwiki.XWiki xwiki = this.context.getWiki(); return xwiki.getRightService().hasProgrammingRights(this.context); }
So how do you check if a specific document has programming rights? AFAICS I need to either access the rights service or change the context document, but both require programming rights.. How can I check programming rights without needing them?
$xwiki.hasAccessLevel("programming", $mydoc.contentAuthor, "anydocumentitsnotusedanyway") should work well.
Thanks, Marius _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
On Wed, Aug 31, 2011 at 3:00 PM, Thomas Mortagne <[email protected]> wrote:
On Wed, Aug 31, 2011 at 11:45 AM, Marius Dumitru Florea <[email protected]> wrote:
Hi devs,
I tried to use:
$someDoc.hasProgrammingRights()
but unfortunately this method checks the current/context document, not the one on which it is called. The code is in com.xpn.xwiki.api.Api:
/** * Check if the current document has programming rights, meaning that it was last saved by a user with the * programming right globally granted. * * @return <tt>true</tt> if the current document has the Programming right or <tt>false</tt> otherwise. */ public boolean hasProgrammingRights() { com.xpn.xwiki.XWiki xwiki = this.context.getWiki(); return xwiki.getRightService().hasProgrammingRights(this.context); }
So how do you check if a specific document has programming rights? AFAICS I need to either access the rights service or change the context document, but both require programming rights.. How can I check programming rights without needing them?
$xwiki.hasAccessLevel("programming", $mydoc.contentAuthor, "anydocumentitsnotusedanyway")
should work well.
What about the rest of the tests done in XWikiRightsServiceImpl#hasProgrammingRights(XWikiDocument, XWikiContext) ? hasAccessLevel('programming', ..) is called only at the end. I suppose they are needed, otherwise hasProgrammingRights would have just called hasAccessLevel no? Thanks, Marius
Thanks, Marius _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On Wed, Aug 31, 2011 at 15:13, Marius Dumitru Florea < [email protected]> wrote:
On Wed, Aug 31, 2011 at 3:00 PM, Thomas Mortagne <[email protected]> wrote:
On Wed, Aug 31, 2011 at 11:45 AM, Marius Dumitru Florea <[email protected]> wrote:
Hi devs,
I tried to use:
$someDoc.hasProgrammingRights()
but unfortunately this method checks the current/context document, not the one on which it is called. The code is in com.xpn.xwiki.api.Api:
/** * Check if the current document has programming rights, meaning that it was last saved by a user with the * programming right globally granted. * * @return <tt>true</tt> if the current document has the Programming right or <tt>false</tt> otherwise. */ public boolean hasProgrammingRights() { com.xpn.xwiki.XWiki xwiki = this.context.getWiki(); return xwiki.getRightService().hasProgrammingRights(this.context); }
So how do you check if a specific document has programming rights? AFAICS I need to either access the rights service or change the context document, but both require programming rights.. How can I check programming rights without needing them?
$xwiki.hasAccessLevel("programming", $mydoc.contentAuthor, "anydocumentitsnotusedanyway")
should work well.
What about the rest of the tests done in XWikiRightsServiceImpl#hasProgrammingRights(XWikiDocument, XWikiContext) ? hasAccessLevel('programming', ..) is called only at the end. I suppose they are needed, otherwise hasProgrammingRights would have just called hasAccessLevel no?
Thomas has proposed the most correct answer but I see one potential issue if $mydoc.contentAuthor does not return a fully qualified username (including the database), so you may need to at least proceed to the addition of the database of the document to the content author name if it does not contains a ':' Denis
Thanks, Marius
Thanks, Marius _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Denis Gervalle SOFTEC sa - CEO eGuilde sarl - CTO
On Wed, Aug 31, 2011 at 3:21 PM, Denis Gervalle <[email protected]> wrote:
On Wed, Aug 31, 2011 at 15:13, Marius Dumitru Florea < [email protected]> wrote:
On Wed, Aug 31, 2011 at 3:00 PM, Thomas Mortagne <[email protected]> wrote:
On Wed, Aug 31, 2011 at 11:45 AM, Marius Dumitru Florea <[email protected]> wrote:
Hi devs,
I tried to use:
$someDoc.hasProgrammingRights()
but unfortunately this method checks the current/context document, not the one on which it is called. The code is in com.xpn.xwiki.api.Api:
/** * Check if the current document has programming rights, meaning that it was last saved by a user with the * programming right globally granted. * * @return <tt>true</tt> if the current document has the Programming right or <tt>false</tt> otherwise. */ public boolean hasProgrammingRights() { com.xpn.xwiki.XWiki xwiki = this.context.getWiki(); return xwiki.getRightService().hasProgrammingRights(this.context); }
So how do you check if a specific document has programming rights? AFAICS I need to either access the rights service or change the context document, but both require programming rights.. How can I check programming rights without needing them?
$xwiki.hasAccessLevel("programming", $mydoc.contentAuthor, "anydocumentitsnotusedanyway")
should work well.
What about the rest of the tests done in XWikiRightsServiceImpl#hasProgrammingRights(XWikiDocument, XWikiContext) ? hasAccessLevel('programming', ..) is called only at the end. I suppose they are needed, otherwise hasProgrammingRights would have just called hasAccessLevel no?
Thomas has proposed the most correct answer but I see one potential issue if $mydoc.contentAuthor does not return a fully qualified username (including the database), so you may need to at least proceed to the addition of the database of the document to the content author name if it does not contains a ':'
That should not be needed if there is no bug.
Denis
Thanks, Marius
Thanks, Marius _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Denis Gervalle SOFTEC sa - CEO eGuilde sarl - CTO _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
On Wed, Aug 31, 2011 at 4:34 PM, Thomas Mortagne <[email protected]> wrote:
On Wed, Aug 31, 2011 at 3:21 PM, Denis Gervalle <[email protected]> wrote:
On Wed, Aug 31, 2011 at 15:13, Marius Dumitru Florea < [email protected]> wrote:
On Wed, Aug 31, 2011 at 3:00 PM, Thomas Mortagne <[email protected]> wrote:
On Wed, Aug 31, 2011 at 11:45 AM, Marius Dumitru Florea <[email protected]> wrote:
Hi devs,
I tried to use:
$someDoc.hasProgrammingRights()
but unfortunately this method checks the current/context document, not the one on which it is called. The code is in com.xpn.xwiki.api.Api:
/** * Check if the current document has programming rights, meaning that it was last saved by a user with the * programming right globally granted. * * @return <tt>true</tt> if the current document has the Programming right or <tt>false</tt> otherwise. */ public boolean hasProgrammingRights() { com.xpn.xwiki.XWiki xwiki = this.context.getWiki(); return xwiki.getRightService().hasProgrammingRights(this.context); }
So how do you check if a specific document has programming rights? AFAICS I need to either access the rights service or change the context document, but both require programming rights.. How can I check programming rights without needing them?
$xwiki.hasAccessLevel("programming", $mydoc.contentAuthor, "anydocumentitsnotusedanyway")
should work well.
What about the rest of the tests done in XWikiRightsServiceImpl#hasProgrammingRights(XWikiDocument, XWikiContext) ? hasAccessLevel('programming', ..) is called only at the end. I suppose they are needed, otherwise hasProgrammingRights would have just called hasAccessLevel no?
Thomas has proposed the most correct answer but I see one potential issue if $mydoc.contentAuthor does not return a fully qualified username (including the database), so you may need to at least proceed to the addition of the database of the document to the content author name if it does not contains a ':'
That should not be needed if there is no bug.
Unless the document is not in the current wiki indeed. We really neede reference based right apis...
Denis
Thanks, Marius
Thanks, Marius _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Denis Gervalle SOFTEC sa - CEO eGuilde sarl - CTO _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
-- Thomas Mortagne
On Wed, Aug 31, 2011 at 3:13 PM, Marius Dumitru Florea <[email protected]> wrote:
On Wed, Aug 31, 2011 at 3:00 PM, Thomas Mortagne <[email protected]> wrote:
On Wed, Aug 31, 2011 at 11:45 AM, Marius Dumitru Florea <[email protected]> wrote:
Hi devs,
I tried to use:
$someDoc.hasProgrammingRights()
but unfortunately this method checks the current/context document, not the one on which it is called. The code is in com.xpn.xwiki.api.Api:
/** * Check if the current document has programming rights, meaning that it was last saved by a user with the * programming right globally granted. * * @return <tt>true</tt> if the current document has the Programming right or <tt>false</tt> otherwise. */ public boolean hasProgrammingRights() { com.xpn.xwiki.XWiki xwiki = this.context.getWiki(); return xwiki.getRightService().hasProgrammingRights(this.context); }
So how do you check if a specific document has programming rights? AFAICS I need to either access the rights service or change the context document, but both require programming rights.. How can I check programming rights without needing them?
$xwiki.hasAccessLevel("programming", $mydoc.contentAuthor, "anydocumentitsnotusedanyway")
should work well.
What about the rest of the tests done in XWikiRightsServiceImpl#hasProgrammingRights(XWikiDocument, XWikiContext) ? hasAccessLevel('programming', ..) is called only at the end. I suppose they are needed, otherwise hasProgrammingRights would have just called hasAccessLevel no?
If this method does not work for what you need then it's a bug to be fixed.
Thanks, Marius
Thanks, Marius _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
On Wed, Aug 31, 2011 at 11:45 AM, Marius Dumitru Florea <[email protected]> wrote:
Hi devs,
I tried to use:
$someDoc.hasProgrammingRights()
but unfortunately this method checks the current/context document,
I agree that it does not really make sense but it's to late to change it now.
not the one on which it is called. The code is in com.xpn.xwiki.api.Api:
/** * Check if the current document has programming rights, meaning that it was last saved by a user with the * programming right globally granted. * * @return <tt>true</tt> if the current document has the Programming right or <tt>false</tt> otherwise. */ public boolean hasProgrammingRights() { com.xpn.xwiki.XWiki xwiki = this.context.getWiki(); return xwiki.getRightService().hasProgrammingRights(this.context); }
So how do you check if a specific document has programming rights? AFAICS I need to either access the rights service or change the context document, but both require programming rights.. How can I check programming rights without needing them?
Thanks, Marius _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
participants (5)
-
Caleb James DeLisle -
Denis Gervalle -
Jerome Velociter -
Marius Dumitru Florea -
Thomas Mortagne