Commit 54601f5c authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Implement error handling for request Hosting Subscription

parent 7c72b6fe
...@@ -55,6 +55,14 @@ ...@@ -55,6 +55,14 @@
return gadget.redirect({"command": "change", return gadget.redirect({"command": "change",
"options": {"jio_key": "/", "page": "slap_service_list"}}); "options": {"jio_key": "/", "page": "slap_service_list"}});
}); });
}, function (error) {
if (error.target.status === 409) {
return gadget.notifySubmitted({message: 'A service with this title already exists.', status: 'error'});
}
if (error.target.status === 400) {
return gadget.notifySubmitted({message: 'Service Title is mandatory.', status: 'error'});
}
}); });
}); });
}) })
...@@ -65,7 +73,7 @@ ...@@ -65,7 +73,7 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this; var gadget = this;
return RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
gadget.getDeclaredGadget('form_view'), gadget.getDeclaredGadget('form_view'),
......
...@@ -274,7 +274,7 @@ ...@@ -274,7 +274,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>981.35383.15103.35259</string> </value> <value> <string>982.17545.17272.64904</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -292,7 +292,7 @@ ...@@ -292,7 +292,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1580513887.37</float> <float>1583203969.98</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
from zExceptions import Unauthorized
if REQUEST is None:
raise Unauthorized
import json import json
portal = context.getPortalObject() portal = context.getPortalObject()
response = REQUEST.RESPONSE
if shared in ["true", "1", 1]: if shared in ["true", "1", 1]:
shared = True shared = True
...@@ -8,7 +15,8 @@ if shared in ["false", "", 0, "0", None]: ...@@ -8,7 +15,8 @@ if shared in ["false", "", 0, "0", None]:
shared = False shared = False
if not title: if not title:
raise ValueError("Service Title is mandatory!") response.setStatus(400)
return "Service Title is mandatory!"
if "{uid}" in title: if "{uid}" in title:
uid_ = portal.portal_ids.generateNewId(id_group=("vifib", "kvm"), default=1) uid_ = portal.portal_ids.generateNewId(id_group=("vifib", "kvm"), default=1)
...@@ -21,7 +29,8 @@ hosting_subscription = portal.portal_catalog.getResultValue( ...@@ -21,7 +29,8 @@ hosting_subscription = portal.portal_catalog.getResultValue(
) )
if hosting_subscription is not None: if hosting_subscription is not None:
raise ValueError("Instance with this name already exists") response.setStatus(409)
return "Instance with this name already exists"
# The URL should come from the URL Probably # The URL should come from the URL Probably
url = context.getUrlString() url = context.getUrlString()
...@@ -29,7 +38,7 @@ url = context.getUrlString() ...@@ -29,7 +38,7 @@ url = context.getUrlString()
person = portal.portal_membership.getAuthenticatedMember().getUserValue() person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person is None: if person is None:
raise ValueError("You cannot request without been logged in as a user.") raise Unauthorized("You cannot request without been logged in as a user.")
if software_type in [None, ""]: if software_type in [None, ""]:
software_type = "RootSoftwareInstance" software_type = "RootSoftwareInstance"
...@@ -63,5 +72,4 @@ if sla_xml: ...@@ -63,5 +72,4 @@ if sla_xml:
</instance>""" % sla_xml </instance>""" % sla_xml
person.requestSoftwareInstance(**request_kw) person.requestSoftwareInstance(**request_kw)
return json.dumps(context.REQUEST.get('request_hosting_subscription').getRelativeUrl()) return json.dumps(context.REQUEST.get('request_hosting_subscription').getRelativeUrl())
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>title, text_content="", software_type=None, shared=False, computer_guid=None, sla_xml=""</string> </value> <value> <string>title, text_content="", software_type=None, shared=False, computer_guid=None, sla_xml="", REQUEST=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment