-
Notifications
You must be signed in to change notification settings - Fork 38
Enh: Аdjust access to save the relation #66
Comments
I did it as optional feature, see pull request. public function behaviors()
{
return [
'saveRelations' => [
'class' => SaveRelationsBehavior::class,
//...
'checkRelationsSafe' => true,// <--
],
];
} That's all. Now only safe relation will be saved. Аdjust public function rules()
{
return [
//...
[['company','users','projectLinks'], 'safe'],//other safe relations
];
}
public function scenarios()
{
$s = parent::scenarios();
if(Yii::$app->user->can('admin')){//your access condition
$s[self::SCENARIO_DEFAULT][] = 'tags';
}
return $s;
} |
Hi @sokollondon Thank you for your Pull Request. I'm wondering why you could not configure relations like this: public function behaviors()
{
$relations = [
'company',
'users',
'contacts',
'images',
'links' => ['scenario' => Link::SCENARIO_FIRST],
'projectLinks' => ['cascadeDelete' => true]
];
if (Yii::$app->user->can('admin')) {
$relations['tags'] = [
'extraColumns' => function ($model) {
/** @var $model Tag */
return [
'order' => $model->order
];
}
];
}
return [
'saveRelations' => [
'class' => SaveRelationsBehavior::className(),
'relations' => $relations
],
];
} Isn't this would be the same as what you're trying to do in the first place? |
@sokollondon |
Thanks for the answer @juban =)
if(Yii::$app->user->can('admin') && $this->type_id == 1){
//...
} But in
|
Is there such a functional?
For example, I need adjust access. So that only the
admin
could save relationtags
But relation
tags
save anyway when$project->save();
The text was updated successfully, but these errors were encountered: