[annotator-dev] How to query annotations created by current user only

Rick rmercer33 at gmail.com
Thu Nov 27 00:47:44 UTC 2014


Thanks for the help Bird, your suggestion works great. I see that I didn't
understand the documentation.

I do have another question if you don't mind.

For the PUT and DELETE endpoints, the annotator does not use the
/api/annotator/:id pattern but sends the annotation in the request body and
calls /api/annotator. I can get the 'id' from the body so can make it work
but this behavior does not correspond to the docs. Any idea what's going on?

Thanks again,

Rick

On Tue, Nov 25, 2014 at 12:46 AM, Sarah Bird - Bonvaya <sarah at bonvaya.com>
wrote:

> Hi Rick,
>
> This is how I do something similar:
>
> a.annotator('addPlugin', 'Store', {
>   prefix: 'http://annotateit.org/api',
>   annotationData: {
>     'project': PROJECTNAME,
>     'version': VERSION,
>     'uri': URI,
>     'siteuid': SITE_UNIQUE_ID,
>     'pageuid': PAGE_UNIQUE_ID
>   },
>   loadFromSearch: {
>     'pageuid': PAGE_UNIQUE_ID.toLowerCase(),
>     'limit': 1000
>   }
> });
>
> (
> https://github.com/open-contracting/standard-collaborator/blob/master/django/website/main/templates/main/standard.html#L91
> )
>
> I am adding custom data, and searching based on that.
>
> In your case, I imagine this should work:
>
> a.annotator('addPlugin', 'Store', {
>   prefix: 'http://annotateit.org/api',
>   annotationData: {
>     "docId":that.data._id,
>     "userId":Meteor.userId()
>   },
>   loadFromSearch: {
>     'userId': Meteor.userId(),
>     'limit': 1000
>   }
> });
>
> Assuming your store endpoint has a search api working.
>
> Best,
>
> Bird
>
>
> On Thu, Nov 20, 2014 at 5:47 PM, Rick <rmercer33 at gmail.com> wrote:
>
>> Hi All,
>>
>> I'm using annotator.js v 1.2.9 and using the Store plugin with Meteor and
>> MongoDB.
>>
>> I want only annotations created by the current user to be displayed.
>>
>> When annotator is first initialized it makes a GET request to receive all
>> annotations. Rather than return all annotations I want to return only those
>> created by the current user (on the current page).
>>
>> But the GET request does not include any user information that can be
>> used to query the database. I tried using the annotationData option of the
>> Store plugin but that info is not part of the GET request - but is part of
>> the annotation json object in the body of a POST.
>>
>> that.$('#document').annotator()
>>         .annotator("addPlugin", 'Store', {
>>           prefix: '/api',
>>           annotationData: {"docId":that.data._id,
>> "userId":Meteor.userId()}
>>         })
>>
>>
>> I tried the Permissions plugin and can see how that prevents others from
>> editing or deleting an annotation they did not create but It doesn't seem
>> to work when I try to restrict readers to just the creator. Here's my code
>> for that:
>>
>>   var userInfo = {id:Meteor.userId(),
>> email:Meteor.user().emails[0].address};
>>
>>
>> .annotator("addPlugin", 'Permissions', {
>>           user: userInfo,
>>           userId: function(user) {
>>             if (user && user.id) {
>>               return user.id;
>>             }
>>             else
>>               return user
>>           },
>>           userString: function(user) {
>>             if (user && user.id) {
>>               return user.email;
>>             }
>>             else
>>               return user
>>           },
>>           permissions: {
>>             'read': [userInfo.id],
>>             'update': [userInfo.id],
>>             'delete': [userInfo.id],
>>             'admin': [userInfo.id]
>>           },
>>           showViewPermissionsCheckbox: false,
>>           showEditPermissionsCheckbox: false
>>         })
>>
>>
>> I also tried the Auth plugin which adds an 'x-annotator-auth-token' key
>> to the request header and I can use that token to obtain user info but, the
>> token is not added to the GET request.
>>
>> So, I don't know how to proceed. All help is gratefully appreciated.
>>
>> Thanks in advance.
>>
>> Rick ;-)
>>
>> _______________________________________________
>> annotator-dev mailing list
>> annotator-dev at lists.okfn.org
>> https://lists.okfn.org/mailman/listinfo/annotator-dev
>> Unsubscribe: https://lists.okfn.org/mailman/options/annotator-dev
>>
>>
>
> _______________________________________________
> annotator-dev mailing list
> annotator-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/annotator-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/annotator-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/annotator-dev/attachments/20141126/a1d4832c/attachment-0004.html>


More information about the annotator-dev mailing list