From 653eae21b332d30d944b9e53e986aa823a656864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Ignacio=20S=C3=A1nchez=20Lara?= Date: Mon, 17 Aug 2015 15:20:15 +0200 Subject: [PATCH] _CDB_Group_RemoveMember_API --- scripts-available/CDB_Groups.sql | 1 + scripts-available/CDB_Groups_API.sql | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/scripts-available/CDB_Groups.sql b/scripts-available/CDB_Groups.sql index a4244a7..b0b6d02 100644 --- a/scripts-available/CDB_Groups.sql +++ b/scripts-available/CDB_Groups.sql @@ -74,6 +74,7 @@ BEGIN cdb_group_role := cartodb._CDB_Group_GroupRole(group_name); cdb_user_role := cartodb._CDB_User_RoleFromUsername(username); EXECUTE format('REVOKE "%s" FROM "%s"', cdb_group_role, cdb_user_role); + PERFORM cartodb._CDB_Group_RemoveMember_API(current_database(), group_name, username); END $$ LANGUAGE PLPGSQL VOLATILE; diff --git a/scripts-available/CDB_Groups_API.sql b/scripts-available/CDB_Groups_API.sql index bca575f..068fe2a 100644 --- a/scripts-available/CDB_Groups_API.sql +++ b/scripts-available/CDB_Groups_API.sql @@ -92,6 +92,28 @@ $$ raise err $$ LANGUAGE 'plpythonu' VOLATILE; +CREATE OR REPLACE +FUNCTION cartodb._CDB_Group_RemoveMember_API(database_name text, group_name text, username text) + RETURNS VOID AS +$$ + import httplib + import string + + try: + params = plpy.execute("select c.host, c.port, c.timeout, c.auth from cartodb._CDB_Group_API_Conf() c;")[0] + if params['host'] is None: + return + + client = httplib.HTTPConnection(params['host'], params['port'], False, params['timeout']) + headers = { 'Authorization': params['auth'], 'Content-Type': 'application/json' } + client.request('DELETE', '/api/v1/databases/%s/groups/%s/users/%s' % (database_name, group_name, username), '', headers) + response = client.getresponse() + assert response.status == 200 + except Exception as err: + plpy.warning('group creation error: ' + str(err)) + raise err +$$ LANGUAGE 'plpythonu' VOLATILE; + DO LANGUAGE 'plpgsql' $$ BEGIN DROP FUNCTION IF EXISTS cartodb._CDB_Group_API_Conf();