default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / bin / pg-readonly
1 #!/usr/bin/perl
2 #
3 # hack to update/add read-only permissions for a user on the db
4 #
5 # usage: pg-readonly freesideuser readonlyuser
6
7 use strict;
8 use DBI;
9 use FS::UID qw(adminsuidsetup);
10 use FS::Record qw(dbdef);
11
12 my $user = shift or die &usage;
13 my $rouser = shift or die &usage;
14
15 my $dbh = adminsuidsetup $user;
16
17 foreach my $table ( dbdef->tables ) {
18   $dbh->do("GRANT SELECT ON $table TO $rouser");
19   $dbh->commit();
20   if ( my $pkey = dbdef->table($table)->primary_key ) {
21     $dbh->do("GRANT SELECT ON ${table}_${pkey}_seq TO $rouser");
22     $dbh->commit();
23   }
24 }
25
26 my @rt_tables = qw(
27 Attachments
28 Queues
29 Links
30 Principals
31 Groups
32 ScripConditions
33 Transactions
34 Scrips
35 ACL
36 GroupMembers
37 CachedGroupMembers
38 Users
39 Tickets
40 ScripActions
41 Templates
42 ObjectCustomFieldValues
43 CustomFields
44 ObjectCustomFields
45 CustomFieldValues
46 Attributes
47 sessions
48 );
49
50 foreach my $table ( @rt_tables ) {
51   $dbh->do("GRANT SELECT ON $table TO $rouser");
52   $dbh->commit();
53   $dbh->do("GRANT SELECT ON ${table}_id_seq TO $rouser");
54   $dbh->commit();
55 }