test_valid_group_names and test_not_valid_group_names

This commit is contained in:
Juan Ignacio Sánchez Lara
2015-08-11 14:49:12 +02:00
parent 1915e28a0f
commit e2dd1e014e
2 changed files with 24 additions and 4 deletions

View File

@@ -102,13 +102,17 @@ $$ LANGUAGE PLPGSQL;
-----------------------
-- Private functions
-----------------------
-- Given a group name returns a role
-- Given a group name returns a role. group_name must be a valid PostgreSQL idenfifier. See http://www.postgresql.org/docs/9.2/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
CREATE OR REPLACE
FUNCTION cartodb._CDB_Group_GroupRole(group_name text)
RETURNS TEXT AS $$
DECLARE
group_role TEXT;
BEGIN
IF group_name !~ '^[a-zA-Z_][a-zA-Z0-9_]*$'
THEN
RAISE EXCEPTION 'Group name (%) must be a valid identifier. See http://www.postgresql.org/docs/9.2/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS', group_name;
END IF;
RETURN 'g_' || md5(current_database()) || '_' || group_name;
END
$$ LANGUAGE PLPGSQL;