]> git.evergreen-ils.org Git - contrib/pines.git/blob - perms/get_combined_perms_per_user.sh
add local git tar script
[contrib/pines.git] / perms / get_combined_perms_per_user.sh
1 #!/bin/bash
2
3 USER_BARCODE="$1"
4 PSQL=/usr/bin/psql
5 PSQL_USER=mydbuser
6 DB_HOST=mydbhost
7
8
9
10 read -d '' SQL <<EOL
11 select  perm.code as "Permission", 
12         perm.description as "Description", 
13         grp.name as "Permission Level", 
14         case 
15                 when map.depth = 0 then 'Consortium' 
16                 when map.depth = 1 then 'System' 
17                 when map.depth = 2 then 'Branch' 
18         end as "Depth", 
19         case 
20                 when map.grantable = true then 'Grantable' 
21                 when map.grantable = false then 'Not Grantable' 
22         end as "Grantability" 
23 from    permission.grp_tree grp 
24                 join permission.grp_perm_map map on (map.grp = grp.id) 
25                 join permission.perm_list perm on (map.perm = perm.id) 
26     where grp.id in (
27                         select id 
28                         from permission.grp_ancestors(
29                         (select profile
30                         from actor.usr
31                         where card in (
32                           select id
33                           from actor.card
34                           where barcode = '$USER_BARCODE'
35                   )
36                 )
37          )
38     ) 
39 UNION ALL
40 select  perm2.code as "Permission",
41     perm2.description as "Description",
42     'Per-User Assignment' as "Permission Level",
43     case
44             when map2.depth = 0 then 'Consortium'
45             when map2.depth = 1 then 'System'
46             when map2.depth = 2 then 'Branch'
47     end as "Depth",
48         case 
49                 when map2.grantable = true then 'Grantable' 
50                 when map2.grantable = false then 'Not Grantable' 
51         end as "Grantability" 
52 from    permission.usr_perm_map map2 
53     join permission.perm_list perm2 on (map2.perm = perm2.id)
54 where   map2.usr in (
55         select usr
56         from actor.card
57         where barcode = '$USER_BARCODE')
58 UNION ALL
59 select  perm3.code as "Permission",
60     perm3.description as "Description",
61     'Secondary: ' || grp3.name as "Permission Level",
62     case
63             when grp_perms.depth = 0 then 'Consortium'
64             when grp_perms.depth = 1 then 'System'
65             when grp_perms.depth = 2 then 'Branch'
66     end as "Depth",
67         case 
68                 when grp_perms.grantable = true then 'Grantable' 
69                 when grp_perms.grantable = false then 'Not Grantable' 
70         end as "Grantability" 
71 from    permission.usr_grp_map map3
72     join permission.grp_perm_map grp_perms on (map3.grp = grp_perms.grp)
73     join permission.grp_tree grp3 on (map3.grp = grp3.id)
74     join permission.perm_list perm3 on (grp_perms.perm = perm3.id)
75 where   map3.usr in (
76         select usr
77         from actor.card
78         where barcode = '$USER_BARCODE')
79
80 order by 1, 2;
81 EOL
82
83 $PSQL -U $PSQL_USER -h $DB_HOST -1 -c "$SQL"
84