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:
Murtuza Zabuawala 2016-04-14 15:46:25 +01:00 committed by Dave Page
parent c6acbcb5ad
commit 49e433db4f
3 changed files with 22 additions and 22 deletions

View File

@ -270,7 +270,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
schema: [{
id: 'name', label: '{{ _('Name') }}', cell: 'string',
type: 'text', mode: ['properties', 'create', 'edit'],
disabled: 'inSchema'
disabled: 'schemaCheck'
},{
id: 'oid', label:'{{ _('OID') }}', cell: 'string',
type: 'text' , mode: ['properties'], disabled: true
@ -282,7 +282,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
},{
id: 'schema', label:'{{ _('Schema') }}', cell: 'string',
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(d && d.label.match(/^pg_/))
{
@ -290,18 +290,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
}
return true;
},
control: Backform.NodeListByNameControl.extend({
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;
}
})
control: 'node-list-by-name'
},{
id: 'typtype', label:'{{ _('Type') }}',
mode: ['create','edit'], disabled: 'inSchemaWithModelCheck',
@ -314,7 +303,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
{label: "Enumeration", value: "e"},
{label: "External", value: "b"},
{label: "Range", value: "r"},
{label: "Shell", value: "s"}
{label: "Shell", value: "p"}
]
},
disabled: 'inSchemaWithModelCheck',
@ -724,7 +713,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
uniqueCol : ['grantee'], deps: ['typtype'],
canAdd: function(m) {
// 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') }}',
@ -734,7 +723,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
control: 'unique-col-collection', deps: ['typtype'],
canAdd: function(m) {
// 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;
},
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
inSchemaWithModelCheck: function(m) {
if(this.node_info && 'schema' in this.node_info)

View File

@ -1,7 +1,7 @@
{% import 'macros/schemas/security.macros' as SECLABLE %}
{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
{## 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) }};
{% endif %}
{### Composite Type ###}

View File

@ -131,9 +131,9 @@ ALTER TYPE {{ conn|qtIdent(o_data.schema, o_data.name) }}
{# Below will change the schema for object #}
{# with extra if condition we will also make sure that object has correct name #}
{% if data.schema and data.schema != o_data.schema %}
ALTER TYPE {% if data.name != o_data.name %}{{ conn|qtIdent(o_data.schema, data.name) }}
{% else %}{{ conn|qtIdent(o_data.schema, o_data.name) }}{% endif %}
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 %}
SET SCHEMA {{ conn|qtIdent(data.schema) }};
{% endif %}
{% endif %}