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

Introduces Permissions to the core. #78

Merged
merged 7 commits into from
Jan 19, 2017
Merged

Introduces Permissions to the core. #78

merged 7 commits into from
Jan 19, 2017

Conversation

Vassyli
Copy link
Contributor

@Vassyli Vassyli commented Nov 1, 2016

Adds a permission model, a manager, as well as traits and interfaces required for models who want to implement permissions.

Every actor has many permission associations, every permission association references a permission as well as a state. This results in ternary permission system:

  • Allowed (actor has a permission association for this permission id, with state = Allowed)
  • Denied (actor has a permission association for this permission id, with state = Denied)
  • Undefined/Not set (actor has not a permission association for this permission id).

This is later important if a crate wants to implement a multi-layered permission system with groups and inheritance.

namespace LotGD\Core\Models;

/**
* Implement this interface if an entity has associates permissions.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "has associated permissions"

@austenmc
Copy link
Contributor

austenmc commented Nov 2, 2016

Good observation about supporting inherited permissions.

const Denied = -1;

const Superuser = "lotgd/core/superuser";
const AddScenes = "lotgd/core/scene/add";
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these scene/character-based permissions should be added as part of the scene or character class.

@@ -47,6 +47,7 @@
$libraryConfigurationManager = new LibraryConfigurationManager($composerManager, getcwd());
$directories = $libraryConfigurationManager->getEntityDirectories();
$directories[] = implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'src', 'Models']);
$directories[] = implode(DIRECTORY_SEPARATOR, [__DIR__, 'Ressources', 'TestModels']);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "Resources"

}
}

public function hasPermission(string $permissionId): bool
Copy link
Contributor

Choose a reason for hiding this comment

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

hasPermissionSet is clearer that it's a presence flag. hasPermission sounds like "Do I have permission?" which sounds like "Is allowed?".

@austenmc
Copy link
Contributor

austenmc commented Nov 2, 2016

I'm concerned there is some unnecessary complexity here that will cause problems for the noob coders we expect to be writing permission checks.

  1. In the current PR, there are two ways to check for a permission: one is through the PermissionManager and one is through the actor class. It's hard to know, just from reading the APIs of User and PermissionManager, which one to use.
  2. Presumably, the cause of (1) is b/c you want to have permissionable entities that aren't Users, like maybe Groups? Are there any other entities you think will implement PermissionableInterface? I can imagine maybe modules have permissions, if you want to establish stronger boundaries between the code you pull in off the web. I'm not sure how useful this is honestly, or whether it's worth the complexity. What if we restricted permissions to be only for Users, then you check permissions via the Manager, and the manager implements a hook that can support Groups via a module.

Open to your thoughts here.

@Vassyli
Copy link
Contributor Author

Vassyli commented Nov 3, 2016

Yes, that's what I intended. Now that you mention it, there is not really much anything besides User and Groups that might use this. I didn't even think about modules. Maybe bots, but they could easily just be a User instead.

I will refactor the Permissionable trait to an abstract Actor model class instead. Also, I will provide a PermissionGroup Interface that the PermissionManager can understand and work with it, as well as add events at least to "isAllowed" and "isDenied".

Alternatively, instead of events I could introduce a GroupableInterface that a User entity might or might not implement whose only function returns a PermissionGroup. Or additionally to the events.

Thoughts?

@austenmc
Copy link
Contributor

Still planning on working on this?

As far as your question is concerned, I would still with something simple, just the events, for now. We're losing steam at this point :) so I say we push toward some kind of MVP.

@Vassyli
Copy link
Contributor Author

Vassyli commented Jan 2, 2017

Yes, I'm still planning, just didn't find time to sit down and get it right.

@Vassyli Vassyli force-pushed the feature/permissions branch from 6ef2252 to 6f2f88d Compare January 2, 2017 15:20
abstract class Actor
{
/** @var array Associations between permission-id and PermissionAssociation entity. */
private $_permissions = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is prefixing private vars with _ in a style guide somewhere? Is that common in PHP?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it's not. I need to get rid of it, that's something that carried over from python - thanks for pointing it out.

use LotGD\Core\Models\Permission;

/**
* The PermissionManager manages (checks and manipulates) of actors.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "manipulates) permissions of actors"

* The PermissionManager class provides methods to work with permissions and is
* the only way to check and manipulate permissions. It can be used to create or
* delete permissions, to remove, allow or deny permissions to actors and to
* check whether an actor has a certain permission or if it is explicitely
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: explicitly
nit: denied to him

use Doctrine\ORM\Mapping\Table;

use Lotgd\Core\Models\Actor;
#use LotGD\Core\Models\PermissionableInterface;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the commented out code?

@Vassyli Vassyli force-pushed the feature/permissions branch from 6f2f88d to e82e72a Compare January 19, 2017 09:33
@Vassyli Vassyli merged commit e82e72a into master Jan 19, 2017
@Vassyli Vassyli deleted the feature/permissions branch January 21, 2017 15:13
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.

2 participants