Closed punani3000 closed 4 years ago
Hi Dirk, does that happen with the latest version?
On Thu, 5 Dec 2019 at 11:49 PM, punani3000 notifications@github.com wrote:
Hi,
I found another bug: console commands don't work if the plugin is active. I get the following error:
Exception 'TypeError' with message 'Argument 3 passed to thejoshsmith\fabpermissions\services\Fab::canViewField() must be an instance of craft\web\User, instance of craft\console\User given, called in /www/site/vendor/thejoshsmith/craft-fab-permissions/src/services/Fields.php on line 32'
When I add the following in to line 32 in the file src/services/Fields.php console commands work fine: if(Craft::$app->request->getIsConsoleRequest()) return $fields;
Thanks, Dirk
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/thejoshsmith/craft-fab-permissions/issues/13?email_source=notifications&email_token=ABKCPKZKVUHSTSFZ4GY2RYLQXDMDTA5CNFSM4JVXUT32YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4H6JDBPQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKCPK6KHWV77N35LK3LZOLQXDMDTANCNFSM4JVXUT3Q .
Closing due to inactivity.
I have this same issue. It is because when running on the console the object returned by Craft::$app->getUser()
is craft\console\User
and not craft\web\User
. Unfortunately, there is not a common interface or ancestor except Component
.
You could probably do something like this:
use craft\console\User as ConsoleUser;
use craft\web\User as WebUser;
...
* @param ConsoleUser|WebUser $user User object
...
public function canViewTab(FieldLayoutTab $tab, $user, $currentSite = null)
{
if( $user->getIsAdmin() ) return true;
if( $user->getIsGuest() ) return false;
That being said, I am currently only running the console as admin and do not foresee needing to run as anything else. In that case, the easiest fix is to just move the fields service config to app.web.php
so it is not used in the console.
Hi,
I found another bug: console commands don't work if the plugin is active. I get the following error:
Exception 'TypeError' with message 'Argument 3 passed to thejoshsmith\fabpermissions\services\Fab::canViewField() must be an instance of craft\web\User, instance of craft\console\User given, called in /www/site/vendor/thejoshsmith/craft-fab-permissions/src/services/Fields.php on line 32'
When I add the following in to line 32 in the file
src/services/Fields.php
console commands work fine:if(Craft::$app->request->getIsConsoleRequest()) return $fields;
Thanks, Dirk