26 lines
666 B
MySQL
26 lines
666 B
MySQL
|
DROP FUNCTION IF EXISTS account.user_hasRole;
|
||
|
|
||
|
DELIMITER $$
|
||
|
CREATE DEFINER=`root`@`%` FUNCTION `account`.`user_hasRole`(vUserName VARCHAR(255), vRoleName VARCHAR(255)) RETURNS tinyint(1)
|
||
|
DETERMINISTIC
|
||
|
BEGIN
|
||
|
/**
|
||
|
* Checks if user has/inherits a role.
|
||
|
*
|
||
|
* @param vUserName The user name
|
||
|
* @param vRoleName Role to check
|
||
|
* @return %TRUE if it has role, %FALSE otherwise
|
||
|
*/
|
||
|
DECLARE vHasRole BOOL DEFAULT FALSE;
|
||
|
|
||
|
SELECT COUNT(*) > 0 INTO vHasRole
|
||
|
FROM user u
|
||
|
JOIN roleRole rr ON rr.role = u.role
|
||
|
JOIN role r ON r.id = rr.inheritsFrom
|
||
|
WHERE u.`name` = vUserName
|
||
|
AND r.`name` = vRoleName COLLATE 'utf8_unicode_ci';
|
||
|
|
||
|
RETURN vHasRole;
|
||
|
END$$
|
||
|
DELIMITER ;
|