--application/shared_components/security/authorization/check_agent_access
wwv_flow_api.create_security_scheme(
  p_id => 16097609166220701 + wwv_flow_api.g_id_offset,
  p_flow_id => wwv_flow.g_flow_id,
  p_name=>'check agent access',
  p_scheme_type=>'FUNCTION_RETURNING_BOOLEAN',
  p_scheme=>'declare'||chr(10)||
'cursor c_supplier(cp_enqu_id number) is SELECT prty_id FROM v_latest_rt_code_for_enro where rt_code=''ENQ SUPP'' and enqu_id=cp_enqu_id;'||chr(10)||
'supplierid number;'||chr(10)||
'begin'||chr(10)||
'--copied from main authorization scheme'||chr(10)||
'IF wwv_flow_custom_auth.current_page_is_public then'||chr(10)||
'  return TRUE;'||chr(10)||
'else '||chr(10)||
''||chr(10)||
'if mip_security.page_authorization(p_app_user=>:app_user, p_page_id=>:app_page_id) then'||chr(10)||
''||chr(10)||
'--scheme code just for enquiry page, checks records against agent'||chr(10)||
'  if :P3_ID is null then'||chr(10)||
'    return true;'||chr(10)||
'  end if; '||chr(10)||
'  if #OWNER#.mip_parties.get_user_role(v(''APP_USER'')) = ''AGENT'' then '||chr(10)||
'    open c_supplier(:P3_ID);'||chr(10)||
'    fetch c_supplier into supplierid;'||chr(10)||
'    if c_supplier%found then'||chr(10)||
'      if #OWNER#.mip_parties.has_supplier(v(''APP_USER''), supplierid)    then'||chr(10)||
'        close c_supplier;'||chr(10)||
'        return true;'||chr(10)||
'      end if;'||chr(10)||
'    else'||chr(10)||
'      close c_supplier;'||chr(10)||
'      return false;'||chr(10)||
'    end if;'||chr(10)||
'  else'||chr(10)||
'    return true;'||chr(10)||
'  end if;'||chr(10)||
'end if;'||chr(10)||
'END IF;'||chr(10)||
''||chr(10)||
'end;',
  p_caching=>'BY_USER_BY_PAGE_VIEW',
  p_error_message=>'Oi');
 
 
end;
/

