【问题标题】:laravel sentry not update groups permissions entry in groups tablelaravel sentry 不更新组表中的组权限条目
【发布时间】:2017-09-21 05:43:07
【问题描述】:

目前我正在审查一个 laravel 项目,使用 Sentry 进行身份验证。每个路由都将在 Sentry 创建的组表中具有权限。

例如分组表中的一行,我使用的是 mongodb

{
  "name": "Admins",
  "permissions": "{\"task1.create\":1,\"task1.edit\":1,\"task1.delete\":1}",
  "created_at": ISODate("2015-10-22T01:16:57.118Z"),
  "user_ids": [
    "547c2b5aabb1ce1752318f27",
    "54d82fa1e471f7cf438b4569",
  ]
}

当我在 routes.php 中添加新路由但 Sentry 没有更新组权限时

例如,我添加了与task1相同的task2,并且我希望groups表看起来像

{
      "name": "Admins",
      "permissions": "{\"task1.create\":1,\"task1.edit\":1,\"task1.delete\":1,\"task2.create\":1,\"task2.edit\":1,\"task2.delete\":1}",
      "created_at": ISODate("2015-10-22T01:16:57.118Z"),
      "user_ids": [
        "547c2b5aabb1ce1752318f27",
        "54d82fa1e471f7cf438b4569",
      ]
    }

我该怎么做,有什么命令或东西可以更新组表吗?

【问题讨论】:

    标签: php mongodb laravel sentry


    【解决方案1】:

    您需要手动更新组。您可以创建页面来更新权限。

    这是更新组的伪代码。

    try
    {
        // Find the group using the group id
        $group = Sentry::findGroupById(1);
    
        // Update the group details
        $group->name = 'Users';
        $group->permissions = array(
            'admin' => 1,
            'users' => 1,
        );
    
        // Update the group
        if ($group->save())
        {
            // Group information was updated
        }
        else
        {
            // Group information was not updated
        }
    }
    catch (Cartalyst\Sentry\Groups\NameRequiredException $e)
    {
        echo 'Name field is required';
    }
    catch (Cartalyst\Sentry\Groups\GroupExistsException $e)
    {
        echo 'Group already exists.';
    }
    catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e)
    {
        echo 'Group was not found.';
    }
    

    更多信息请查看手册:https://cartalyst.com/manual/sentry/2.1#example-8

    【讨论】:

    • 虽然它更新了数据库中的组表,但它没有更新视图。它缓存在某个地方吗?
    猜你喜欢
    • 2014-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 2023-02-09
    相关资源
    最近更新 更多