Giter Club home page Giter Club logo

Comments (2)

robregonm avatar robregonm commented on August 28, 2024

Hi,
I'm not sure... It doesn't make much sense (from the OOP point of view)... what you might mean is "getRoles()",... and also, it doesn't make sense to have and "$id" param in that function... because the class instance IS the user itself.
So for this case, I agree having only one function called "getRoles" which returns an array containing all the permissions/roles for the active user (no $id param).

Regarding the function getRoleArray() looks fine, however, the array-to-string conversion should be work for the developer, because not all the developers need to format the resulting array into a comma separated string, you might want to format it using your own style. So, in that case, the "getRoles" functions is enough.

IMHO The other functions need some review. I'm not so sure of having the "setRoles" function, because you might want to append a single permission, and every time you want to add/remove a permission, the DB processing will be slow (because it will rewrite all the permissions again).

from yii2-auth.

cansozeri avatar cansozeri commented on August 28, 2024

Do you have any suggestion to add the role without SetRole function to database ?? How can we do this with a simple way ?? Because model->save is not work, when I tried it gives me error .. I think we should done this with a seperate function ...

And yes the id is useless, I have forgot it there because I have tested something else, the function actually like this ..

public function getRole()
    {
        /** @var \yii\rbac\DbManager $authManager */
        $authManager = Yii::$app->get('authManager');


        $Ridentity = $authManager->getRolesByUser($this->id);



        if($Ridentity)
        {
            foreach ($Ridentity as $item)
            {
               $role[$item->name] = $item->name;

            }
        }
        else
        {
            $role=null;
        }


        return $role;

    }

We need getRoleTypes function too, because there is no role when we create a user, and to be selected and attached to a user we need to return the role types from the database...

public function getRoleTypes()
    {
        /** @var \yii\rbac\DbManager $authManager */
        $roller = Yii::$app->get('authManager')->getRoles();

        foreach ($roller as $item)
        {
           $role[$item->name] = $item->name;

        }


        return $role;
    }

from yii2-auth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.