MISP/app/Controller/RolesController.php

130 lines
3.2 KiB
PHP
Raw Normal View History

<?php
App::uses('AppController', 'Controller');
/**
* Roles Controller
*
* @property Role $Role
*/
class RolesController extends AppController {
2013-04-24 15:24:39 +02:00
public $options = array('0' => 'Read Only', '1' => 'Manage My Own Events', '2' => 'Manage Organization Events', '3' => 'Manage & Publish Organization Events'); // FIXME move this to Role Model
public $components = array(
2012-12-19 02:48:53 +01:00
'Security',
2013-01-22 15:46:39 +01:00
'Session', 'AdminCrud' // => array('fields' => array('name'))
2012-12-19 02:48:53 +01:00
);
public $helpers = array('Js' => array('Jquery'));
2012-12-19 02:48:53 +01:00
public $paginate = array(
'limit' => 60,
'order' => array(
'Role.name' => 'ASC'
)
);
2012-12-19 02:48:53 +01:00
public function beforeFilter() {
parent::beforeFilter();
}
2013-01-22 16:12:36 +01:00
/**
* view method
*
* @param string $id
* @return void
2013-01-28 12:05:23 +01:00
*
* @throws NotFoundException
2013-01-22 16:12:36 +01:00
*/
public function view($id = null) {
$this->Role->id = $id;
//$this->Acl->allow($this->Role, 'controllers/Events/add');
2013-01-22 16:12:36 +01:00
if (!$this->Role->exists()) {
throw new NotFoundException(__('Invalid role'));
}
2015-08-31 02:32:37 +02:00
$this->set('premissionLevelName', $this->Role->premissionLevelName);
2013-01-22 16:12:36 +01:00
$this->set('role', $this->Role->read(null, $id));
$this->set('id', $id);
2013-01-22 16:12:36 +01:00
}
/**
* admin_add method
2012-12-19 02:48:53 +01:00
*
* @return void
*/
public function admin_add() {
if(!$this->_isSiteAdmin()) $this->redirect(array('controller' => 'roles', 'action' => 'index', 'admin' => false));
if ($this->request->is('post')) {
$this->Role->create();
if ($this->Role->save($this->request->data)) {
$this->Session->setFlash(__(sprintf('The Role has been saved.')));
$this->set('options', $this->options);
$passAlong = $this->Role->read(null, $this->Role->getInsertID());
$this->redirect(array('action' => 'index'));
} else {
if (!($this->Session->check('Message.flash'))) {
$this->Role->Session->setFlash(__(sprintf('The Role could not be saved. Please, try again.')));
}
}
}
$this->set('permFlags', $this->Role->permFlags);
$this->set('options', $this->options);
//$this->AdminCrud->adminAdd();
}
/**
* admin_index method
*
* @return void
*/
public function admin_index() {
if(!$this->_isSiteAdmin()) $this->redirect(array('controller' => 'roles', 'action' => 'index', 'admin' => false));
$this->AdminCrud->adminIndex();
$this->set('permFlags', $this->Role->permFlags);
$this->set('options', $this->options);
}
/**
* admin_edit method
*
* @param string $id
* @return void
* @throws NotFoundException
*/
public function admin_edit($id = null) {
if(!$this->_isSiteAdmin()) $this->redirect(array('controller' => 'roles', 'action' => 'index', 'admin' => false));
$this->AdminCrud->adminEdit($id);
$passAlong = $this->Role->read(null, $id);
$this->set('options', $this->options);
$this->set('permFlags', $this->Role->permFlags);
$this->set('id', $id);
}
/**
* admin_delete method
*
* @param string $id
2012-12-19 02:48:53 +01:00
*
* @throws MethodNotAllowedException
2012-12-19 02:48:53 +01:00
* @throws NotFoundException
*
* @return void
*/
public function admin_delete($id = null) {
$this->AdminCrud->adminDelete($id);
}
/**
* index method
*
* @return void
*/
public function index() {
$this->recursive = 0;
$this->set('permFlags', $this->Role->permFlags);
2013-04-24 15:24:39 +02:00
$this->set('list', $this->paginate());
$this->set('options', $this->options);
}
}