Compare commits

...

7 Commits

Author SHA1 Message Date
Gonzalo Riestra
1637257772 Merge pull request #346 from CartoDB/username
Add CDB_Username function
2019-02-22 09:20:47 +01:00
Gonzalo Riestra
a904b101a3 update news 2019-02-22 08:39:17 +01:00
Javier Torres
917a975baa Tabs vs spaces 2019-02-21 15:20:24 +01:00
Gonzalo Riestra
0568b36a90 use session_user instead of current_user 2019-02-20 14:45:57 +01:00
Gonzalo Riestra
6d122462bb decouple tests from cartodb 2019-02-20 13:34:11 +01:00
Gonzalo Riestra
ffaf5e4400 Bump to 0.25.0 2019-02-20 10:38:16 +01:00
Gonzalo Riestra
2a4ecd4850 Add CDB_Username() function 2019-02-20 10:38:00 +01:00
7 changed files with 38 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
# cartodb/Makefile
EXTENSION = cartodb
EXTVERSION = 0.24.1
EXTVERSION = 0.25.0
SED = sed
AWK = awk
@@ -93,6 +93,7 @@ UPGRADABLE = \
0.23.2 \
0.24.0 \
0.24.1 \
0.25.0 \
$(EXTVERSION)dev \
$(EXTVERSION)next \
$(END)

View File

@@ -1,3 +1,6 @@
0.25.0 (2019-02-22)
* Add `CDB_Username` to get the cartodb username from the current PostgreSQL user
0.24.1 (2019-01-02)
* Drop functions removed in 0.12 (#341)
* Travis: Test with PostgreSQL 9.5, 10 and 11.

View File

@@ -0,0 +1,6 @@
-- Returns the cartodb username of the current PostgreSQL session
CREATE OR REPLACE FUNCTION CDB_Username()
RETURNS text
AS $$
SELECT CDB_Conf_GetConf(CONCAT('api_keys_', session_user))->>'username';
$$ LANGUAGE SQL STABLE PARALLEL SAFE SECURITY DEFINER;

View File

@@ -0,0 +1 @@
../scripts-available/CDB_Username.sql

22
test/CDB_Username.sql Normal file
View File

@@ -0,0 +1,22 @@
SELECT session_user; -- postgres
SELECT CDB_Username(); -- (NULL)
-- Add the role fulano with api_key and connect with it
\set QUIET on
CREATE ROLE fulano LOGIN;
GRANT USAGE ON SCHEMA cartodb TO fulano;
GRANT EXECUTE ON FUNCTION CDB_Username() TO fulano;
INSERT INTO cdb_conf (key, value) VALUES ('api_keys_fulano', '{"username": "fulanito", "permissions":[]}');
SET SESSION AUTHORIZATION fulano;
\set QUIET off
SELECT session_user; -- fulano
SELECT CDB_Username(); -- fulanito
-- Remove fulano
\set QUIET on
SET SESSION AUTHORIZATION postgres;
REVOKE USAGE ON SCHEMA cartodb FROM fulano;
REVOKE EXECUTE ON FUNCTION CDB_Username() FROM fulano;
DROP ROLE fulano;
\set QUIET off

4
test/CDB_Username_expect Normal file
View File

@@ -0,0 +1,4 @@
postgres
fulano
fulanito