Is there an event I can listen to when a document is shared with a user or a group?

Hey team!

Background: I’m very new to XWiki, found it amazing because of it’s extendability and a great plugin ecosystem. I have been given a usecase which involves synchronizing the access of a particular user for a 3rd party hosted document(Google docs for example) which might be mentioned as a link in an XWiki wiki. If a user has an access to that particular wiki, then the links mentioned in that particular wiki should be accessible when a user opens it. We’re going to make it an option rather than a default for security purposes.

Question: Is there a way I can listen to an event which might be triggered when a user shares a particular xwiki document with a group/user?, I’m wondering if a DocumentUpdatedEvent is fired in such a scenario, if yes, would I have to compare the list of users who have access to it from the prior document version and generate a new event? If not, is there an ActionExecutedEvent for such a thing?

Thanks,
Pratik

Hi,

which sharing capability of XWiki do you have in mind exactly? AFAIR there’s no “share with a user/group” action natively in XWiki but maybe you’re doing it in a custom way?

There’s a share page by email feature that allows sharing with users or groups. Maybe that’s the one?

Thanks for the reply @vmassol and @surli
I really thought Xwiki had the capability to restrict a group/user from viewing a particular wiki, have I got it wrong?, Because when I saw the fact that xwiki had user/groups I thought it would be possible. Is there an extension/plugin which has been built for the same?, sorry I discovered XWiki just recently and might have overlooked this.

Thanks,
Pratik.

No, that’s true: you can restrict viewing a particular wiki, but people has to know they should go to view your pages. I thought that you had in mind a particular mechanism to push people to go view the page.

So far my understanding of your scenario is that:

  1. you host a doc in a 3rd party
  2. you create (or update?) a document in XWiki with a link to the first doc
  3. you notify people to go in XWiki ? how ?

So the usecase is to synchronize access,

  1. User/Group gets access to a wiki
  2. We check if there are any google doc links present in that wiki
  3. If yes, then we provide the user with an access to that google doc in google drive.

But for all of this to happen I would need to know of an event which tells that “now this user/group has access to this wiki”

Sorry it’s still not entirely clear to me: when you say “User/Group gets access to a wiki”, there’s something automatic to create the user/groups or it will be manual in your process?
In any case there is dedicated events when a specific xobject is created, which is the case when a user or a group is created, it might be best event for you.
See the definition here: https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/internal/event/XObjectAddedEvent.java
And example of usage here for listening on a user created: https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-user/xwiki-platform-user-default/src/main/java/org/xwiki/user/internal/group/UsersCacheInvalidationListener.java#L70

We don’t have events triggered at first access of a user in a wiki, after the user profile has been created if that’s what you want.

Sorry it’s still not entirely clear to me: when you say “User/Group gets access to a wiki”, there’s something automatic to create the user/groups or it will be manual in your process?

It’s a manual process, like when the wiki owner enables access to a particular user/group. I think there’s something fundamental which I’m missing to understand here. I was gonna make something like a web-hook out of this event if it had existed. Do you think it’s possible to customize XWiki to trigger such an event?

So triggering the event I mentioned is easy: you just need to create a user.

Well it might also be me missing something :slight_smile: Honestly right now I find your usecase overly complicated: one of the main reason to use XWiki is for storing documents, so I’m not sure to understand the usecase of synchronizing access to a 3rd party dedicated to store documents. And even if I put that aside I’m still not sure to understand what problem you want to solve with the events: if you create the users manually then you can as well just send an email automatically when they’re registered on the wiki so they consult it?

so I’m not sure to understand the usecase of synchronizing access to a 3rd party dedicated to store documents

So the point is to avoid getting access to the links present in the Wiki, once the user gets access to that wiki, the links present in that wiki should automatically be accessible.

if you create the users manually then you can as well just send an email automatically when they’re registered on the wiki so they consult it?

A user might have been created but might not have access to that wiki until he has been allowed to view that wiki, isn’t it?

I’m very sorry but that sentence is confusing for me: if you grant access to someone to a wiki, which contains links, then yes of course those links are accessible. There’s nothing to automate here: you give access, people gets access. What do I miss?

Ok so my previous answer is wrong then: you don’t want to listen on events triggered at user creation, you want to listen on events when access is granted. So in your scenario, how do you grant access to a specific part of the wiki to users?
Rights management in XWiki is also performed using XObjects (like many things in XWiki) so you could listen to XObjectAdded/UpdatedEvent but here it’s far more complicated because those events are triggered for any rights manipulation and you’d have some complex filtering to do.

Thanks for being so patient with me, the links present in the document can be google drive links, and just because I have an access to the wiki which contains those links, I should be able to have viewing rights for those linked documents in google drive if they don’t have an access to those links in google drive yet. Am I a bit more clear now?

Thanks! this helps plenty, and I think I do understand that since the event is very generic I’d have to have some complicated filtering logic. Regarding granting the access, I think we’ll go with whatever XWiki provdes from the UI, it’s not gonna be automated

Ok, so my understanding is that you want the following:

  1. You have a wiki containing links to google docs
  2. You grant access to user JohnDoe to the document YourWiki.GDoc1 which contains a link to drive.google.com/gdoc1
  3. Automatically drive.google.com/gdoc1 viewing credentials is modified to grant access to JohnDoe

Is it the scenario you have in mind? In such case how do you perform the binding between the user in xwiki and the user in google drive?

Ok then maybe you could check the Right API extension and the dedicated RightUpdatedEvent: https://extensions.xwiki.org/xwiki/bin/view/Extension/api-rights/#HUpdatedRightEvent you have to install the extension first on your wiki, but it might simplify your job.

In such case how do you perform the binding between the user in xwiki and the user in google drive?

I’m wondering if I can use the email from the User Module extension someway once I get a reference of the user from the RightUpdatedEvent?, what do you think?, also sorry for the late reply I was not working :slight_smile:

Hi,

it’s indeed possible but I’m sorry it won’t be exactly straightforward: the user API in XWiki is not yet used everywhere so you’ll need to use bridges.
So what might be done:

  • you get a RightUpdatedEvent which is sent along with:

data: a List<SecurityRuleDiff> corresponding of the diff of rules before and after the changes

  • so you listen to that event and actually retrieve the data (see the Observation Module doc)
  • then from the SecurityRuleDiff you can check previous and current SecurityRule. And a SecurityRule allows to get a List<DocumentReference> when you get users (I’ll let you check the sources of the right-api extension)
  • So now you have a DocumentReference representing a user and the User API allows you to retrieve an email from a UserReference by resolving the UserProperties: you need first to transform that DocumentReference to a UserReference
  • this is done using the bridged documented in User API documentation, with a UserReferenceResolver
  • then you can use a UserPropertiesResolver which takes a UserReference and you get a UserProperties object which gives you the email address of your user (see also User API doc for that)

Hey @surli, thanks so much, I think this is pretty much everything I needed to know!