how to auto GRANT rights on a new table?

Поиск
Список
Период
Сортировка
От Maciej Sieczka
Тема how to auto GRANT rights on a new table?
Дата
Msg-id 47BF42AA.8010607@o2.pl
обсуждение исходный текст
Ответы Re: how to auto GRANT rights on a new table?  (Maciej Sieczka <tutey@o2.pl>)
Список pgsql-novice
Hello,

Greetings Everyone! This is my first post to your list.

I have a novice problem as follows:


There are 2 role groups in my cluster: "editors" and "viewers". In each
group there are several users.

In the DB, members of "editors" are allowed to create new tables in one
schema. My problem is that only the very user who created the table is
allowed to edit it.

I need to modify this PostgreSQL's default behaviour, so that the ACL on
a new table in this schema is set to arwdx for the group "editors", and
to r for "viewers", without having to manually GRANT rights each time a
new table is created. I don't know how.

 From reading so far I suppose I should create a function which calls
an appropriate GRANT, and trigger it when a new record is added to
"pg_tables". Is that a way to go? Is there an easier one?

If the function+trgger approach is optimal, can Anybody show me how they
should look and how to deploy them? I have a muddy idea they would
something like this pseudo-code:

CREATE TRIGGER trig_acl
   AFTER INSERT
   ON pg_catalog.pg_tables WHERE schemaname='dss_postgis' FOR EACH ROW
   EXECUTE PROCEDURE fnct_acl();

CREATE FUNCTION fnct_acl () RETURNS opaque AS '
   DECLARE
     table_name TEXT #how do I fetch the table name???
   BEGIN
     GRANT ALL ON myschema.table_name TO editors;
   END;
' LANGUAGE 'plpgsql';

What should I modify to make it real code?


An extra, but desired functionality, would be if I could also
prevent other "editors" from modifying the table *if* it is being
currently being edited by some user. Is that feasible at all?

Thank you for any pointers!

Regards,
Maciek

P.S.
I searched the archives and only found this [1] thread related, but it
does not provide an obvious (for me) solution.

[1]http://www.nabble.com/grant-select-on-all-tables-to1029307.html#a1029307

В списке pgsql-novice по дате отправления:

Предыдущее
От: Terry Lee Tucker
Дата:
Сообщение: Re: Trigger question
Следующее
От: Maciej Sieczka
Дата:
Сообщение: Re: how to auto GRANT rights on a new table?