]> git.evergreen-ils.org Git - contrib/pines.git/blob - helper-scripts/get_combined_perms_per_profile.sh
add local git tar script
[contrib/pines.git] / helper-scripts / get_combined_perms_per_profile.sh
1 #!/bin/bash
2
3 Usage () {
4 echo "USAGE: $0 <permission group name>"
5 exit 1
6 }
7
8 GROUP_NAME="$1"
9 PG_USER="evergreen"
10 PSQL="/usr/bin/psql"
11 PG_DB="evergreen"
12
13
14 if [ -z $GROUP_NAME ]; then
15     Usage
16 fi
17 read -d '' SQL <<EOF
18 select  perm.code as "Permission", 
19         perm.description as "Description", 
20         grp.name as "Permission Level", 
21         case 
22             when map.depth = 0 then 'Consortium' 
23             when map.depth = 1 then 'System' 
24             when map.depth = 2 then 'Branch' 
25         end as "Depth", 
26         case 
27             when map.grantable = true then 'Grantable' 
28             when map.grantable = false then 'Not Grantable' 
29         end as "Grantability" 
30 from    permission.grp_tree grp 
31         join permission.grp_perm_map map on (map.grp = grp.id) 
32         join permission.perm_list perm on (map.perm = perm.id) 
33 where   grp.id in (
34             select id 
35             from permission.grp_ancestors(
36                 (select id 
37                     from permission.grp_tree 
38                     where name = '$GROUP_NAME')
39             )
40         ) 
41         order by 1, 2;
42 EOF
43
44 PGUSER="$PG_USER" "$PSQL" -A --pset footer --field-separator ',' -o "$GROUP_NAME-perms.out" -c "$SQL" "$PG_DB"
45