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

[Feature Request]: Send username of the user that created the page in the webhook #3279

Closed
joaomezzari opened this issue Feb 22, 2022 · 2 comments

Comments

@joaomezzari
Copy link

Describe the feature you'd like

Hi,
In order to do some notifications, we need that the outgoing webhook sends the username of the user that created the page where the event is happening, in the payload. Something like:
{ "event": "page_update", "text": "Benny updated page \"My wonderful updated page\"", **"page_owner": "username"** "triggered_at": "2021-12-11T22:25:10.000000Z", "triggered_by": { "id": 1, "name": "Benny", "slug": "benny" }, "triggered_by_profile_url": "https://bookstack.local/user/benny", "webhook_id": 2, "webhook_name": "My page update webhook", "url": "https://bookstack.local/books/my-awesome-book/page/my-wonderful-updated-page", "related_item": { "id": 2432, "book_id": 13, "chapter_id": 554, "name": "My wonderful updated page", "slug": "my-wonderful-updated-page", "priority": 2, "created_at": "2021-12-11T21:53:24.000000Z", "updated_at": "2021-12-11T22:25:10.000000Z", "created_by": 1, "updated_by": 1, "draft": false, "revision_count": 9, "template": false, "owned_by": 1 } }

Describe the benefits this feature would bring to BookStack users

By sending the username, we can integrate notifications with other platforms consuming the APIs and directing something to the specific user, for example.

Additional context

No response

@ssddanbrown
Copy link
Member

Thanks for the request @joaomezzari,

My trouble with this is that we have to limit the scope of the webhook data somewhere, we can't just add or load in all details ever needed. For things outside of that it'd be a case look back up to the REST API.
That said, maybe we should still load in common relations for the main entities like the creator and updater. In that case it'd be accessible (in theory) at related_item.owned_by.slug.
This may be a breaking change to the webhook shape though so not something for a patch release.

If you're desperate for this, and can piece together PHP, there's a WEBHOOK_CALL_BEFORE event for the logical theme system that can be used to customize the webhook data.

ssddanbrown added a commit that referenced this issue Mar 26, 2022
Creates a new organsied formatting system for webhook data, with
interfaces for extending with custom model formatting rules.
Allows easy usage & extension of the default bookstack formatting
behaviour when customizing webhook events via theme system, and keeps
default data customizations organised.

This also makes the following webhook data changes:
- owned_by/created_by/updated_by user details are loaded for events with
  Entity details. (POTENTIALLY BREAKING CHANGE).
- current_revision details are loaded for page update/create events.

Added testing to cover added model formatting rules.

For #3279 and #3218
@ssddanbrown ssddanbrown added this to the Next Feature Release milestone Mar 26, 2022
@ssddanbrown ssddanbrown self-assigned this Mar 26, 2022
@ssddanbrown
Copy link
Member

I have now applied changes related to this within 3625f12. Creator, Updater and Owner details are now loaded in so you'd be able to get the owner slug at related_item.owned_by.slug. Trimmed-down example data:

{
    "event": "page_update",
    ...
    "url": "https://bookstack.local/books/my-awesome-book/page/my-wonderful-updated-page",
    "related_item": {
        "id": 2432,
        ...
        "created_by": {
            "id": 1,
            "name": "Benny",
            "slug": "benny"
        },
        "updated_by": {
            "id": 1,
            "name": "Benny",
            "slug": "benny"
        },
        "owned_by": {
            "id": 1,
            "name": "Benny",
            "slug": "benny"
        },
        ...
    }
}

These changes will be part of the next feature release.

Note-to-self when updating docs/release-notes

This is a breaking change. IDs previously obtained at created_by/updated_by/owned_by will need to instead use the id property at those locations (related_item.owned_by.id).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants