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

Use web standard Permissions API #3200

Merged
merged 6 commits into from
Oct 27, 2019
Merged

Use web standard Permissions API #3200

merged 6 commits into from
Oct 27, 2019

Conversation

kt3k
Copy link
Member

@kt3k kt3k commented Oct 25, 2019

This PR changes the current permissions API to the web standard Permissions API.

  • Removed op_permissions, added op_query_permission
  • Added TypeError for invalid permission name and invalid urls.
  • Added a few tests for check handlings of invalid parameters.
  • For now I keep permissions object at Deno.permissions. Maybe this should be moved to navigator.permissions later.

ref:


Partially addresses #2767.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

Nice

export class PermissionStatus {
state: PermissionState;
constructor(state: PermissionState);
}
Copy link
Member

Choose a reason for hiding this comment

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

Could you duplicate the jsdoc comments here?

(We need to fix this situation soon...)

assertEquals(perms[perm], perm === grant);
}
testPerm({ [grant]: true }, async function envGranted(): Promise<void> {
const status0 = await Deno.permissions.query({ name: grant });
Copy link
Member

Choose a reason for hiding this comment

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

Should we not just start using the global Permissions object?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. Let's move permissions under navigator and other classes to global.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe leave it for separate PR since it is apparently controversial

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry I misread the thread. OK. Let's keep it for now.

Comment on lines 23 to 25
url?: string;
path?: string;
Copy link
Collaborator

@nayeemrmn nayeemrmn Oct 25, 2019

Choose a reason for hiding this comment

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

Why not use sub types for these?

interface PermissionDescriptor {
  name: PermissionName;
}

namespace Deno {
  export interface NetPermissionDescriptor extends PermissionDescriptor {
    name: "net";
    url?: string;
  }

  // ...
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! That looks nicer. I'll update.

@nayeemrmn
Copy link
Collaborator

Like I said here #2767 (comment), putting this in navigator breaks compatibility.

What about this is supposed to work outside of deno anyway? 🙄 Happened with window.location... that should be deprecated immediately IMO.

Comment on lines 35 to 38
type PermissionDescriptor =
| SimplePermissionDescriptor
| PathPermissionDescriptor
| NetPermissionDescriptor;
Copy link
Collaborator

@nayeemrmn nayeemrmn Oct 26, 2019

Choose a reason for hiding this comment

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

👍

Opinion: I think it would be better to give each permission its own interface so they are arbitrarily extensible e.g. #3137.

Maybe read/write have a meaningful commonality but the rest aren't related to each other.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense 👍 I separated descriptor types for each permission.


export class Permissions {
query(d: PermissionDescriptor): Promise<PermissionStatus>;
revoke(d: PermissionDescriptor): Promise<PermissionStatus>;
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to have jsdoc with examples for these, since the previous API did have nice docs.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

Looking good. There's one more documentation change needed https://deno.land/std/manual.md#inspecting-and-revoking-permissions

@kt3k
Copy link
Member Author

kt3k commented Oct 27, 2019

Thank you for catching. Updated //std/manual.md.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM - thanks! Looking forward to having this in the next release

@ry ry merged commit efd7e78 into denoland:master Oct 27, 2019
@kt3k kt3k deleted the perm-api branch October 27, 2019 15:42
@kt3k kt3k mentioned this pull request Nov 8, 2019
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 21, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Feb 1, 2021
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