Fixes #1136 - do not to allow create a server group with same name.

This commit is contained in:
Murtuza Zabuawala 2016-05-25 00:00:09 +05:30 committed by Ashesh Vashi
parent 42a3b784ba
commit c81977d441

View File

@ -198,6 +198,18 @@ class ServerGroupView(NodeView):
data = request.form if request.form else json.loads(request.data.decode())
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'])