目前,我正在审核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没有更新组权限
例如,我添加task2和task1相同,我希望组表看起来像
{
"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",
]
}
我该怎么做,是否有任何命令或更新组表的内容?
答案 0 :(得分:0)
您需要手动更新群组。您可以创建页面以更新权限。
以下是更新组的伪代码。
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