Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mentions PoC #9279

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft

Mentions PoC #9279

wants to merge 22 commits into from

Conversation

mtomilov
Copy link
Contributor

@mtomilov mtomilov commented Jan 27, 2025

Refs #9281

Adds @mentions support in the API, emails will be addressed separately.
All of create / get / edit / search endpoints now support them.

Testing API

  • Run migrations make db
  • Login as devdata_admin and generate API token from http://localhost:5000/account/developer
  • Create annotation
     curl -X POST --location "http://localhost:5000/api/annotations" \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{
             "uri": "https://www.google.com/",
             "text": "**hello** <span>world</span>"
         }'
    
    Mentions can be already put in the text here and will be returned in the response.
  • Edit annotation
     curl -X PATCH --location "http://localhost:5000/api/annotations/<url safe id>" \
         -H "Authorization: Bearer <token>" \
         -H "Content-Type: application/json" \
         -d '{
                 "text": "Hello <a data-hyp-mention data-userid=\"acct:devdata_admin@localhost\">@devdata_admin</a>, take a look at this\nHello <a data-hyp-mention data-userid=\"acct:devdata_user@localhost\">@devdata_user</a>, take a look at this"
             }'
    
    But I think it's easier to test via edit on already created annotation.
  • Search annotations
    curl -X GET --location "http://localhost:5000/api/search" \ -H "Authorization: Bearer <token>"
    Mentions will be returned here as well

Testing emails

Notifications are sent only on creation for now

  • Create annotation
     curl -X POST --location "http://localhost:5000/api/annotations" \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{
             "uri": "https://www.google.com/",
             "text": "Hello <a data-hyp-mention data-userid=\"acct:devdata_admin@localhost\">@devdata_admin</a>, take a look at this\nHello <a data-hyp-mention data-userid=\"acct:devdata_user@localhost\">@devdata_user</a>, take a look at this"
         }'
    
  • Check h/mail folder for incoming mail

h/services/mention.py Outdated Show resolved Hide resolved

@staticmethod
def _parse_userids(text: str) -> list[str]:
return USERID_PAT.findall(text)
Copy link
Contributor Author

@mtomilov mtomilov Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll probably want to parse userids from text_rendered html.

@mtomilov mtomilov changed the title Mentions POC Mentions PoC Jan 27, 2025
@mtomilov mtomilov requested a review from marcospri January 27, 2025 16:16
h/schemas/annotation.py Outdated Show resolved Hide resolved
h/services/mention.py Show resolved Hide resolved
h/services/mention.py Outdated Show resolved Hide resolved
h/models/mention.py Outdated Show resolved Hide resolved
h/services/mention.py Outdated Show resolved Hide resolved
import re
from typing import Iterable, Sequence

import sqlalchemy as sa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't be shy about importing anything from sqlalchemy. I mean speling the whole from sqlalchemy import select, ....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, is this the recommended way?

h/services/mention.py Show resolved Hide resolved
h/services/annotation_json.py Show resolved Hide resolved
h/schemas/annotation.py Outdated Show resolved Hide resolved
h/services/annotation_json.py Show resolved Hide resolved
return [notification.mentioned_user.email], subject, text, html


def _get_user_url(user, request):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from emails/reply_notifcation.py for now

return []

notifications = []
for mention in annotation.mentions:
Copy link
Contributor Author

@mtomilov mtomilov Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to factor in groups / permissions / limits here as well to avoid sending notifications when not appropriate.

@mtomilov mtomilov requested review from acelaya and marcospri January 29, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants