_CDB_Group_AddMember_API
This commit is contained in:
parent
00e9cc5a79
commit
e4a56371c0
@ -59,6 +59,7 @@ BEGIN
|
||||
RAISE EXCEPTION 'Group role (%) and user role (%) must be already existing', cdb_group_role, cdb_user_role;
|
||||
END IF;
|
||||
EXECUTE format('GRANT "%s" TO "%s"', cdb_group_role, cdb_user_role);
|
||||
PERFORM cartodb._CDB_Group_AddMember_API(current_database(), group_name, username);
|
||||
END
|
||||
$$ LANGUAGE PLPGSQL VOLATILE;
|
||||
|
||||
|
@ -69,6 +69,29 @@ $$
|
||||
raise err
|
||||
$$ LANGUAGE 'plpythonu' VOLATILE;
|
||||
|
||||
CREATE OR REPLACE
|
||||
FUNCTION cartodb._CDB_Group_AddMember_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'])
|
||||
body = '{ "username": "%s" }' % username
|
||||
headers = { 'Authorization': params['auth'], 'Content-Type': 'application/json' }
|
||||
client.request('POST', '/api/v1/databases/%s/groups/%s/users' % (database_name, group_name), body, 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();
|
||||
|
Loading…
Reference in New Issue
Block a user