yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

RBAC module uses yii queries instead of active record #6840

Closed Faryshta closed 9 years ago

Faryshta commented 9 years ago

This is more a question than an issue since it works fine by now.

Why does the yii\rbac\DbManager class uses yii queries instead of yii\db\ActiveRecord models? The DbManager handles all the inserts, updates, deletes and selects by creating Query classes instead of using active record models.

Is there a reason behind this?

I think it would be easier to extend if RBAC functionality if it used activerecord models.

The hardest part I can think for the models would be the tableName method which is configured by the DbManager but thats easily solved

public function tableName() {
      return Yii::$app->getAuthManager()->assignmentTable;
}
cebe commented 9 years ago

duplicate of #570

Faryshta commented 9 years ago

Cebe thanks for the link to the discussion. it looks like everyone agrees that activerecord is a better approach. I have a few advancements on this issue, should i submit a patch?

cebe commented 9 years ago

what kind of advancements?

Faryshta commented 9 years ago

yii\rbac\BaseModel that checks the configuration on init to see if the authManager component is configured to use and DbManager instance.

Then gii generated models extending the BaseModel. i want to add a bit or recursive support for things like see all the permissions for a user and all the children/parents of an item but that is still not done.

And rewrite some of the DbManager classes to use the models instead of queries. I haven't completed this yet but i think i can submit the pull request and keep working till its done or get feedback on what to get better

Faryshta commented 9 years ago

The branch is up on my git fork.

https://github.com/Faryshta/yii2/compare/yiisoft:master...Faryshta:activeRecordRBAC

I will rewrite the DbManager class now but I think the models are completed.

cebe commented 9 years ago

You can open a PR when you are done with that. We can discuss it then.