限制邮政路线

时间:2017-07-12 11:48:20

标签: mojolicious

在Mojolicious应用程序中使用此代码:

my $svc = $authorized->under('/cleaning')->to('Login#has_role', roles_allowed =>  ['office', 'booking', 'reception']);
$svc->post('/new')       ->name('create_svc')->to('Cleaning#create'); 
$svc->get ('/edit/:id')  ->name('edit_svc')  ->to('Cleaning#edit');
$svc->post('/edit/:id')  ->name('update_svc')->to('Cleaning#update');

update_svc路由限制为办公室预订的最基本,最简单的方法是什么?换句话说:具有 office 预订角色的所有用户都应该能够发送更改的帖子请求,而 cleaning 用户应该只能查看表格。

1 个答案:

答案 0 :(得分:0)

我自己找到了这个解决方案:

my $svc_read  = $authorized->under('/cleaning')->to('Login#has_role', roles_allowed =>  ['office', 'booking', 'reception']);
my $svc_write = $authorized->under('/cleaning')->to('Login#has_role', roles_allowed =>  ['office', 'booking']);

$svc_write->post('/new')     ->name('create_svc')->to('Cleaning#create'); 
$svc_read ->get('/edit/:id') ->name('edit_svc')  ->to('Cleaning#edit');
$svc_write->post('/edit/:id')->name('update_svc')->to('Cleaning#update');

但是,如果您的应用中已经有许多获取/发布路由,那么可能会有更多通用解决方案更好用。