• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Can I do a permission check in PreDispatch?

Jaxel

Well-known member
#1
I have a public controller... each function of it, has their own little permissions. But there is also a global permission which must be true in order to do any of the functions. Do I need to check this global permission in every single function? Or can I do it in a preDispatch? I am trying using the following code below, but it doesn't seem to fire. If I move this permission check into each function, it works, but I would rather keep the redundancy down.
PHP:
public function _preDispatch($action)
{
	parent::_preDispatch($action);

	$this->perms = $this->getModelFromCache('EWRmedio_Model_Perms')->getPerm();

	if (!$this->perms['view']) { return $this->responseNoPermission(); } // ???
}
 

Mike

XenForo developer
Staff member
#2
You can do that, but you can't return from that function - you need to throw an exception:

throw $this->responseException($this->responseNoPermission());

For example, though there's actually a method that combines those 2 calls... :)
 
R

ragtek

Guest
#3
You can do that, but you can't return from that function - you need to throw an exception:

throw $this->responseException($this->responseNoPermission());

For example, though there's actually a method that combines those 2 calls... :)
yep
throw $this->getNoPermissionResponseException()