spatie / laravel-permission

Associate users with roles and permissions
https://spatie.be/docs/laravel-permission
MIT License
12.04k stars 1.76k forks source link

User does not have the right permissions. Necessary permissions are ... #2286

Closed xx1196 closed 1 year ago

xx1196 commented 1 year ago

i create a laravel 9 project, but when i check de permissions this always return false, i use the method $this->middleware('permission:opportunities.index|opportunities.index_me|opportunities.index_me_assigns')->only('index'); , in laravel 8 this works, but in laravel 9 this alwys return false

Versions You can use composer show to get the version numbers of:

PHP version: 8.1.10 Database version:

i reate de route api and in the controller have public function __construct() { $this->middleware('permission:opportunities.index|opportunities.index_me|opportunities.index_me_assigns')->only('index'); } in the request this fails with the menssage {"data":{"error":"User does not have the right permissions. Necessary permissions are opportunities.index, opportunities.index_me, opportunities.index_me_assigns","code":500}}

Environment (please complete the following information, because it helps us investigate better):

this my dockerfile FROM php:8.1-fpm

Install system dependencies

RUN apt-get update && apt-get install -y libpq-dev \ git \ curl \ libpng-dev \ libonig-dev \ libxml2-dev \ libzip-dev \ zip \ unzip

Add Node 12 LTS

RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -- \ && apt-get install -y nodejs \ && apt-get autoremove -y

Clear cache

RUN apt-get clean && rm -rf /var/lib/apt/lists/*

Install PHP extensions

RUN docker-php-ext-install zip pdo pdo_pgsql pgsql mbstring exif pcntl bcmath gd RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql

Get latest Composer

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

Create system user to run Composer and Artisan Commands

TO DO change user

RUN useradd -G www-data,root -u 1000 -d /home/xx1196 xx1196 RUN mkdir -p /home/xx1196/.composer && \ chown -R xx1196:xx1196 /home/xx1196

Memory Limit

RUN echo "memory_limit=-1" > $PHP_INI_DIR/conf.d/memory-limit.ini

size upload

RUN echo "upload_max_filesize = -1" > $PHP_INI_DIR/conf.d/upload-max-filesize.ini RUN echo "post_max_size = -1" > $PHP_INI_DIR/conf.d/post-max-size.ini

Set working directory

WORKDIR /var/www

WORKDIR /var/www COPY . /var/www

RUN chown -R xx1196:xx1196 . RUN chmod 755 .

RUN rm -f package-lock.json RUN npm i RUN npm run prod RUN composer install

RUN php artisan optimize

RUN php artisan migrate

TO DO genera ficheos para firmar

RUN php artisan translations:export -A

RUN php storage.php

RUN chmod -R 777 /var/www/storage RUN chmod -R 777 /var/www/storage/app RUN chmod -R 777 /var/www/storage/app/public

RUN chmod -R 777 /var/www/storage/app/public/*

RUN chmod -R 777 /var/www/resources/lang/ RUN chmod -R 777 /var/www/resources/lang/en/.php RUN chmod -R 777 /var/www/resources/lang/en/.php

RUN php artisan cache:forget spatie.permission.cache CMD php artisan serve --host=0.0.0.0 --port=80

EXPOSE 80

TO DO user v

USER xx1196

this my composer json: { "name": "xx1196/test", "type": "project", "description": "", "keywords": [ "framework", "laravel" ], "license": "MIT", "require": { "php": "^8.1", "assada/laravel-achievements": "^2.5", "aws/aws-sdk-php": "^3.255", "barryvdh/laravel-dompdf": "^2.0", "barryvdh/laravel-translation-manager": "^0.6.3", "coderello/laravel-passport-social-grant": "^3.0", "doctrine/dbal": "^3.5", "fruitcake/laravel-cors": "^3.0", "google/apiclient": "^2.13", "guzzlehttp/guzzle": "^7.5", "kreait/laravel-firebase": "^4.2", "laravel-notification-channels/fcm": "^2.6", "laravel/cashier": "^14.5", "laravel/framework": "^9.45", "laravel/passport": "^11.3", "laravel/sanctum": "^3.0", "laravel/socialite": "^5.5", "laravel/tinker": "^2.7", "laravel/ui": "^4.1", "league/flysystem-aws-s3-v3": "^3.10", "owen-oj/laravel-getid3": "^2.1", "phpoffice/phpspreadsheet": "^1.26", "predis/predis": "^2.0", "ramsey/uuid": "^4.7", "sendgrid/sendgrid": "^8.0", "sentry/sentry-laravel": "^3.1", "spatie/laravel-google-calendar": "^3.5", "spatie/laravel-permission": "^5.7", "tightenco/ziggy": "^1.5" }, "require-dev": { "fakerphp/faker": "^1.9.1", "laravel/pint": "^1.0", "laravel/sail": "^1.0.1", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^6.1", "phpunit/phpunit": "^9.5.10", "spatie/laravel-ignition": "^1.0", "pestphp/pest-plugin-laravel": "^1.3" }, "autoload": { "psr-4": { "App\": "app/", "Database\Factories\": "database/factories/", "Database\Seeders\": "database/seeders/" } }, "autoload-dev": { "psr-4": { "Tests\": "tests/" } }, "scripts": { "post-autoload-dump": [ "Illuminate\Foundation\ComposerScripts::postAutoloadDump", "@php artisan package:discover --ansi" ], "post-update-cmd": [ "@php artisan vendor:publish --tag=laravel-assets --ansi --force" ] }, "extra": { "laravel": { "dont-discover": [] } }, "config": { "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true, "allow-plugins": { "pestphp/pest-plugin": true } }, "minimum-stability": "dev", "prefer-stable": true }

parallels999 commented 1 year ago

Make a debug, and feel free to make a PR if you think that is a bug

xx1196 commented 1 year ago

image

in tinker the can method is true when have the permission, but in the middleware has_permission in code have a false when check the equals permission, any idea?

erikn69 commented 1 year ago

Maybe you are mixing guard names