diff --git a/scripts-available/CDB_Groups.sql b/scripts-available/CDB_Groups.sql index 253e72c..716032e 100644 --- a/scripts-available/CDB_Groups.sql +++ b/scripts-available/CDB_Groups.sql @@ -52,7 +52,7 @@ $$ LANGUAGE PLPGSQL VOLATILE; -- Adds users to a group, comma-separated 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 $$ DECLARE group_role TEXT; @@ -60,7 +60,7 @@ DECLARE username TEXT; BEGIN group_role := cartodb._CDB_Group_GroupRole(group_name); - foreach username in array string_to_array(usernames, ',') + foreach username in array usernames loop user_role := cartodb._CDB_User_RoleFromUsername(username); IF(group_role IS NULL OR user_role IS NULL) @@ -75,7 +75,7 @@ $$ LANGUAGE PLPGSQL VOLATILE; -- Removes a user from a group 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 $$ DECLARE group_role TEXT; @@ -83,7 +83,7 @@ DECLARE username TEXT; BEGIN group_role := cartodb._CDB_Group_GroupRole(group_name); - foreach username in array string_to_array(usernames, ',') + foreach username in array usernames loop user_role := cartodb._CDB_User_RoleFromUsername(username); EXECUTE format('REVOKE %I FROM %I', group_role, user_role); diff --git a/scripts-available/CDB_Groups_API.sql b/scripts-available/CDB_Groups_API.sql index ed5447f..136a969 100644 --- a/scripts-available/CDB_Groups_API.sql +++ b/scripts-available/CDB_Groups_API.sql @@ -51,27 +51,27 @@ $$ $$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER; 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 $$ import string import urllib 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) plpy.execute(query) $$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER; 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 $$ import string import urllib 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) plpy.execute(query) $$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER;