This forum is archived. Posts are preserved for historical reference. For current help, join us on Discord.

Permissions

In UserSpice 4.3 and Below · Started by Sebastian on 2016-08-23 10:39 am · 8378 views · 3 replies

Hi,

I've added some Permission Levels and wanted to use these permissions to allow or disallow users access to sites/functions etc. I found that the permissions are saved in the database in the table "user_permission_matches".
So, is it the way to have access to the permissions to query this table, like
$query = $db->query("SELECT * FROM user_permission_matches WHERE user_id = ?", array($num));
?
Or does UserSpice offers some functions for that?
Thanks,
Sebastian
There are not built in functions for doing that, but I could definitely see the use case for it. By default those permissions are designed only to control access to particular pages, but there is no reason why that functionality could not be extended.

Just fyi, you can always get the id of the logged in user by putting
$user->data()->id;

You'll notice that we also do something similar with the menus. The menu looks at the permission level of the logged in user. In fact, there is a function for that.
if (checkMenu(2,$user->data()->id)){  //Links for permission level 2 (default admin) ?>

You may want to play with that checkMenu function. It might be a slightly faster (but less flexible) way to do that rather than querying manually.
Oh thanks, checkMenu is exactly what I need. So, no need to do it manually.
Sebastian
Absolutely. Glad it helped.