您可以edit
在EventsController
. 找到事件的区域,然后检查登录的编辑器是否是该区域的编辑器。您需要做的就是确保当用户登录时,他/她的角色保存在AuthComponent
的会话中。例如:
public function edit($event_id = null) {
if($this->Auth->user('role') == "editor") {
// User is logged in as editor, check if the Event region matches his regions.
$event = $this->Event->findById($event_id); // Get the event
$user = $this->Event->User->findById($this->Auth->user('id')); // Get the user (Assuming an Event belongsTo user, otherwise you'll have to load the model first).
if(!array_search($event['Event']['region_id'], $user['User']['Region'])) {
// The event's region wasn't found in the Regions for the User, deny access
$this->Session->setFlash(__('You are not authorized to edit this event.'));
$this->redirect(array('action' => 'view', $event_id));
}
}
}
所以基本上在你做任何其他逻辑之前,你检查用户是否是编辑器,如果是,他关联的区域是否与当前事件的区域匹配。如果它没有设置一个 flash 消息并且用户被踢回view
事件的视图。