forked from pgadmin-org/pgadmin4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprivilege.ui.js
More file actions
88 lines (82 loc) · 2.48 KB
/
privilege.ui.js
File metadata and controls
88 lines (82 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2025, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import gettext from 'sources/gettext';
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
import { getNodeListByName } from '../../../../static/js/node_ajax';
export function getNodePrivilegeRoleSchema(nodeObj, treeNodeInfo, itemNodeData, privileges) {
return new PrivilegeRoleSchema(
()=>getNodeListByName('role', treeNodeInfo, itemNodeData, {}, ()=>true, (res)=>{
res.unshift({label: 'PUBLIC', value: 'PUBLIC'});
return res;
}),
()=>getNodeListByName('role', treeNodeInfo, itemNodeData),
treeNodeInfo,
privileges
);
}
export default class PrivilegeRoleSchema extends BaseUISchema {
constructor(granteeOptions, grantorOptions, nodeInfo, supportedPrivs) {
super({
grantee: undefined,
grantor: nodeInfo?.server?.user?.name,
privileges: [],
});
this.granteeOptions = granteeOptions;
this.grantorOptions = grantorOptions;
this.nodeInfo = nodeInfo;
this.supportedPrivs = supportedPrivs || [];
}
updateSupportedPrivs = (updatedPrivs) => {
this.supportedPrivs = updatedPrivs;
};
get baseFields() {
let obj = this;
return [{
id: 'grantee', label: gettext('Grantee'), type:'text',
editable: true,
cell: ()=>({
cell: 'select', options: this.granteeOptions,
controlProps: {
allowClear: false,
}
}),
disabled: function (state) {
return !obj.isNew(state);
},
noEmpty: true,
},
{
id: 'privileges', label: gettext('Privileges'),
type: 'text', group: null,
cell: () => ({
cell: 'privilege',
controlProps: {
supportedPrivs: this.supportedPrivs,
}
}),
disabled : function(state) {
return !(
obj.nodeInfo &&
obj.nodeInfo.server?.user?.name == state['grantor']
);
},
},
{
id: 'grantor', label: gettext('Grantor'), type: 'text', readonly: true,
editable: false, cell: ()=>({cell: 'select', options: obj.grantorOptions}),
}];
}
validate(state, setError) {
if((state.privileges || []).length <= 0) {
setError('privileges', gettext('At least one privilege should be selected.'));
return true;
}
return false;
}
}