Added user access level restriction to viewing emails
This commit is contained in:
parent
a270f31009
commit
ed0ec443a3
|
|
@ -43,6 +43,18 @@ class AppController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function isManager() {
|
||||||
|
$currentuser = $this->getCurrentUser();
|
||||||
|
if($currentuser['access_level'] == 'manager') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the current logged in user.
|
* Read the current logged in user.
|
||||||
* @return array - the currently logged in user.
|
* @return array - the currently logged in user.
|
||||||
|
|
|
||||||
|
|
@ -87,19 +87,29 @@ class EmailsController extends AppController {
|
||||||
* Fetch all the Emails that are from, to, cc a User ID
|
* Fetch all the Emails that are from, to, cc a User ID
|
||||||
*
|
*
|
||||||
* @param <type> $id
|
* @param <type> $id
|
||||||
* @return <type>
|
* @return <type>
|
||||||
*/
|
*/
|
||||||
function view_user_emails($id) {
|
function view_user_emails($id) {
|
||||||
if(!$id) {
|
if(!$id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
$user = $this->Email->User->find('first', array('conditions'=>array('User.id'=>$id), 'fields'=>array('User.id','User.access_level'), 'recursive'=>0));
|
||||||
|
|
||||||
|
if($user['User']['access_level'] == 'manager' || $user['User']['access_level'] == 'admin') {
|
||||||
|
if( (!$this->isAdmin()) && (!$this->isManager()) ) {
|
||||||
|
echo "Unable to view Emails for this User. You have insufficient privileges.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//$this->set('emails', $this->paginate());
|
//$this->set('emails', $this->paginate());
|
||||||
$fromMailIDs = $this->Email->find('list', array('conditions'=>array('Email.user_id'=>$id)));
|
$fromMailIDs = $this->Email->find('list', array('conditions'=>array('Email.user_id'=>$id)));
|
||||||
$recMailIDs = $this->Email->EmailRecipient->find('list', array('conditions'=>array('EmailRecipient.user_id'=>$id),
|
$recMailIDs = $this->Email->EmailRecipient->find('list', array('conditions'=>array('EmailRecipient.user_id'=>$id),
|
||||||
'fields'=>array('EmailRecipient.email_id', 'EmailRecipient.email_id')));
|
'fields'=>array('EmailRecipient.email_id', 'EmailRecipient.email_id')));
|
||||||
|
|
||||||
// print_r($recMailIDs);
|
// print_r($recMailIDs);
|
||||||
|
|
||||||
// print_r($fromMailIDs);
|
// print_r($fromMailIDs);
|
||||||
$allIDs = $fromMailIDs + $recMailIDs;
|
$allIDs = $fromMailIDs + $recMailIDs;
|
||||||
|
|
@ -111,17 +121,17 @@ class EmailsController extends AppController {
|
||||||
|
|
||||||
|
|
||||||
$this->paginate['Email'] = array(
|
$this->paginate['Email'] = array(
|
||||||
'conditions' => array('Email.id'=>$allIDs),
|
'conditions' => array('Email.id'=>$allIDs),
|
||||||
'order'=>array('Email.udate DESC'),
|
'order'=>array('Email.udate DESC'),
|
||||||
'contain' => array('EmailRecipient', 'User'),
|
'contain' => array('EmailRecipient', 'User'),
|
||||||
'limit' => 100,
|
'limit' => 100,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$userMail = $this->paginate('Email');
|
$userMail = $this->paginate('Email');
|
||||||
//$userMail = $this->Email->find('all', array('conditions'=>array('Email.id'=>$allIDs), 'order'=>array('Email.udate DESC')));
|
//$userMail = $this->Email->find('all', array('conditions'=>array('Email.id'=>$allIDs), 'order'=>array('Email.udate DESC')));
|
||||||
$this->set('userMail', $userMail);
|
$this->set('userMail', $userMail);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -145,7 +155,7 @@ class EmailsController extends AppController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ class UsersController extends AppController {
|
||||||
|
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
|
$this->Cookie->del('Auth.User');
|
||||||
$this->redirect($this->Auth->logout());
|
$this->redirect($this->Auth->logout());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,5 +81,3 @@
|
||||||
<div id="emailTable">
|
<div id="emailTable">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php debug($user);?>
|
|
||||||
Loading…
Reference in a new issue