Array notation for batch group functions
This commit is contained in:
parent
b73eb486a5
commit
154eff6d25
@ -52,7 +52,7 @@ $$ LANGUAGE PLPGSQL VOLATILE;
|
|||||||
|
|
||||||
-- Adds users to a group, comma-separated
|
-- Adds users to a group, comma-separated
|
||||||
CREATE OR REPLACE
|
CREATE OR REPLACE
|
||||||
FUNCTION cartodb.CDB_Group_AddUsers(group_name text, usernames text)
|
FUNCTION cartodb.CDB_Group_AddUsers(group_name text, usernames text[])
|
||||||
RETURNS VOID AS $$
|
RETURNS VOID AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
group_role TEXT;
|
group_role TEXT;
|
||||||
@ -60,7 +60,7 @@ DECLARE
|
|||||||
username TEXT;
|
username TEXT;
|
||||||
BEGIN
|
BEGIN
|
||||||
group_role := cartodb._CDB_Group_GroupRole(group_name);
|
group_role := cartodb._CDB_Group_GroupRole(group_name);
|
||||||
foreach username in array string_to_array(usernames, ',')
|
foreach username in array usernames
|
||||||
loop
|
loop
|
||||||
user_role := cartodb._CDB_User_RoleFromUsername(username);
|
user_role := cartodb._CDB_User_RoleFromUsername(username);
|
||||||
IF(group_role IS NULL OR user_role IS NULL)
|
IF(group_role IS NULL OR user_role IS NULL)
|
||||||
@ -75,7 +75,7 @@ $$ LANGUAGE PLPGSQL VOLATILE;
|
|||||||
|
|
||||||
-- Removes a user from a group
|
-- Removes a user from a group
|
||||||
CREATE OR REPLACE
|
CREATE OR REPLACE
|
||||||
FUNCTION cartodb.CDB_Group_RemoveUsers(group_name text, usernames text)
|
FUNCTION cartodb.CDB_Group_RemoveUsers(group_name text, usernames text[])
|
||||||
RETURNS VOID AS $$
|
RETURNS VOID AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
group_role TEXT;
|
group_role TEXT;
|
||||||
@ -83,7 +83,7 @@ DECLARE
|
|||||||
username TEXT;
|
username TEXT;
|
||||||
BEGIN
|
BEGIN
|
||||||
group_role := cartodb._CDB_Group_GroupRole(group_name);
|
group_role := cartodb._CDB_Group_GroupRole(group_name);
|
||||||
foreach username in array string_to_array(usernames, ',')
|
foreach username in array usernames
|
||||||
loop
|
loop
|
||||||
user_role := cartodb._CDB_User_RoleFromUsername(username);
|
user_role := cartodb._CDB_User_RoleFromUsername(username);
|
||||||
EXECUTE format('REVOKE %I FROM %I', group_role, user_role);
|
EXECUTE format('REVOKE %I FROM %I', group_role, user_role);
|
||||||
|
@ -51,27 +51,27 @@ $$
|
|||||||
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER;
|
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER;
|
||||||
|
|
||||||
CREATE OR REPLACE
|
CREATE OR REPLACE
|
||||||
FUNCTION cartodb._CDB_Group_AddUsers_API(group_name text, usernames text)
|
FUNCTION cartodb._CDB_Group_AddUsers_API(group_name text, usernames text[])
|
||||||
RETURNS VOID AS
|
RETURNS VOID AS
|
||||||
$$
|
$$
|
||||||
import string
|
import string
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
url = '/api/v1/databases/{0}/groups/%s/users' % (urllib.pathname2url(group_name))
|
url = '/api/v1/databases/{0}/groups/%s/users' % (urllib.pathname2url(group_name))
|
||||||
body = "{ \"users\": [\"%s\"] }" % "\",\"".join(usernames.split(','))
|
body = "{ \"users\": [\"%s\"] }" % "\",\"".join(usernames)
|
||||||
query = "select cartodb._CDB_Group_API_Request('POST', '%s', '%s', '{200, 409}') as response_status" % (url, body)
|
query = "select cartodb._CDB_Group_API_Request('POST', '%s', '%s', '{200, 409}') as response_status" % (url, body)
|
||||||
plpy.execute(query)
|
plpy.execute(query)
|
||||||
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER;
|
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER;
|
||||||
|
|
||||||
CREATE OR REPLACE
|
CREATE OR REPLACE
|
||||||
FUNCTION cartodb._CDB_Group_RemoveUsers_API(group_name text, usernames text)
|
FUNCTION cartodb._CDB_Group_RemoveUsers_API(group_name text, usernames text[])
|
||||||
RETURNS VOID AS
|
RETURNS VOID AS
|
||||||
$$
|
$$
|
||||||
import string
|
import string
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
url = '/api/v1/databases/{0}/groups/%s/users' % (urllib.pathname2url(group_name))
|
url = '/api/v1/databases/{0}/groups/%s/users' % (urllib.pathname2url(group_name))
|
||||||
body = "{ \"users\": [\"%s\"] }" % "\",\"".join(usernames.split(','))
|
body = "{ \"users\": [\"%s\"] }" % "\",\"".join(usernames)
|
||||||
query = "select cartodb._CDB_Group_API_Request('DELETE', '%s', '%s', '{200, 404}') as response_status" % (url, body)
|
query = "select cartodb._CDB_Group_API_Request('DELETE', '%s', '%s', '{200, 404}') as response_status" % (url, body)
|
||||||
plpy.execute(query)
|
plpy.execute(query)
|
||||||
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER;
|
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER;
|
||||||
|
Loading…
Reference in New Issue
Block a user