nette / security

🔑 Provides authentication, authorization and a role-based access control management via ACL (Access Control List)
https://doc.nette.org/access-control
Other
357 stars 40 forks source link

BackedEnum everywhere #65

Closed MartkCz closed 1 month ago

MartkCz commented 2 years ago

I use everywhere enums for roles/resources/privileges in php 8.1. it's better for maintenance than strings.

enum Roles: string implements Role
{
  case EDITOR = 'editor';

  public function getRoleId(): string
  {
      return $this->value;
  }
}

enum Resources: string implements Resource
{
  case ARTICLE = 'article';

  public function getResourceId(): string
  {
      return $this->value;
  }
}

enum ArticlePrivilege: string // implements Privilege
{
  case EDIT = 'edit';
}

only method isAllowed accepts Resource and Role objects

Proposal

1) Add interface Privilege 2) Allow passing object of Role, Resource,Privilege to methods: Permission::hasResource, Permission::allow, Permission::addRole, etc

MartkCz commented 2 years ago

I could prepare PR if it makes sense