adding perm convenience scripts
authorChris Sharp <csharp@georgialibraries.org>
Mon, 22 Apr 2019 12:13:30 +0000 (08:13 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Mon, 22 Apr 2019 12:13:30 +0000 (08:13 -0400)
perms/get_combined_perms_per_profile.sh [new file with mode: 0755]
perms/get_combined_perms_per_user.sql [new file with mode: 0644]
perms/get_profiles_with_perm.sh [new file with mode: 0755]

diff --git a/perms/get_combined_perms_per_profile.sh b/perms/get_combined_perms_per_profile.sh
new file mode 100755 (executable)
index 0000000..ec6f481
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+Usage () {
+echo "USAGE: $0 <permission group name>"
+exit 1
+}
+
+GROUP_NAME="$1"
+
+if [ -z $GROUP_NAME ]; then
+    Usage
+fi
+read -d '' SQL <<EOF
+select  perm.code as "Permission", 
+        perm.description as "Description", 
+        grp.name as "Permission Level", 
+        case 
+            when map.depth = 0 then 'Consortium' 
+            when map.depth = 1 then 'System' 
+            when map.depth = 2 then 'Branch' 
+        end as "Depth", 
+        case 
+            when map.grantable = true then 'Grantable' 
+            when map.grantable = false then 'Not Grantable' 
+        end as "Grantability" 
+from    permission.grp_tree grp 
+        join permission.grp_perm_map map on (map.grp = grp.id) 
+        join permission.perm_list perm on (map.perm = perm.id) 
+where   grp.id in (
+            select id 
+            from permission.grp_ancestors(
+                (select id 
+                    from permission.grp_tree 
+                    where name = '$GROUP_NAME')
+            )
+        ) 
+        order by 1, 2;
+EOF
+
+PGUSER=evergreen psql -A --pset footer -o "$GROUP_NAME-perms.out" -c "$SQL" evergreen
diff --git a/perms/get_combined_perms_per_user.sql b/perms/get_combined_perms_per_user.sql
new file mode 100644 (file)
index 0000000..156e706
--- /dev/null
@@ -0,0 +1,31 @@
+select  perm.code as "Permission", 
+                perm.description as "Description", 
+                grp.name as "Permission Level", 
+                case 
+                        when map.depth = 0 then 'Consortium' 
+                        when map.depth = 1 then 'System' 
+                        when map.depth = 2 then 'Branch' 
+                end as "Depth", 
+                case 
+                        when map.grantable = true then 'Grantable' 
+                        when map.grantable = false then 'Not Grantable' 
+                end as "Grantability" 
+from    permission.grp_tree grp 
+                join permission.grp_perm_map map on (map.grp = grp.id) 
+                join permission.perm_list perm on (map.perm = perm.id) 
+where   grp.id in (
+                        select id 
+                        from permission.grp_ancestors(
+                                       
+                        (select profile
+                        from actor.usr
+                      where usrname = 'username'
+--                      where card in (
+--                          select id
+--                          from actor.card
+--                          where barcode = 'barcode'
+--                  )
+                )
+                        )
+    ) 
+order by 1, 2;
diff --git a/perms/get_profiles_with_perm.sh b/perms/get_profiles_with_perm.sh
new file mode 100755 (executable)
index 0000000..3d07782
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+Usage () {
+echo "USAGE: $0 <perm_code>.  Example: $0 VIEW_COPY_ALERT"
+exit 1
+}
+
+PERM_CODE="$1"
+PSQL="/usr/bin/psql"
+DB_USER="evergreen"
+
+if [ -z "$PERM_CODE" ]; then
+Usage
+fi
+
+PGUSER=$DB_USER $PSQL -c "select grp.name, perm.code, map.depth, map.grantable from permission.grp_perm_map map join  permission.grp_tree grp on (map.grp = grp.id) join permission.perm_list perm on (map.perm = perm.id) where perm.code = '$PERM_CODE'"