public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin4][Patch]: RM1119 - Add proper validations in fields before processing
2+ messages / 2 participants
[nested] [flat]

* [pgAdmin4][Patch]: RM1119 - Add proper validations in fields before processing
@ 2016-08-08 08:48 Surinder Kumar <[email protected]>
  2016-08-08 11:47 ` Re: [pgAdmin4][Patch]: RM1119 - Add proper validations in fields before processing Dave Page <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Surinder Kumar @ 2016-08-08 08:48 UTC (permalink / raw)
  To: pgadmin-hackers

Hi

Issues fixed:
1) Add proper validation checks for fields.
2) Fixed wrong sql generation due to incorrect conditions in template.

Please find attached patch and review.


Thanks,
Surinder Kumar


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [application/octet-stream] RM1119.patch (4.5K, 3-RM1119.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/templates/sequence/js/sequence.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/templates/sequence/js/sequence.js
index 474f849..aad76b4 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/templates/sequence/js/sequence.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/templates/sequence/js/sequence.js
@@ -146,7 +146,8 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
           mode: ['properties', 'create', 'edit']
         },{
           id: 'increment', label: '{{ _('Increment') }}', type: 'int',
-          mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}'
+          mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}',
+          min: 1
         },{
           id: 'start', label: '{{ _('Start') }}', type: 'int',
           mode: ['create'], group: '{{ _('Definition') }}'
@@ -161,7 +162,8 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
           mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}'
         },{
           id: 'cache', label: '{{ _('Cache') }}', type: 'int',
-          mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}'
+          mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}',
+          min: 1
         },{
           id: 'cycled', label: '{{ _('Cycled') }}', type: 'switch',
           mode: ['properties', 'create', 'edit'], group: '{{ _('Definition') }}',
@@ -193,11 +195,12 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
          * the GUI for the respective control.
          */
         validate: function() {
-          var msg = undefined;
+          var msg = undefined,
+              minimum = this.get('minimum'),
+              maximum = this.get('maximum');
+              start = this.get('start');
           // Clear any existing error msg.
-          this.errorModel.unset('name');
-          this.errorModel.unset('seqowner');
-          this.errorModel.unset('schema');
+          this.errorModel.clear();

           if (_.isUndefined(this.get('name'))
               || String(this.get('name')).replace(/^\s+|\s+$/g, '') == '') {
@@ -219,6 +222,26 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
             this.errorModel.set('schema', msg);
             return msg;
           }
+
+          var min_lt = '{{ _('minimum value must be less than maximum value.') }}',
+              start_lt = '{{ _('start value cannot be less than minimum value.') }}',
+              start_gt = '{{ _('start value cannot be greater than maximum value.') }}';
+          if ((minimum == 0 && maximum == 0) ||
+              (parseInt(minimum, 10) >= parseInt(maximum, 10))) {
+            msg = min_lt
+            this.errorModel.set('minimum', msg);
+            return msg;
+          }
+          else if (start < minimum) {
+            msg = start_lt
+            this.errorModel.set('start', msg);
+            return msg;
+          }
+          else if (start > maximum) {
+            msg = start_gt
+            this.errorModel.set('start', msg);
+            return msg;
+          }
           return null;
         }
       })
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/templates/sequence/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/templates/sequence/sql/9.1_plus/create.sql
index 23ac1f3..0444a0d 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/templates/sequence/sql/9.1_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/templates/sequence/sql/9.1_plus/create.sql
@@ -3,14 +3,16 @@ CREATE SEQUENCE {{ conn|qtIdent(data.schema) }}.{{ conn|qtIdent(data.name) }}
 {% if data.cycled and data.cycled == True %}
     CYCLE
 {% endif %}
-{% if data.increment %}
+{% if data.increment is defined %}
     INCREMENT {{data.increment}}
-{% endif %}{% if data.start %}
+{% endif %}{% if data.start is defined %}
     START {{data.start}}
-{% endif %}{% if data.minimum %}
+{% elif data.current_value is defined %}
+    START {{data.current_value}}
+{% endif %}{% if data.minimum is defined %}
     MINVALUE {{data.minimum}}
-{% endif %}{% if data.maximum %}
+{% endif %}{% if data.maximum is defined %}
     MAXVALUE {{data.maximum}}
-{% endif %}{% if data.cache %}
+{% endif %}{% if data.cache is defined %}
     CACHE {{data.cache}}{% endif %};
-{% endif %}
\ No newline at end of file
+{% endif %}


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [pgAdmin4][Patch]: RM1119 - Add proper validations in fields before processing
  2016-08-08 08:48 [pgAdmin4][Patch]: RM1119 - Add proper validations in fields before processing Surinder Kumar <[email protected]>
@ 2016-08-08 11:47 ` Dave Page <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Dave Page @ 2016-08-08 11:47 UTC (permalink / raw)
  To: Surinder Kumar <[email protected]>; +Cc: pgadmin-hackers

Thanks, applied.

On Mon, Aug 8, 2016 at 9:48 AM, Surinder Kumar
<[email protected]> wrote:
> Hi
>
> Issues fixed:
> 1) Add proper validation checks for fields.
> 2) Fixed wrong sql generation due to incorrect conditions in template.
>
> Please find attached patch and review.
>
>
> Thanks,
> Surinder Kumar
>
>
>
> --
> Sent via pgadmin-hackers mailing list ([email protected])
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>



-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2016-08-08 11:47 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-08-08 08:48 [pgAdmin4][Patch]: RM1119 - Add proper validations in fields before processing Surinder Kumar <[email protected]>
2016-08-08 11:47 ` Dave Page <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox