Commit 66cdaadb authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Fix up create new Login when Password don't comply with the policy

  This prevents display error page when something is invalid using JIO API.
parent e26a9add
......@@ -25,6 +25,11 @@
</head>
<body>
<div data-gadget-url="gadget_slapos_annotated_helper.html"
data-gadget-scope="annotated_helper"
data-template-id="add-new-login-header-text"
data-gadget-sandbox="public">
</div>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
......
......@@ -233,7 +233,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>982.32516.46874.3959</string> </value>
<value> <string>984.14093.31233.63027</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -251,7 +251,7 @@
</tuple>
<state>
<tuple>
<float>1584351106.69</float>
<float>1590777644.94</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP) {
(function (window, rJS, RSVP, jIO) {
"use strict";
rJS(window)
......@@ -63,6 +63,24 @@
return gadget.redirect({"command": "change",
"options": {"jio_key": content.parent_relative_url,
"page": "slap_controller"}});
})
.push(undefined, function (error) {
return gadget.getTranslationList(["Unknown Error, please open a ticket."])
.push(function (error_message) {
if (error.target === undefined) {
// received a cancelation so just skip
return gadget;
}
return jIO.util.readBlobAsText(error.target.response)
.then(function (evt) {
if (error.target.status === 406) {
return gadget.notifySubmitted({message: JSON.parse(evt.target.result),
status: 'error'});
}
return gadget.notifySubmitted({message: error_message[0],
status: 'error'});
});
});
});
});
});
......@@ -184,4 +202,4 @@
});
});
});
}(window, rJS, RSVP));
\ No newline at end of file
}(window, rJS, RSVP, jIO));
\ No newline at end of file
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>982.32679.18615.42052</string> </value>
<value> <string>984.18432.37885.8345</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -258,7 +258,7 @@
</tuple>
<state>
<tuple>
<float>1584351093.59</float>
<float>1591033199.4</float>
<string>UTC</string>
</tuple>
</state>
......
from zExceptions import Unauthorized
import json
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person.getUid() != context.getUid():
raise Unauthorized("You are not allowed to create login to a different user")
if context.Person_testLoginExistence(reference=reference):
raise Unauthorized("Login already exists")
context.REQUEST.RESPONSE.setStatus('406')
return json.dumps(
portal.Base_translateString("Login already exists"))
erp5_login = context.newContent(
try:
erp5_login = context.newContent(
portal_type = "ERP5 Login",
reference=reference,
password=password
)
erp5_login.validate()
)
erp5_login.validate()
except ValueError as e:
context.REQUEST.RESPONSE.setStatus('406')
return json.dumps(str(portal.Base_translateString(e)))
return erp5_login.getRelativeUrl()
return json.dumps(erp5_login.getRelativeUrl())
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