我正在使用访问控制过滤器进行访问管理,但无法完成一件事 - 例如,我怎样才能只允许项目经理更新项目并禁止其他人使用?我通过 matchCallback 进行了尝试,但在这种情况下,所有项目经理都可以更新任何项目,因为返回 TRUE。
类似的更经常需要的规则 - 如何允许用户使用 ACF 更新/删除他是作者的帖子?
'access' => [
'class' => AccessControl::className(),
'only' => ['index', 'view', 'create', 'update', 'delete'],
'rules' => [
[
'actions' => ['update'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return Yii::$app->user->identity->getProjectParticipants()
->one()->isManager(Yii::$app->user->identity->id);
}
],
],
],