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

Querying database requires full user info access #43

Open
Arteneko opened this issue Oct 11, 2022 · 1 comment · Fixed by snuna/rusticnotion#4
Open

Querying database requires full user info access #43

Arteneko opened this issue Oct 11, 2022 · 1 comment · Fixed by snuna/rusticnotion#4

Comments

@Arteneko
Copy link

Hello!
I have the following code, in a project where I don't need full user info, just the base (without the email).
If I don't have the e-mail permission granted, the code crashes with the error below, but with the permission granted it successfully queries.

// The query
let results = notion_api
    .query_database(db, DatabaseQuery::default())
    .await?;
// The error without any user info beyond ID
Error: Error parsing json response: missing field `type`

Caused by:
    missing field `type`

// The error with user info without email
Error: Error parsing json response: missing field `email`

Caused by:
    missing field `email`

IMHO, those should either be optional, or on an enum/nested struct, and not require full permissions (otherwise, could it be mentioned in the README?)

@markacola
Copy link
Contributor

I did a bit of digging on this one. With the 3 different levels of access to user info that the notion API provides:

  1. No user information,
  2. Read user information without email addresses, and
  3. Read user information including email addresses.

The shape returned from the Notion API expected by the library currently is 3, however when querying any content with a mention and the settings of 1 & 2 then the following shapes are returned from the Notion API:
1.

{
  "type": "mention",
  "mention": {
    "type": "user",
    "user": {
      "object": "user",
      "id": "1118608e-35e8-4fa3-aef7-a4ced85ce8e0"
    }
  },
  "annotations": { ... },
  "plain_text": "@Anonymous",
  "href": null
}
{
  "type": "mention",
  "mention": {
    "type": "user",
    "user": {
      "object": "user",
      "id": "1118608e-35e8-4fa3-aef7-a4ced85ce8e0",
      "name": "John Doe",
      "avatar_url": "https://secure.notion-static.com/e6a352a8-8381-44d0-a1dc-9ed80e62b53d.jpg",
      "type": "person",
      "person": {}
    }
  },
  "annotations": { ... },
  "plain_text": "@John Doe",
  "href": null
}

The missing email and type in 1, and the missing email in 2, cause the serde deserialisation to choke.

The missing email can be resolved relatively trivially by wrapping the Bot and Person structs email in an Option<string>.

The missing type for fully anonymous users is a bit more challenging to resolve. Digging into serde I found an issue detailing the limitations for the library around mixing tagged and untagged deserialisation. I have tried the suggested workaround with the three enums by specifying a new User enum variant of Anonymous, but I haven't been able to get it working.

Another option to resolve this issue is to swap to serde(untagged) for the User enum deserialisation and use something like monostate which would allow for specifying type: MustBe!("person") and type: MustBe!("bot") on User::Person and User::Bot respectively.

Not sure if that helps, but keen to get the issues resolved as I would like to use the lower-privileged integration at some point too :)
@jakeswenson would love some direction on this one if you've got a spare moment.

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 a pull request may close this issue.

2 participants