fix: refs #7187 check for multiple device on freelancer
This commit is contained in:
parent
976b18203e
commit
71a9aed1bb
|
@ -0,0 +1,22 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_checkMultipleDevice`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Verify if a worker has multiple assigned devices,
|
||||
* except for freelancers.
|
||||
*
|
||||
* @param vUserFk worker id.
|
||||
*/
|
||||
DECLARE vHasPda BOOLEAN;
|
||||
DECLARE vIsFreelance BOOLEAN;
|
||||
|
||||
SELECT COUNT(*) INTO vHasPda FROM deviceProductionUser WHERE userFk = vSelf;
|
||||
SELECT isFreelance INTO vIsFreelance FROM worker WHERE id = vSelf;
|
||||
|
||||
IF NOT vIsFreelance AND vHasPda > 1 THEN
|
||||
CALL util.throw('You can only have one PDA');
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -3,20 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionUser_
|
|||
BEFORE INSERT ON `deviceProductionUser`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE vHasPda BOOLEAN;
|
||||
DECLARE visFreelancer BOOLEAN;
|
||||
DECLARE vUserName VARCHAR(50);
|
||||
|
||||
SELECT COUNT(*) INTO vHasPda FROM deviceProductionUser WHERE userFk = NEW.userFk;
|
||||
|
||||
SELECT name INTO vUserName FROM account.user WHERE id = NEW.userFk;
|
||||
|
||||
SELECT account.user_hasRoleId(vUserName, (SELECT id FROM role WHERE name = 'freelancer')) INTO vIsFreelancer;
|
||||
|
||||
IF NOT vIsFreelancer AND vHasPda THEN
|
||||
CALL util.throw('You can only have one PDA');
|
||||
ELSE
|
||||
CALL worker_checkMultipleDevice(NEW.userFk);
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -3,20 +3,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionUser_
|
|||
BEFORE UPDATE ON `deviceProductionUser`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE vHasPda BOOLEAN;
|
||||
DECLARE visFreelancer BOOLEAN;
|
||||
DECLARE vUserName VARCHAR(50);
|
||||
|
||||
SELECT COUNT(*) INTO vHasPda FROM deviceProductionUser WHERE userFk = NEW.userFk;
|
||||
|
||||
SELECT name INTO vUserName FROM account.user WHERE id = NEW.userFk;
|
||||
|
||||
SELECT account.user_hasRoleId(vUserName, (SELECT id FROM role WHERE name = 'freelancer')) INTO vIsFreelancer;
|
||||
|
||||
IF NOT vIsFreelancer AND vHasPda THEN
|
||||
CALL util.throw('You can only have one PDA');
|
||||
ELSE
|
||||
CALL worker_checkMultipleDevice(NEW.userFk);
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
Loading…
Reference in New Issue