MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / Privilege

Function Privilege

web/pgadmin/static/js/components/Privilege.jsx:29–168  ·  view source on GitHub ↗
({value, onChange, controlProps})

Source from the content-addressed store, hash-verified

27}));
28
29export default function Privilege({value, onChange, controlProps}) {
30 // All available privileges in the PostgreSQL database server for
31 // generating the label for the specific Control
32 const LABELS = {
33 'C': 'CREATE',
34 'T': 'TEMPORARY',
35 'c': 'CONNECT',
36 'a': 'INSERT',
37 'r': 'SELECT',
38 'R': 'READ',
39 'W': 'WRITE',
40 'w': 'UPDATE',
41 'd': 'DELETE',
42 'D': 'TRUNCATE',
43 'x': 'REFERENCES',
44 't': 'TRIGGER',
45 'U': 'USAGE',
46 'X': 'EXECUTE',
47 'm': 'MAINTAIN',
48 };
49 let all = false;
50 let allWithGrant = false;
51
52 let textValue = '';
53 for(const v of value||[]) {
54 if(v.privilege) {
55 textValue += v.privilege_type;
56 if(v.with_grant) {
57 textValue += '*';
58 }
59 }
60 }
61
62 const checkboxId = _.uniqueId();
63 /* Calculate the real display value by merging all supported privs with incoming value */
64 const realVal = (controlProps?.supportedPrivs || []).map((priv)=>{
65 let inValue = _.find(value, (v)=>v.privilege_type===priv) || {
66 privilege: false, with_grant: false,
67 };
68 return {
69 privilege_type: priv,
70 privilege: Boolean(inValue.privilege),
71 with_grant: Boolean(inValue.with_grant),
72 };
73 });
74
75 const onCheckAll = (e, forWithGrant)=>{
76 let newValue = [];
77 /* Push all the privs or ignore if unchecked and return empty */
78 realVal.forEach((v)=>{
79 if(forWithGrant) {
80 newValue.push({
81 ...v,
82 privilege: true,
83 with_grant: e.target.checked,
84 });
85 } else if(e.target.checked) {
86 newValue.push({

Callers

nothing calls this directly

Calls 3

onCheckAllFunction · 0.85
onCheckFunction · 0.85
findMethod · 0.80

Tested by

no test coverage detected