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

Team's hasTeamPermission behaviour differs for Web and API users #62

Closed
SeanBourke opened this issue Sep 5, 2020 · 1 comment · Fixed by #89
Closed

Team's hasTeamPermission behaviour differs for Web and API users #62

SeanBourke opened this issue Sep 5, 2020 · 1 comment · Fixed by #89

Comments

@SeanBourke
Copy link
Contributor

  • Jetstream Version: 0.6.4
  • Laravel Version: 8.0 (dev)
  • PHP Version: 7.94

Description:

Attempting to inherit team permissions to enable users to perform actions on behalf of a team, however this is prevented due to $user->tokenCan taking precedence in HasTeams.php.

Where permissions are listed in $user->teamPermissions array, a request to $user->hasTeamPermission($teams, 'existingPermission') will always return false.

Steps To Reproduce:

  1. Add user to team with Administration Permission (inheriting all team permissions)
  2. Update TeamPolicy.php to enable functions based on team permissions
public function addTeamMember(User $user, Team $team)
    {
        return $user->ownsTeam($team) || $user->hasTeamPermission($team, 'create');
    }
  1. Authenticate as user and note that permission is not inherited. Die and dump of $user->hasTeamPermission($team, 'create') will return false, whereas 'create' is included in $user->teamPermissions($team) array.
  2. Comment out code block in HasTeams.php
/*if (in_array(HasApiTokens::class, class_uses_recursive($this)) &&
            ! $this->tokenCan($permission)) {
            return false;
        }*/
  1. Authenticate as user and note that permission is now inherited. Die and dump of $user->hasTeamPermission($team, 'create') now returns true.
@SeanBourke
Copy link
Contributor Author

SeanBourke commented Sep 5, 2020

Validated that hasTeamPermission is returning the correct value where the Team Permissions are overlapped in the API permissions and the Team permissions and is requested via a generated Sanctum API token. Any requests for the same user via inertia or livewire will return false for the same check.

API
Route:
image
Response:
image

Web

dd('Permissions:' . implode($user->teamPermissions($team)) . PHP_EOL . 'Can Create:' . ($user->hasTeamPermission($team, 'read') ? 'true' : 'false'));

Response:
image

@SeanBourke SeanBourke changed the title Team's hasTeamPermission overwritten by API's tokenCan Team's hasTeamPermission not working as expected when not called from API Sep 7, 2020
@SeanBourke SeanBourke changed the title Team's hasTeamPermission not working as expected when not called from API Team's hasTeamPermission behaviour differs for Web and API users Sep 8, 2020
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