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

Refactor browserContext.grantPermissions #1075

Merged
merged 9 commits into from Oct 23, 2023
Merged

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Oct 18, 2023

What?

This refactors the browserContext.grantPermissions implementation.

Why?

This helps bring it inline with current ways of implementing the APIs:

  1. Parsing the options in a new parsed type.
  2. Returning an error instead of panicking.
  3. Explicit errors when a permission is invalid/unrecognised.
  4. Working with goja in the mapping layer and not in the business logic.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

Prerequisite to working on #443

@ankur22 ankur22 force-pushed the refactor/grantPermissions branch 3 times, most recently from b8e6390 to 08e7912 Compare October 18, 2023 16:50
ka3de
ka3de previously approved these changes Oct 19, 2023
Copy link
Collaborator

@ka3de ka3de left a comment

Choose a reason for hiding this comment

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

LGTM 👏

inancgumus
inancgumus previously approved these changes Oct 19, 2023
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

Nice work 👍 It's a good step towards #271 and #1064. Thanks! Some minor suggestions. Feel free to skip.

browser/mapping.go Outdated Show resolved Hide resolved
common/browser_context.go Outdated Show resolved Hide resolved
common/browser_context.go Outdated Show resolved Hide resolved
common/browser_context_options.go Outdated Show resolved Hide resolved
common/browser_context_options.go Outdated Show resolved Hide resolved
common/browser_context_options.go Outdated Show resolved Hide resolved
tests/browser_context_test.go Show resolved Hide resolved
ka3de
ka3de previously approved these changes Oct 20, 2023
Copy link
Collaborator

@ka3de ka3de left a comment

Choose a reason for hiding this comment

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

LGTM.

ankur22 and others added 9 commits October 23, 2023 11:05
This change aligns the options parsing with the other APIs.
Instead of panicking in grantPermissions we should return an error to
prevent unnecessary panics.
This moves the goja value parsing into the mapping layer so that we're
removing goja from the browserContext business logic, which makes the
code a bit more maintainable.
This change makes it explicit when a permission is used that the module
doesn't recognise, allowing the user to fix the mistake quickly instead
of having to debug the issue if the module just hid the invalid
permissions.
Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
Copy link
Collaborator

@ka3de ka3de left a comment

Choose a reason for hiding this comment

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

LGTM.

@ankur22 ankur22 merged commit ca8adca into main Oct 23, 2023
17 checks passed
@ankur22 ankur22 deleted the refactor/grantPermissions branch October 23, 2023 14:07
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.

None yet

3 participants