mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Type fixes:
- Renaming or changing the schema for a shell type should not be allowed. - I'm allowed to try to add ACL entries or security labels to an existing shell type. This should be disallowed. - Changing the schema on a (non-shell) type doesn't work - the type name is omitted, e.g. ALTER TYPE pem SET SCHEMA pemhistory; Which should be: ALTER TYPE pem.foo SET SCHEMA pemhistory;
This commit is contained in:
parent
c6acbcb5ad
commit
49e433db4f
@ -270,7 +270,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
|
|||||||
schema: [{
|
schema: [{
|
||||||
id: 'name', label: '{{ _('Name') }}', cell: 'string',
|
id: 'name', label: '{{ _('Name') }}', cell: 'string',
|
||||||
type: 'text', mode: ['properties', 'create', 'edit'],
|
type: 'text', mode: ['properties', 'create', 'edit'],
|
||||||
disabled: 'inSchema'
|
disabled: 'schemaCheck'
|
||||||
},{
|
},{
|
||||||
id: 'oid', label:'{{ _('OID') }}', cell: 'string',
|
id: 'oid', label:'{{ _('OID') }}', cell: 'string',
|
||||||
type: 'text' , mode: ['properties'], disabled: true
|
type: 'text' , mode: ['properties'], disabled: true
|
||||||
@ -282,7 +282,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
|
|||||||
},{
|
},{
|
||||||
id: 'schema', label:'{{ _('Schema') }}', cell: 'string',
|
id: 'schema', label:'{{ _('Schema') }}', cell: 'string',
|
||||||
type: 'text', mode: ['create', 'edit'], node: 'schema',
|
type: 'text', mode: ['create', 'edit'], node: 'schema',
|
||||||
disabled: 'inSchema', filter: function(d) {
|
disabled: 'schemaCheck', filter: function(d) {
|
||||||
// If schema name start with pg_* then we need to exclude them
|
// If schema name start with pg_* then we need to exclude them
|
||||||
if(d && d.label.match(/^pg_/))
|
if(d && d.label.match(/^pg_/))
|
||||||
{
|
{
|
||||||
@ -290,18 +290,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
control: Backform.NodeListByNameControl.extend({
|
control: 'node-list-by-name'
|
||||||
render: function(){
|
|
||||||
// Initialize parent's render method
|
|
||||||
Backform.NodeListByNameControl.prototype.render.apply(this, arguments);
|
|
||||||
|
|
||||||
// Set schema default value to its parent Schema
|
|
||||||
if(this.model.isNew()){
|
|
||||||
this.model.set({'schema': this.model.node_info.schema.label});
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},{
|
},{
|
||||||
id: 'typtype', label:'{{ _('Type') }}',
|
id: 'typtype', label:'{{ _('Type') }}',
|
||||||
mode: ['create','edit'], disabled: 'inSchemaWithModelCheck',
|
mode: ['create','edit'], disabled: 'inSchemaWithModelCheck',
|
||||||
@ -314,7 +303,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
|
|||||||
{label: "Enumeration", value: "e"},
|
{label: "Enumeration", value: "e"},
|
||||||
{label: "External", value: "b"},
|
{label: "External", value: "b"},
|
||||||
{label: "Range", value: "r"},
|
{label: "Range", value: "r"},
|
||||||
{label: "Shell", value: "s"}
|
{label: "Shell", value: "p"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
disabled: 'inSchemaWithModelCheck',
|
disabled: 'inSchemaWithModelCheck',
|
||||||
@ -724,7 +713,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
|
|||||||
uniqueCol : ['grantee'], deps: ['typtype'],
|
uniqueCol : ['grantee'], deps: ['typtype'],
|
||||||
canAdd: function(m) {
|
canAdd: function(m) {
|
||||||
// Do not allow to add when shell type is selected
|
// Do not allow to add when shell type is selected
|
||||||
return !(m.get('typtype') === 's');
|
return !(m.get('typtype') === 'p');
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
id: 'seclabels', label: '{{ _('Security Labels') }}',
|
id: 'seclabels', label: '{{ _('Security Labels') }}',
|
||||||
@ -734,7 +723,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
|
|||||||
control: 'unique-col-collection', deps: ['typtype'],
|
control: 'unique-col-collection', deps: ['typtype'],
|
||||||
canAdd: function(m) {
|
canAdd: function(m) {
|
||||||
// Do not allow to add when shell type is selected
|
// Do not allow to add when shell type is selected
|
||||||
return !(m.get('typtype') === 's');
|
return !(m.get('typtype') === 'p');
|
||||||
}
|
}
|
||||||
|
|
||||||
}],
|
}],
|
||||||
@ -789,6 +778,17 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
schemaCheck: function(m) {
|
||||||
|
if(this.node_info && 'schema' in this.node_info)
|
||||||
|
{
|
||||||
|
if (m.isNew()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return m.get('typtype') === 'p';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
// We will check if we are under schema node & in 'create' mode
|
// We will check if we are under schema node & in 'create' mode
|
||||||
inSchemaWithModelCheck: function(m) {
|
inSchemaWithModelCheck: function(m) {
|
||||||
if(this.node_info && 'schema' in this.node_info)
|
if(this.node_info && 'schema' in this.node_info)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{% import 'macros/schemas/security.macros' as SECLABLE %}
|
{% import 'macros/schemas/security.macros' as SECLABLE %}
|
||||||
{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
|
{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
|
||||||
{## If user selected shell type then just create type template ##}
|
{## If user selected shell type then just create type template ##}
|
||||||
{% if data and data.typtype == 's' %}
|
{% if data and data.typtype == 'p' %}
|
||||||
CREATE TYPE {{ conn|qtIdent(data.schema, data.name) }};
|
CREATE TYPE {{ conn|qtIdent(data.schema, data.name) }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{### Composite Type ###}
|
{### Composite Type ###}
|
||||||
|
@ -131,9 +131,9 @@ ALTER TYPE {{ conn|qtIdent(o_data.schema, o_data.name) }}
|
|||||||
{# Below will change the schema for object #}
|
{# Below will change the schema for object #}
|
||||||
{# with extra if condition we will also make sure that object has correct name #}
|
{# with extra if condition we will also make sure that object has correct name #}
|
||||||
{% if data.schema and data.schema != o_data.schema %}
|
{% if data.schema and data.schema != o_data.schema %}
|
||||||
ALTER TYPE {% if data.name != o_data.name %}{{ conn|qtIdent(o_data.schema, data.name) }}
|
ALTER TYPE {% if data.name and data.name != o_data.name %}{{ conn|qtIdent(o_data.schema, data.name) }}
|
||||||
{% else %}{{ conn|qtIdent(o_data.schema, o_data.name) }}{% endif %}
|
{% else %}{{ conn|qtIdent(o_data.schema, o_data.name) }}
|
||||||
|
{% endif %}
|
||||||
SET SCHEMA {{ conn|qtIdent(data.schema) }};
|
SET SCHEMA {{ conn|qtIdent(data.schema) }};
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
Loading…
Reference in New Issue
Block a user