Skip to content
This repository has been archived by the owner on Sep 13, 2021. It is now read-only.

api handles chart access authorization only, the rest is done by plugins #155

Merged
merged 5 commits into from
Apr 29, 2020

Conversation

gka
Copy link
Member

@gka gka commented Apr 29, 2020

}
}
// user is authorized to access chart
// further authoritzation is handled by plugins

Object.assign(payload, params);
try {
const result = await events.emit(
Copy link
Contributor

@sto3psl sto3psl Apr 29, 2020

Choose a reason for hiding this comment

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

After looking at the changes in export-{pdf|zip} we need to change the way results are handled here.

Before the changes, the mentioned plugins threw errors when they can't handle a format. That caused results to look something like this:

const results = [
  { status; 'error', error: 'cant handle format' }, // export-zip
  { status: 'success', data: ... }, // export-pdf
]

Then the successful event was used further.

Now plugins just return undefined and the result looks like this:

const results = [
  { status: 'success', data: undefined }, // export-zip
  { status; 'success', data: ... } // export-pdf
]

Again the first successful event is used. Plugin results appear in the order they are configured and called. With format pdf this would be a problem in my example.

By throwing in the plugins there was always only 1 successful result, the result of the plugin that implemented the corresponding format.

Now without throwing we need to filter based on the returned data.

I implemented it that way because it's common in Hapi to throw Errors in certain conditions and I'm aware that this might be controversial.

Copy link
Contributor

@sto3psl sto3psl Apr 29, 2020

Choose a reason for hiding this comment

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

A further improvement could be that the ApiEventEmitter automatically filters results with data: undefined.

Copy link
Member Author

@gka gka Apr 29, 2020

Choose a reason for hiding this comment

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

I see. I changed the filter to success and use .find() to look for a result with data in 8b2d63b

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. I think that was the only thing left. Going to approve the PRs.

@gka gka force-pushed the export-chart-auth branch from c438f95 to b78934f Compare April 29, 2020 13:04
@gka gka merged commit 0dea280 into publish Apr 29, 2020
davidkokkelink added a commit that referenced this pull request May 1, 2020
@davidkokkelink davidkokkelink deleted the export-chart-auth branch May 1, 2020 14:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants