raoul2000 / yii2-workflow

A simple workflow engine for Yii2
BSD 3-Clause "New" or "Revised" License
171 stars 48 forks source link

Unsafe attributes #21

Closed Faryshta closed 8 years ago

Faryshta commented 8 years ago

How can I declare an attribute as unsafe? That means it can be massively assigned using the Model::load() method.

Regulary if I want the 'paymet_method' to only be asigned during 'select-payment'. The code looks like this.

public function rules()
{
    return [['!payment_method'], 'safe', 'except' => 'select-payment'];
}

Unfortunately workflow makes its own behaviors and they won't work during the load() execution

public function rules()
{
    return [['!payment_method'], 'safe', 'except' => WorkflowScenario::enterStatus('select-method')];
}

This one won't work since the scenario only exists during transitions, not during loading.

raoul2000 commented 8 years ago

Hi, you are right, massive assignements and safe/unsafe rule is not handled by the dynamic workflow scenario which has only been designed to handle attribute validations. Transition driven Validation is triggered by the BEFORE_VALIDATE event but as there is no such thing for assignement, I don't see how it could be implemented. I hope you'll be able to find a workaround ...

ciao

Faryshta commented 8 years ago

thats a helpful response. i will have to figure something for that.