public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin4][PATCH] To fix the issue in server group node
2+ messages / 2 participants
[nested] [flat]

* [pgAdmin4][PATCH] To fix the issue in server group node
@ 2017-05-17 07:28 Murtuza Zabuawala <[email protected]>
  2017-05-17 14:58 ` Re: [pgAdmin4][PATCH] To fix the issue in server group node Dave Page <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Murtuza Zabuawala @ 2017-05-17 07:28 UTC (permalink / raw)
  To: pgadmin-hackers

Hi,

PFA minor patch to fix the in server group node, If you user creates/update
server group name which is already present in tree then it fails and it
does not provide clear informative error message regarding failure.

Issue found during testing node rename issue :)
RM#2414

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

diff --git a/web/pgadmin/browser/server_groups/__init__.py b/web/pgadmin/browser/server_groups/__init__.py
index 8d28ec4..e337d85 100644
--- a/web/pgadmin/browser/server_groups/__init__.py
+++ b/web/pgadmin/browser/server_groups/__init__.py
@@ -19,9 +19,9 @@ from flask_security import current_user
 from pgadmin.browser import BrowserPluginModule
 from pgadmin.browser.utils import NodeView
 from pgadmin.utils.ajax import make_json_response, gone, \
-    make_response as ajax_response
+    make_response as ajax_response, bad_request
 from pgadmin.utils.menu import MenuItem
-
+from sqlalchemy import exc
 from pgadmin.model import db, ServerGroup
 
 
@@ -174,6 +174,10 @@ class ServerGroupView(NodeView):
                 if u'name' in data:
                     servergroup.name = data[u'name']
                 db.session.commit()
+            except exc.IntegrityError:
+                return bad_request(gettext(
+                    "The specified server group already exists."
+                ))
             except Exception as e:
                 return make_json_response(
                     status=410, success=0, errormsg=e.message
@@ -220,18 +224,6 @@ class ServerGroupView(NodeView):
         )
         if data[u'name'] != '':
             try:
-                check_sg = ServerGroup.query.filter_by(
-                    user_id=current_user.id,
-                    name=data[u'name']).first()
-
-                # Throw error if server group already exists...
-                if check_sg is not None:
-                    return make_json_response(
-                        status=409,
-                        success=0,
-                        errormsg=gettext('Server group already exists')
-                    )
-
                 sg = ServerGroup(
                     user_id=current_user.id,
                     name=data[u'name'])
@@ -248,9 +240,15 @@ class ServerGroupView(NodeView):
                         "icon-%s" % self.node_type,
                         True,
                         self.node_type,
-                        can_delete=True  # This is user created hence can deleted
+                        # This is user created hence can deleted
+                        can_delete=True
                     )
                 )
+            except exc.IntegrityError:
+                return bad_request(gettext(
+                    "The specified server group already exists."
+                ))
+
             except Exception as e:
                 return make_json_response(
                     status=410,


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


Attachments:

  [text/plain] server_group_duplicate_name_issue.diff (2.5K, 3-server_group_duplicate_name_issue.diff)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/__init__.py b/web/pgadmin/browser/server_groups/__init__.py
index 8d28ec4..e337d85 100644
--- a/web/pgadmin/browser/server_groups/__init__.py
+++ b/web/pgadmin/browser/server_groups/__init__.py
@@ -19,9 +19,9 @@ from flask_security import current_user
 from pgadmin.browser import BrowserPluginModule
 from pgadmin.browser.utils import NodeView
 from pgadmin.utils.ajax import make_json_response, gone, \
-    make_response as ajax_response
+    make_response as ajax_response, bad_request
 from pgadmin.utils.menu import MenuItem
-
+from sqlalchemy import exc
 from pgadmin.model import db, ServerGroup
 
 
@@ -174,6 +174,10 @@ class ServerGroupView(NodeView):
                 if u'name' in data:
                     servergroup.name = data[u'name']
                 db.session.commit()
+            except exc.IntegrityError:
+                return bad_request(gettext(
+                    "The specified server group already exists."
+                ))
             except Exception as e:
                 return make_json_response(
                     status=410, success=0, errormsg=e.message
@@ -220,18 +224,6 @@ class ServerGroupView(NodeView):
         )
         if data[u'name'] != '':
             try:
-                check_sg = ServerGroup.query.filter_by(
-                    user_id=current_user.id,
-                    name=data[u'name']).first()
-
-                # Throw error if server group already exists...
-                if check_sg is not None:
-                    return make_json_response(
-                        status=409,
-                        success=0,
-                        errormsg=gettext('Server group already exists')
-                    )
-
                 sg = ServerGroup(
                     user_id=current_user.id,
                     name=data[u'name'])
@@ -248,9 +240,15 @@ class ServerGroupView(NodeView):
                         "icon-%s" % self.node_type,
                         True,
                         self.node_type,
-                        can_delete=True  # This is user created hence can deleted
+                        # This is user created hence can deleted
+                        can_delete=True
                     )
                 )
+            except exc.IntegrityError:
+                return bad_request(gettext(
+                    "The specified server group already exists."
+                ))
+
             except Exception as e:
                 return make_json_response(
                     status=410,


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

* Re: [pgAdmin4][PATCH] To fix the issue in server group node
  2017-05-17 07:28 [pgAdmin4][PATCH] To fix the issue in server group node Murtuza Zabuawala <[email protected]>
@ 2017-05-17 14:58 ` Dave Page <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Dave Page @ 2017-05-17 14:58 UTC (permalink / raw)
  To: Murtuza Zabuawala <[email protected]>; +Cc: pgadmin-hackers

Thanks, patch applied.

On Wed, May 17, 2017 at 8:28 AM, Murtuza Zabuawala <
[email protected]> wrote:

> Hi,
>
> PFA minor patch to fix the in server group node, If you user
> creates/update server group name which is already present in tree then it
> fails and it does not provide clear informative error message regarding
> failure.
>
> Issue found during testing node rename issue :)
> RM#2414
>
> --
> Regards,
> Murtuza Zabuawala
> EnterpriseDB: 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
>
>


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

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


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


end of thread, other threads:[~2017-05-17 14:58 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-05-17 07:28 [pgAdmin4][PATCH] To fix the issue in server group node Murtuza Zabuawala <[email protected]>
2017-05-17 14:58 ` 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