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 policy actions to be defined via class methods only #43

Closed
chrisalley opened this issue Jul 15, 2023 · 2 comments
Closed

Allow policy actions to be defined via class methods only #43

chrisalley opened this issue Jul 15, 2023 · 2 comments
Assignees

Comments

@chrisalley
Copy link
Collaborator

Following the discussion in #41, it would be simpler to be able to define actions without explicitly defining an actions map, e.g.

class PostPolicy extends Policy {
  user: AuthorisableUser
  record: AuthorisablePost

  constructor(user: AuthorisableUser, record: AuthorisablePost) {
    super(user, record)
  }

  view(): boolean {
    return true
  }

  publish(): boolean {
    return this.user.id === this.record.userId
  }

  destroy(): boolean {
    return this.user.isAdmin
  }
}
@johno
Copy link
Collaborator

johno commented Jul 18, 2023

100% agree there!

@chrisalley
Copy link
Collaborator Author

Solved in #48 and #49.

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

No branches or pull requests

2 participants