RBAC failing probably due to cache

I just pushed some changes from localhost to a staging (pre-production) server. I began testing and tried to access a restricted action prior to running the migration to update the rbac tables, so it failed. I have now updated the rbac tables, but I cannot make it pass.

There shouldn’t be anything wrong with the rule as it works fine on localhost. I’m thinking it’s a caching issue. I’m seeing this in the log: yii\rbac\DbManager::checkAccessFromCache.

But how can I clear the cache if indeed that’s the issue? I’ve tried yii cache-flush-all from the console, but that doesn’t help. I only have FileCache enabled.

if (!$group->canUpdateOwn()) {
    throw new NotFoundHttpException;
}
class MyGroupRule extends Rule
{
    public $name = 'isGroupOwner';

    public function execute($user, $item, $params)
    {
        return isset($params['Group']) ? $params['Group']->user_id === $user : false;
    }
}

Hi @mcki0127,

Yes, you need to clear (invalidate) the cache.

        $manager = Yii::$app->authManager;
        $manager->invalidateCache();

I also tried to clear the cache from the console or from the migrations, but I couldn’t manage to do it. So I ended up making a dedicated action for it in the backend.

1 Like

That was it. Thanks! I have flush-all in the backend (production only). I’ll add this one to it.

1 Like