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

Accountability object not available in activity hooks #17266

Open
ernst86913 opened this issue Jan 22, 2023 · 9 comments
Open

Accountability object not available in activity hooks #17266

ernst86913 opened this issue Jan 22, 2023 · 9 comments

Comments

@ernst86913
Copy link
Contributor

Describe the Bug

Custom Claims / custom accountability are a great feature of Directus. Unfortunately the (custom) accountability object is not passed through to activity hooks - where it would actually be needed for auditing purposes. Therefore it’s not possible to track activities based on custom claims / custom accountability.

To Reproduce

Write a custom claim, use custom claim information to enhance accountability object… listen to activity hooks… accountability object is always empty.

Errors Shown

No response

What version of Directus are you using?

9.22.3

What version of Node.js are you using?

6.14

What database are you using?

15

What browser are you using?

Chrome

How are you deploying Directus?

Docker

@github-actions
Copy link

Linear: ENG-552

@br41nslug
Copy link
Member

As a side note: Are you sure thats "nodejs 6.14"? because that is far below the supported version of LTS (which is 18.x currently)

@rijkvanzanten
Copy link
Member

@ernst86913 Can you share a minimal reproduction of a hook where you'd expect this to happen?

@ernst86913
Copy link
Contributor Author

@rijkvanzanten Having a look at the central items service, there are 3 calls of the ACTIVITY SERVICE... example:

			const activity = await activityService.createOne({
				action: Action.CREATE,
				user: this.accountability!.user,
				collection: this.collection,
				ip: this.accountability!.ip,
				user_agent: this.accountability!.userAgent,
				origin: this.accountability!.origin,
				item: primaryKey,
			});

Unfortunately in those calls the ACCOUNTABILITY object is not past over to the activityService... when the activityService emits a filter event after it is called (which I am listening to) I cannot use the accountability information to enrich the activity record with additional information like account information, division information, department information,........ which I later want to use to give access rights to activity logs e.g. to each business division....

So... my proposal would be to simply add the accountability to the activityService call... which can then be used to include it in the activity filter emit.

@br41nslug
Copy link
Member

Not quite sure why i set it as improvement yesterday 😅 but i can confirm accountability is always null in any activity event independent of custom claims. Tested with this hook extension:

module.exports = function ({ filter }, {}) {
    filter('activity.create', function (input, meta, ctx) {
        console.log('accountability', ctx.accountability);
        return input;
    });
    filter('activity.update', function (input, meta, ctx) {
        console.log('accountability', ctx.accountability);
        return input;
    });
    filter('activity.delete', function (input, meta, ctx) {
        console.log('accountability', ctx.accountability);
        return input;
    });
}

@ernst86913
Copy link
Contributor Author

BTW - just had a look at revisions... same there as well...

@ernst86913
Copy link
Contributor Author

@br41nslug Hi - can you please also have a look at revisions? Or should I open a separate issue for it ?

@br41nslug
Copy link
Member

br41nslug commented Jan 24, 2023

Have a look at that PR i created, revisions are included in that 😄 Or did you mean in a place i have missed?

@ernst86913
Copy link
Contributor Author

ernst86913 commented Jan 24, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

3 participants