Refactor Member -> User

This commit is contained in:
Juan Ignacio Sánchez Lara 2015-09-07 09:56:59 +02:00
parent 0896b1451a
commit 428a2391ad
3 changed files with 12 additions and 12 deletions

View File

@ -52,7 +52,7 @@ $$ LANGUAGE PLPGSQL VOLATILE;
-- Adds a user to a group -- Adds a user to a group
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb.CDB_Group_AddMember(group_name text, username text) FUNCTION cartodb.CDB_Group_AddUser(group_name text, username text)
RETURNS VOID AS $$ RETURNS VOID AS $$
DECLARE DECLARE
group_role TEXT; group_role TEXT;
@ -65,13 +65,13 @@ BEGIN
RAISE EXCEPTION 'Group role (%) and user role (%) must be already existing', group_role, user_role; RAISE EXCEPTION 'Group role (%) and user role (%) must be already existing', group_role, user_role;
END IF; END IF;
EXECUTE format('GRANT %I TO %I', group_role, user_role); EXECUTE format('GRANT %I TO %I', group_role, user_role);
PERFORM cartodb._CDB_Group_AddMember_API(group_name, username); PERFORM cartodb._CDB_Group_AddUser_API(group_name, username);
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ 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_RemoveMember(group_name text, username text) FUNCTION cartodb.CDB_Group_RemoveUser(group_name text, username text)
RETURNS VOID AS $$ RETURNS VOID AS $$
DECLARE DECLARE
group_role TEXT; group_role TEXT;
@ -80,7 +80,7 @@ BEGIN
group_role := cartodb._CDB_Group_GroupRole(group_name); group_role := cartodb._CDB_Group_GroupRole(group_name);
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);
PERFORM cartodb._CDB_Group_RemoveMember_API(group_name, username); PERFORM cartodb._CDB_Group_RemoveUser_API(group_name, username);
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE;

View File

@ -45,7 +45,7 @@ $$
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER; $$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb._CDB_Group_AddMember_API(group_name text, username text) FUNCTION cartodb._CDB_Group_AddUser_API(group_name text, username text)
RETURNS VOID AS RETURNS VOID AS
$$ $$
import string import string
@ -58,7 +58,7 @@ $$
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER; $$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb._CDB_Group_RemoveMember_API(group_name text, username text) FUNCTION cartodb._CDB_Group_RemoveUser_API(group_name text, username text)
RETURNS VOID AS RETURNS VOID AS
$$ $$
import string import string

View File

@ -187,7 +187,7 @@ function setup() {
sql "SELECT cartodb.CDB_Group_CreateGroup('group_a_tmp')" sql "SELECT cartodb.CDB_Group_CreateGroup('group_a_tmp')"
sql "SELECT cartodb.CDB_Group_RenameGroup('group_a_tmp', 'group_a')" sql "SELECT cartodb.CDB_Group_RenameGroup('group_a_tmp', 'group_a')"
sql "SELECT cartodb.CDB_Group_AddMember('group_a', 'cdb_testmember_1')" sql "SELECT cartodb.CDB_Group_AddUser('group_a', 'cdb_testmember_1')"
sql "SELECT cartodb.CDB_Group_CreateGroup('group_b')" sql "SELECT cartodb.CDB_Group_CreateGroup('group_b')"
} }
@ -203,7 +203,7 @@ function tear_down() {
sql "select cartodb.CDB_Group_DropGroup('group_b')" sql "select cartodb.CDB_Group_DropGroup('group_b')"
sql "SELECT cartodb.CDB_Group_RemoveMember('group_a', 'cdb_testmember_1')" sql "SELECT cartodb.CDB_Group_RemoveUser('group_a', 'cdb_testmember_1')"
sql "select cartodb.CDB_Group_DropGroup('group_a')" sql "select cartodb.CDB_Group_DropGroup('group_a')"
sql "SELECT cartodb.CDB_Organization_RemoveAdmin('cdb_org_admin');" sql "SELECT cartodb.CDB_Organization_RemoveAdmin('cdb_org_admin');"
@ -474,8 +474,8 @@ function test_group_management_functions_cant_be_used_by_normal_members() {
sql cdb_testmember_1 "SELECT cartodb.CDB_Group_CreateGroup('group_x_1');" fails sql cdb_testmember_1 "SELECT cartodb.CDB_Group_CreateGroup('group_x_1');" fails
sql cdb_testmember_1 "SELECT cartodb.CDB_Group_RenameGroup('group_a', 'group_x_2');" fails sql cdb_testmember_1 "SELECT cartodb.CDB_Group_RenameGroup('group_a', 'group_x_2');" fails
sql cdb_testmember_1 "SELECT cartodb.CDB_Group_DropGroup('group_a');" fails sql cdb_testmember_1 "SELECT cartodb.CDB_Group_DropGroup('group_a');" fails
sql cdb_testmember_1 "SELECT cartodb.CDB_Group_AddMember('group_a', 'cdb_testmember_2');" fails sql cdb_testmember_1 "SELECT cartodb.CDB_Group_AddUser('group_a', 'cdb_testmember_2');" fails
sql cdb_testmember_1 "SELECT cartodb.CDB_Group_RemoveMember('group_a', 'cdb_testmember_1');" fails sql cdb_testmember_1 "SELECT cartodb.CDB_Group_RemoveUser('group_a', 'cdb_testmember_1');" fails
} }
function test_group_permission_functions_cant_be_used_by_normal_members() { function test_group_permission_functions_cant_be_used_by_normal_members() {
@ -496,8 +496,8 @@ function test_group_permission_functions_cant_be_used_by_normal_members() {
function test_group_management_functions_can_be_used_by_org_admin() { function test_group_management_functions_can_be_used_by_org_admin() {
sql cdb_org_admin "SELECT cartodb.CDB_Group_CreateGroup('group_x_tmp');" sql cdb_org_admin "SELECT cartodb.CDB_Group_CreateGroup('group_x_tmp');"
sql cdb_org_admin "SELECT cartodb.CDB_Group_RenameGroup('group_x_tmp', 'group_x');" sql cdb_org_admin "SELECT cartodb.CDB_Group_RenameGroup('group_x_tmp', 'group_x');"
sql cdb_org_admin "SELECT cartodb.CDB_Group_AddMember('group_x', 'cdb_testmember_1');" sql cdb_org_admin "SELECT cartodb.CDB_Group_AddUser('group_x', 'cdb_testmember_1');"
sql cdb_org_admin "SELECT cartodb.CDB_Group_RemoveMember('group_x', 'cdb_testmember_1');" sql cdb_org_admin "SELECT cartodb.CDB_Group_RemoveUser('group_x', 'cdb_testmember_1');"
# TODO: workaround superadmin limitation # TODO: workaround superadmin limitation
sql "SELECT cartodb.CDB_Group_DropGroup('group_x');" sql "SELECT cartodb.CDB_Group_DropGroup('group_x');"
} }