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

Allow number as valid type of role #93

Open
vegerot opened this issue Nov 20, 2020 · 0 comments · May be fixed by #94
Open

Allow number as valid type of role #93

vegerot opened this issue Nov 20, 2020 · 0 comments · May be fixed by #94

Comments

@vegerot
Copy link

vegerot commented Nov 20, 2020

Context:

I want to be able to define the roles in my application as a const enum in TypeScript like so

const enum ACRolesEnum {
  blocks,
  event,
  holidays,
  photos
}

const enum RoleTypes {
  User,
  Admin,
  Developer,
  Scheduler
}

roles
  .grant(RoleTypes.User)
    .readOwn(��ACRolesEnum.photos)
    .readOwn(ACRolesEnum.event)
  .grant(RoleType.Developer)
    .readAny(ACRolesEnum.photos)
.lock()

Problem:

However, Typscript enums use numbers by default, and .read, .update, etc. only accept string | string[]. (and .grant also accepts IAccessInfo)

Proposal:
I've read through a lot of the code that uses these roles, and I can't see any reason we couldn't also accept number | number[] as part of it.

Workaround:
Use string enums instead, like

const enum ACRolesEnum {
  blocks = 'blocks',
  event = 'event',
}
vegerot added a commit to vegerot/accesscontrol that referenced this issue Nov 20, 2020
In some cases it makes sense to have `number`s instead of `string`s for
role types.  For example, when using `enum`s in TypeScript

Fixes onury#93
vegerot added a commit to vegerot/accesscontrol that referenced this issue Nov 20, 2020
In some cases it makes sense to have `number`s instead of `string`s for
role types.  For example, when using `enum`s in TypeScript

Fixes onury#93
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 a pull request may close this issue.

1 participant