Common utility function to parse privileges before sending to database.
(str_privileges, allowed_acls=[])
| 106 | |
| 107 | |
| 108 | def parse_priv_to_db(str_privileges, allowed_acls=[]): |
| 109 | """ |
| 110 | Common utility function to parse privileges before sending to database. |
| 111 | """ |
| 112 | from pgadmin.utils.driver import get_driver |
| 113 | from config import PG_DEFAULT_DRIVER |
| 114 | driver = get_driver(PG_DEFAULT_DRIVER) |
| 115 | |
| 116 | db_privileges = { |
| 117 | 'c': 'CONNECT', |
| 118 | 'C': 'CREATE', |
| 119 | 'T': 'TEMPORARY', |
| 120 | 'a': 'INSERT', |
| 121 | 'r': 'SELECT', |
| 122 | 'R': 'READ', |
| 123 | 'w': 'UPDATE', |
| 124 | 'W': 'WRITE', |
| 125 | 'd': 'DELETE', |
| 126 | 'D': 'TRUNCATE', |
| 127 | 'x': 'REFERENCES', |
| 128 | 't': 'TRIGGER', |
| 129 | 'U': 'USAGE', |
| 130 | 'X': 'EXECUTE', |
| 131 | 'm': 'MAINTAIN' |
| 132 | } |
| 133 | |
| 134 | privileges = [] |
| 135 | allowed_acls_len = len(allowed_acls) |
| 136 | |
| 137 | for priv in str_privileges: |
| 138 | priv_with_grant = [] |
| 139 | priv_without_grant = [] |
| 140 | |
| 141 | _parse_privileges(priv, db_privileges, allowed_acls, priv_with_grant, |
| 142 | priv_without_grant) |
| 143 | |
| 144 | # If we have all acl then just return all |
| 145 | if len(priv_with_grant) == allowed_acls_len > 1: |
| 146 | priv_with_grant = ['ALL'] |
| 147 | if len(priv_without_grant) == allowed_acls_len > 1: |
| 148 | priv_without_grant = ['ALL'] |
| 149 | |
| 150 | grantee = driver.qtIdent(None, priv['grantee']) \ |
| 151 | if priv['grantee'] != 'PUBLIC' else 'PUBLIC' |
| 152 | |
| 153 | old_grantee = driver.qtIdent(None, priv['old_grantee']) \ |
| 154 | if 'old_grantee' in priv and priv['old_grantee'] != 'PUBLIC' \ |
| 155 | else grantee |
| 156 | |
| 157 | acltype = priv['acltype'] if 'acltype' in priv else 'defaultacls' |
| 158 | |
| 159 | grantor = driver.qtIdent(None, priv['grantor']) |
| 160 | |
| 161 | # Appending and returning all ACL |
| 162 | privileges.append({ |
| 163 | 'grantor': grantor, |
| 164 | 'grantee': grantee, |
| 165 | 'with_grant': priv_with_grant, |
no test coverage detected