25 lines
639 B
SQL
25 lines
639 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` 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 ;
|