dataservices-api/client/renderer/templates/20_public_functions.erb

27 lines
973 B
Plaintext
Raw Normal View History

--
-- Public geocoder API function
--
-- These are the only ones with permissions to publicuser role
-- and should also be the only ones with SECURITY DEFINER
CREATE OR REPLACE FUNCTION <%= GEOCODER_CLIENT_SCHEMA %>.<%= name %> (<%= params_with_type_and_default %>)
2015-11-19 01:38:06 +08:00
RETURNS <%= return_type %> AS $$
DECLARE
2015-11-19 01:38:06 +08:00
ret <%= return_type %>;
username text;
orgname text;
BEGIN
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
RAISE EXCEPTION 'The api_key must be provided';
END IF;
2016-01-22 23:30:38 +08:00
SELECT u, o INTO username, orgname FROM <%= GEOCODER_CLIENT_SCHEMA %>._cdb_entity_config() AS (u text, o text);
-- JSON value stored "" is taken as literal
IF username IS NULL OR username = '' OR username = '""' THEN
2015-12-03 02:12:11 +08:00
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
END IF;
SELECT <%= GEOCODER_CLIENT_SCHEMA %>._<%= name %>(username, orgname, <%= params %>) INTO ret;
RETURN ret;
END;
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;