2016-02-09 17:50:45 +08:00
|
|
|
CREATE TYPE cdb_dataservices_client._entity_config AS (
|
|
|
|
username text,
|
2018-09-05 23:28:15 +08:00
|
|
|
organization_name text,
|
|
|
|
apikey_permissions json
|
2016-02-09 17:50:45 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Get entity config function
|
|
|
|
--
|
|
|
|
-- The purpose of this function is to retrieve the username and organization name from
|
|
|
|
-- a) schema where he/her is the owner in case is an organization user
|
|
|
|
-- b) entity_name from the cdb_conf database in case is a non organization user
|
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_entity_config()
|
|
|
|
RETURNS record AS $$
|
|
|
|
DECLARE
|
|
|
|
result cdb_dataservices_client._entity_config;
|
2018-09-05 23:28:15 +08:00
|
|
|
apikey_config json;
|
2016-02-09 17:50:45 +08:00
|
|
|
is_organization boolean;
|
2018-09-11 16:57:32 +08:00
|
|
|
organization_name text DEFAULT NULL;
|
2016-02-09 17:50:45 +08:00
|
|
|
BEGIN
|
2018-09-05 23:28:15 +08:00
|
|
|
SELECT cartodb.cdb_conf_getconf('api_keys_'||session_user) INTO apikey_config;
|
|
|
|
|
2016-02-09 17:50:45 +08:00
|
|
|
SELECT cartodb.cdb_conf_getconf('user_config')->'is_organization' INTO is_organization;
|
|
|
|
IF is_organization IS NULL THEN
|
|
|
|
RAISE EXCEPTION 'User must have user configuration in the config table';
|
|
|
|
ELSIF is_organization = TRUE THEN
|
|
|
|
SELECT cartodb.cdb_conf_getconf('user_config')->>'entity_name' INTO organization_name;
|
|
|
|
END IF;
|
2018-09-11 17:19:12 +08:00
|
|
|
result.username = apikey_config->>'username';
|
2016-02-09 17:50:45 +08:00
|
|
|
result.organization_name = organization_name;
|
2018-09-05 23:28:15 +08:00
|
|
|
result.apikey_permissions = apikey_config->'permissions';
|
2016-02-09 17:50:45 +08:00
|
|
|
RETURN result;
|
|
|
|
END;
|
2017-11-07 01:09:48 +08:00
|
|
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL SAFE;
|