salix/db/routines/hedera/functions/myUser_checkRestPriv.sql

32 lines
727 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `hedera`.`myUser_checkRestPriv`(vMethodPath VARCHAR(255))
RETURNS tinyint(1)
DETERMINISTIC
BEGIN
/**
* Checks if the current user has permission to run a REST service.
*
* @param vMethodPath Route of the REST service
* @return %TRUE if it has permissions, otherwise %FALSE
*/
DECLARE vCount INT;
DECLARE vHasRole INT DEFAULT NULL;
SELECT COUNT(*) INTO vCount FROM restPriv
WHERE methodPath = vMethodPath;
IF vCount = 0 THEN
RETURN FALSE;
END IF;
SELECT COUNT(*) > 0
INTO vHasRole
FROM restPriv
WHERE methodPath = vMethodPath
AND (`role` IS NULL OR account.myUser_hasRoleId(`role`))
LIMIT 1;
RETURN vHasRole;
END$$
DELIMITER ;