Annotation: office.can_login

CREATE OR REPLACE FUNCTION office.can_login(user_id integer_strict, office_id integer_strict, OUT result boolean, OUT message text)
RETURNS record

Information: office.can_login

Schema office
Function Name can_login
Arguments user_id integer_strict, office_id integer_strict, OUT result boolean, OUT message text
Owner postgres
Result Type record
Description

Implementation: office.can_login

CREATE OR REPLACE FUNCTION office.can_login(user_id integer_strict, office_id integer_strict, OUT result boolean, OUT message text)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE _office_id      integer;
BEGIN
    _office_id  := office.get_office_id_by_user_id($1);
    message     := '';

    IF $1 = office.get_sys_user_id() THEN
        result = false;
    END IF;

    IF $2=_office_id THEN
        result = true;
    ELSE
        IF office.is_parent_office(_office_id,$2) THEN
            result = true;
        END IF;
    END IF;

    IF(result) THEN
        IF(policy.is_restricted_mode() AND NOT policy.is_elevated_user($1)) THEN
            result := false;
            message := 'You need to have an elevated priviledge to login interactively during end of day operation';
            RAISE WARNING '%', message;
        END IF;
    END IF;
    
    RETURN;
END;
$function$