Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1637257772 | ||
|
|
a904b101a3 | ||
|
|
917a975baa | ||
|
|
0568b36a90 | ||
|
|
6d122462bb | ||
|
|
ffaf5e4400 | ||
|
|
2a4ecd4850 |
3
Makefile
3
Makefile
@@ -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)
|
||||
|
||||
3
NEWS.md
3
NEWS.md
@@ -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.
|
||||
|
||||
6
scripts-available/CDB_Username.sql
Normal file
6
scripts-available/CDB_Username.sql
Normal 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;
|
||||
1
scripts-enabled/920-CDB_Username.sql
Symbolic link
1
scripts-enabled/920-CDB_Username.sql
Symbolic link
@@ -0,0 +1 @@
|
||||
../scripts-available/CDB_Username.sql
|
||||
22
test/CDB_Username.sql
Normal file
22
test/CDB_Username.sql
Normal 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
4
test/CDB_Username_expect
Normal file
@@ -0,0 +1,4 @@
|
||||
postgres
|
||||
|
||||
fulano
|
||||
fulanito
|
||||
Reference in New Issue
Block a user