目前,我正在审查一个laravel项目,使用Sentry进行身份验证。每条路由在Sentry创建的groups表中都有一个权限。
例如,groups表中的一行,我使用的是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中添加新的路由,但是前哨没有更新组权限时
例如,我添加了与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",
]
}我该怎么做呢?有没有什么命令或东西可以更新groups表?
发布于 2017-04-24 21:50:35
您需要手动更新该组。您可以创建页面来更新权限。
下面是用于更新组的伪代码。
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
https://stackoverflow.com/questions/43589839
复制相似问题