Re: [pgadmin-hackers] [pgAdmin4][PATCH] To fix the issue in server group node

2017-05-17 Thread Dave Page
Thanks, patch applied.

On Wed, May 17, 2017 at 8:28 AM, Murtuza Zabuawala <
murtuza.zabuaw...@enterprisedb.com> 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 (pgadmin-hackers@postgresql.org)
> 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


[pgadmin-hackers] [pgAdmin4][PATCH] To fix the issue in server group node

2017-05-17 Thread Murtuza Zabuawala
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 (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers