Commit 7817397b authored by Romain Courteaud's avatar Romain Courteaud

slapos_panel: allow user to generate/revoke certificates

parent 4d5befac
......@@ -214,6 +214,7 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_panel/Base_getPaymentModeForCurrency',
'slapos_panel/Base_getStatusMonitorUrl',
'slapos_panel/Base_hasSlapOSProjectUserGroup',
'slapos_panel/CertificateLogin_invalidateOnSlaposPanel',
'slapos_panel/ComputeNode_getBusyComputePartitionList',
'slapos_panel/ComputeNode_requestCertificate',
'slapos_panel/ComputeNode_revokeCertificate',
......@@ -238,6 +239,7 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_panel/InstanceTree_requestStop',
'slapos_panel/InstanceTree_updateParameter',
'slapos_panel/PaymentTransaction_redirectToManualPayment',
'slapos_panel/Person_addSlapOSCredentialToken',
'slapos_panel/Project_addSlapOSAllocationSupply',
'slapos_panel/Project_addSlapOSComputeNode',
'slapos_panel/Project_addSlapOSComputeNodeToken',
......
<!DOCTYPE html>
<html>
<!--
data-i18n=Password is different from confirmation
data-i18n=Data updated.
data-i18n=Reference
data-i18n=Password
data-i18n=Confirm your Password
data-i18n=Login:
data-i18n=Credential Request Created.
data-i18n=You are not allowed to access this content, please login with an user which has the right permission
data-i18n=Error page
data-i18n=Logout
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Site List</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_erp5_page_slap_erp5_login_view.js" type="text/javascript"></script>
</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>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
/*global window, rJS, RSVP, jIO, Blob, UriTemplate */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, jIO, UriTemplate) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("updatePanel", "updatePanel")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("updateDocument", "updateDocument")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("getTranslationList", "getTranslationList")
.declareAcquiredMethod("redirect", "redirect")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
return this.changeState({
jio_key: options.jio_key,
doc: options.doc,
editable: 1
});
})
.onEvent('submit', function () {
var gadget = this,
doc = {};
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (content) {
var k;
for (k in content) {
if (content.hasOwnProperty(k)) {
if (k !== "password_confirmation") {
doc[k] = content[k];
}
if ((k === "password_confirmation") &&
(content.password !== content.password_confirmation)) {
return gadget.notifySubmitted({message: gadget.message1_translation, status: 'error'});
}
}
}
return gadget.jio_getAttachment('acl_users', 'links')
.push(function (links) {
var logout_url_template = links._links.logout.href;
return gadget.getSetting("hateoas_url")
.push(function (hateoas_url) {
return gadget.jio_putAttachment(gadget.state.jio_key,
hateoas_url + gadget.state.jio_key + "/Login_edit", doc);
})
.push(function (response) {
if (response.target === undefined) {
return gadget.notifySubmitted({message: gadget.message2_translation, status: 'success'});
}
// This is probably not ok
if (response.target.status === 200 && response.target.responseURL.search("login_form")) {
// The script required to launch a redirect
return gadget.notifySubmitted({message: gadget.message2_translation, status: 'success'})
.push(function () {
return gadget.getSetting('frontpage_gadget');
})
.push(function (frontpage_gadget) {
return gadget.getUrlFor({
command: 'display',
absolute_url: true,
options: {"jio_key": "/", "page": frontpage_gadget}
})
})
.push(function (came_from) {
return gadget.redirect({
command: 'raw',
options: {
url: UriTemplate.parse(logout_url_template).expand({came_from: came_from})
}
});
});
}
return gadget.notifySubmitted({message: gadget.message2_translation, status: 'success'});
});
})
.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'});
});
});
});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.onStateChange(function () {
var gadget = this,
page_title_translation,
translation_list = [
"Password is different from confirmation",
"Data updated.",
"Reference",
"Password",
"Confirm your Password",
"Login"
];
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('form_view'),
gadget.getSetting("hateoas_url"),
gadget.getTranslationList(translation_list)
]);
})
.push(function (result) {
gadget.message1_translation = result[2][0];
gadget.message2_translation = result[2][1];
page_title_translation = result[2][5];
return result[0].render({
erp5_document: {
"_embedded": {"_view": {
"my_reference": {
"description": "",
"title": result[2][2],
"default": gadget.state.doc.reference,
"css_class": "",
"required": 1,
"editable": 1,
"key": "reference",
"hidden": 0,
"type": "StringField"
},
"my_new_password": {
"description": "",
"title": result[2][3],
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "password",
"hidden": 0,
"type": "PasswordField"
},
"my_confirmation_password": {
"description": "",
"title": result[2][4],
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "password_confirmation",
"hidden": 0,
"type": "PasswordField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["my_reference"], ["my_new_password"], ["my_confirmation_password"] ]
]]
}
});
})
.push(function () {
return gadget.updatePanel({
jio_key: "person_module"
});
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: "change", options: {editable: true}}),
gadget.getUrlFor({command: 'history_previous'}),
gadget.getUrlFor({command: "change", options: {page: "slap_invalidate_login"}})
]);
})
.push(function (url_list) {
var header_dict = {
selection_url: url_list[1],
page_title: page_title_translation + " : " + gadget.state.doc.reference,
delete_url: url_list[2],
save_action: true
};
if (!gadget.state.editable) {
header_dict.edit_content = url_list[0];
}
return gadget.updateHeader(header_dict);
});
});
}(window, rJS, RSVP, jIO, UriTemplate));
\ No newline at end of file
<!DOCTYPE html>
<html>
<!--
data-i18n=Data updated.
data-i18n=Reference
data-i18n=Info
data-i18n=Password is managed by Facebook, so you cannot change password for this login at this site.
data-i18n=Facebook Login:
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Site List</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_erp5_page_slap_facebook_login_view.js" type="text/javascript"></script>
</head>
<body>
<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>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
/*global window, rJS, RSVP, jIO, Blob */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("updatePanel", "updatePanel")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("updateDocument", "updateDocument")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("getTranslationList", "getTranslationList")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
return this.changeState({
jio_key: options.jio_key,
doc: options.doc,
editable: 1
});
})
.onEvent('submit', function () {
var gadget = this;
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (content) {
return gadget.updateDocument(content);
})
.push(function () {
return gadget.notifySubmitted({message: gadget.message_translation, status: 'success'});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.onStateChange(function () {
var gadget = this,
page_title_translation,
translation_list = [
"Data updated.",
"Reference",
"Info",
"Password is managed by Facebook, so you can't change password for this login at this site.",
"Facebook Login:"
];
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('form_view'),
gadget.getSetting("hateoas_url"),
gadget.getTranslationList(translation_list)
]);
})
.push(function (result) {
gadget.message_translation = result[2][0];
page_title_translation = result[2][4];
return result[0].render({
erp5_document: {
"_embedded": {"_view": {
"my_reference": {
"description": "",
"title": result[2][1],
"default": gadget.state.doc.reference,
"css_class": "",
"required": 1,
"editable": 0,
"key": "reference",
"hidden": 0,
"type": "StringField"
},
"note": {
"description": "",
"title": result[2][2],
"default": result[2][3],
"css_class": "",
"required": 1,
"editable": 0,
"key": "note",
"hidden": 0,
"type": "StringField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["my_reference"]]
], [
"bottom",
[["note"]]
]]
}
});
})
.push(function () {
return gadget.updatePanel({
jio_key: "person_module"
});
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: "change", options: {editable: true}}),
gadget.getUrlFor({command: 'history_previous'}),
gadget.getUrlFor({command: "change", options: {page: "slap_invalidate_login"}})
]);
})
.push(function (url_list) {
var header_dict = {
selection_url: url_list[1],
page_title: page_title_translation + " " + gadget.state.doc.reference,
delete_url: url_list[2]
};
if (!gadget.state.editable) {
header_dict.edit_content = url_list[0];
}
return gadget.updateHeader(header_dict);
});
});
}(window, rJS, RSVP));
\ No newline at end of file
<!DOCTYPE html>
<html>
<!--
data-i18n=Data updated.
data-i18n=Reference
data-i18n=Info
data-i18n=Password is managed by Google, so you cannot change password for this login at this site.
data-i18n=Google Login:
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Site List</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_erp5_page_slap_google_login_view.js" type="text/javascript"></script>
</head>
<body>
<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>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
/*global window, rJS, RSVP, jIO, Blob */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("updatePanel", "updatePanel")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("updateDocument", "updateDocument")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("getTranslationList", "getTranslationList")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
return this.changeState({
jio_key: options.jio_key,
doc: options.doc,
editable: 1
});
})
.onEvent('submit', function () {
var gadget = this;
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (content) {
return gadget.updateDocument(content);
})
.push(function () {
return gadget.notifySubmitted({message: gadget.message_translation, status: 'success'});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.onStateChange(function () {
var gadget = this,
page_title_translation,
translation_list = [
"Data updated.",
"Reference",
"Info",
"Password is managed by Google, so you can't change password for this login at this site.",
"Google Login:"
];
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('form_view'),
gadget.getSetting("hateoas_url"),
gadget.getTranslationList(translation_list)
]);
})
.push(function (result) {
gadget.message_translation = result[2][0];
page_title_translation = result[2][4];
return result[0].render({
erp5_document: {
"_embedded": {"_view": {
"my_reference": {
"description": "",
"title": result[2][1],
"default": gadget.state.doc.reference,
"css_class": "",
"required": 1,
"editable": 0,
"key": "reference",
"hidden": 0,
"type": "StringField"
},
"note": {
"description": "",
"title": result[2][2],
"default": result[2][3],
"css_class": "",
"required": 1,
"editable": 0,
"key": "note",
"hidden": 0,
"type": "StringField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["my_reference"]]
], [
"bottom",
[["note"]]
]]
}
});
})
.push(function () {
return gadget.updatePanel({
jio_key: "person_module"
});
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: "change", options: {editable: true}}),
gadget.getUrlFor({command: 'history_previous'}),
gadget.getUrlFor({command: "change", options: {page: "slap_invalidate_login"}})
]);
})
.push(function (url_list) {
var header_dict = {
selection_url: url_list[1],
page_title: page_title_translation + " " + gadget.state.doc.reference,
delete_url: url_list[2]
};
if (!gadget.state.editable) {
header_dict.edit_content = url_list[0];
}
return gadget.updateHeader(header_dict);
});
});
}(window, rJS, RSVP));
\ No newline at end of file
<!doctype html>
<html>
<!--
data-i18n=Login is Disabled.
data-i18n=Login to be disabled:
data-i18n=Warning
data-i18n=Ensure you have another login configured, else you will not be able to login anymore.
data-i18n=Parent Relative Url
data-i18n=Disable Login
-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Delete Project</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_erp5_page_slap_invalidate_login.js"></script>
</head>
<body>
<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>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("updatePanel", "updatePanel")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("getTranslationList", "getTranslationList")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit();
})
.onEvent('submit', function () {
var gadget = this;
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (doc) {
return gadget.getSetting("hateoas_url")
.push(function (url) {
return gadget.jio_putAttachment(doc.relative_url,
url + doc.relative_url + "/ERP5Login_invalidate", {});
});
})
.push(function () {
return gadget.notifySubmitted({message: gadget.message_translation, status: 'success'})
.push(function () {
// Workaround, find a way to open document without break gadget.
return gadget.redirect({"command": "change",
"options": {jio_key: "/", "page": "slap_person_view"}});
});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.declareMethod("render", function (options) {
var gadget = this,
page_title_translation,
translation_list = [
"Login is Disabled.",
"Login to be disabled:",
"Warning",
"Ensure you have another login configured, else you will not be able to login anymore.",
"Parent Relative Url",
"Disable Login"
];
return new RSVP.Queue()
.push(function () {
return gadget.getSetting("hateoas_url")
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('form_view'),
gadget.jio_get(options.jio_key),
gadget.getTranslationList(translation_list)
]);
});
})
.push(function (result) {
options.doc = result[1];
gadget.message_translation = result[2][0];
page_title_translation = result[2][5];
return result[0].render({
erp5_document: {
"_embedded": {"_view": {
"my_title": {
"description": "",
"title": result[2][1] + " ",
"default": options.doc.reference,
"css_class": "",
"required": 1,
"editable": 0,
"key": "reference_label",
"hidden": 0,
"type": "StringField"
},
"message": {
"description": "",
"title": result[2][2],
"default": result[2][3],
"css_class": "",
"required": 1,
"editable": 0,
"key": "title_label",
"hidden": 0,
"type": "StringField"
},
"my_relative_url": {
"description": "",
"title": result[2][4],
"default": options.jio_key,
"css_class": "",
"required": 1,
"editable": 1,
"key": "relative_url",
"hidden": 1,
"type": "StringField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["my_title"], ["my_relative_url"]]
], [
"bottom",
[["message"]]
]]
}
});
})
.push(function () {
return gadget.updatePanel({
jio_key: false
});
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: "change", options: {editable: true}}),
gadget.getUrlFor({command: 'history_previous'})
]);
})
.push(function (result) {
var header_dict = {
selection_url: result[1],
page_title: page_title_translation + ": " + options.doc.reference
};
header_dict.submit_action = true;
return gadget.updateHeader(header_dict);
});
});
}(window, rJS, RSVP));
\ No newline at end of file
<!DOCTYPE html>
<html>
<!--
data-i18n=Password is different from confirmation
data-i18n=New User Login created.
data-i18n=Login Name
data-i18n=Password
data-i18n=Confirm your Password
data-i18n=Add New User Login
data-i18n=The name of a document in ERP5
data-i18n=Portal Type
data-i18n=Parent Relative Url
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Site List</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_erp5_page_slap_person_add_erp5_login.js" type="text/javascript"></script>
</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>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, jIO) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("updatePanel", "updatePanel")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("getTranslationList", "getTranslationList")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit();
})
.onEvent('submit', function () {
var gadget = this,
doc = {};
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return RSVP.all([
form_gadget.getContent(),
gadget.message1_translation,
gadget.message2_translation
]);
})
.push(function (result) {
var k,
content = result[0];
for (k in content) {
if (content.hasOwnProperty(k)) {
if (k !== "password_confirmation") {
doc[k] = content[k];
}
if ((k === "password_confirmation") &&
(content.password !== content.password_confirmation)) {
return gadget.notifySubmitted({message: result[1], status: 'error'});
}
}
}
return gadget.getSetting("hateoas_url")
.push(function (hateoas_url) {
return gadget.jio_putAttachment(content.parent_relative_url,
hateoas_url + gadget.state.jio_key + "/Person_newLogin", doc)
.push(function () {
return gadget.notifySubmitted({message: result[2], status: 'success'});
})
.push(function () {
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'});
});
});
});
});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.declareMethod("render", function (options) {
var gadget = this,
page_title_translation,
translation_list = [
"Login Name",
"Password",
"Confirm your Password",
"Add New User Login",
"The name of a document in ERP5",
"Portal Type",
"Parent Relative Url",
"Password is different from confirmation",
"New User Login created."
];
gadget.state.jio_key = options.jio_key;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('form_view'),
gadget.getTranslationList(translation_list)
]);
})
.push(function (result) {
gadget.message1_translation = result[1][7];
gadget.message2_translation = result[1][8];
page_title_translation = result[1][3];
return result[0].render({
erp5_document: {
"_embedded": {"_view": {
"my_reference": {
"description": "",
"title": result[1][0],
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "reference",
"hidden": 0,
"type": "StringField"
},
"my_new_password": {
"description": "",
"title": result[1][1],
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "password",
"hidden": 0,
"type": "PasswordField"
},
"my_confirmation_password": {
"description": "",
"title": result[1][2],
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "password_confirmation",
"hidden": 0,
"type": "PasswordField"
},
"my_portal_type": {
"description": result[1][4],
"title": result[1][5],
"default": "ERP5 Login",
"css_class": "",
"required": 1,
"editable": 1,
"key": "portal_type",
"hidden": 1,
"type": "StringField"
},
"my_parent_relative_url": {
"description": "",
"title": result[1][6],
"default": gadget.state.jio_key,
"css_class": "",
"required": 1,
"editable": 1,
"key": "parent_relative_url",
"hidden": 1,
"type": "StringField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["my_reference"], ["my_new_password"], ["my_confirmation_password"], ["my_portal_type"], ["my_parent_relative_url"]]
]]
}
});
})
.push(function () {
return gadget.updatePanel({
jio_key: "person_module"
});
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: 'change', options: {page: "slap_controller"}})
]);
})
.push(function (url_list) {
return gadget.updateHeader({
page_title: page_title_translation,
selection_url: url_list[0],
submit_action: true
});
});
});
}(window, rJS, RSVP, jIO));
\ No newline at end of file
<!doctype html>
<html>
<!--
data-i18n=Token is Requested.
data-i18n=This person already has one token, please revoke it before request a new one.
data-i18n=Parent Relative Url
data-i18n=Your Token
data-i18n=Request New Token
-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Add Text Document</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_erp5_page_slap_person_get_token.js"></script>
</head>
<body>
<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>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("updatePanel", "updatePanel")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("getTranslationList", "getTranslationList")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit();
})
.onEvent('submit', function () {
var gadget = this;
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (doc) {
return gadget.getSetting("hateoas_url")
.push(function (url) {
return gadget.jio_getAttachment(doc.relative_url,
url + doc.relative_url + "/Base_getCredentialToken");
})
.push(function (result) {
var msg;
if (result) {
msg = gadget.msg1_translation;
} else {
msg = gadget.msg2_translation;
result = {};
}
return gadget.notifySubmitted({message: msg, status: 'success'})
.push(function () {
// Workaround, find a way to open document without break gadget.
result.jio_key = doc.relative_url;
return gadget.render(result);
});
});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.declareMethod("render", function (options) {
var gadget = this,
page_title_translation,
translation_list = [
"Token is Requested.",
"This person already has one token, please revoke it before request a new one.",
"Parent Relative Url",
"Your Token",
"Request New Token"
];
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('form_view'),
gadget.getTranslationList(translation_list)
]);
})
.push(function (result) {
gadget.msg1_translation = result[1][0];
gadget.msg2_translation = result[1][1];
page_title_translation = result[1][4];
return result[0].render({
erp5_document: {
"_embedded": {"_view": {
"my_relative_url": {
"description": "",
"title": result[1][2],
"default": options.jio_key,
"css_class": "",
"required": 1,
"editable": 1,
"key": "relative_url",
"hidden": 1,
"type": "StringField"
},
"my_access_token": {
"description": "",
"title": result[1][3],
"default": options.access_token,
"css_class": "",
"required": 1,
"editable": 0,
"key": "certificate",
"hidden": (options.access_token === undefined) ? 1 : 0,
"type": "StringField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"center",
[["my_access_token"], ["my_relative_url"]]
]]
}
});
})
.push(function () {
return gadget.updatePanel({
jio_key: "person_module"
});
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: 'change', options: {page: "slap_person_view"}})
]);
})
.push(function (url_list) {
var header_dict = {
page_title: page_title_translation,
submit_action: true,
selection_url: url_list[0]
};
return gadget.updateHeader(header_dict);
});
});
}(window, rJS, RSVP));
\ No newline at end of file
<!doctype html>
<html>
<!--
data-i18n=Certificate is Requested.
data-i18n=This person already has one certificate, please revoke it before request a new one..
data-i18n=Parent Relative Url
data-i18n=Your Certificate
data-i18n=Your Key
data-i18n=Request New Certificate
data-i18n=Title
-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Request New Certificate</title>
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="gadget_erp5_page_slap_person_request_certificate.js" type="text/javascript"></script>
</head>
<body>
<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>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
<!doctype html>
<html>
<!--
data-i18n=Certificate is Revoked.
data-i18n=This person has no certificate to revoke.
data-i18n=Parent Relative Url
data-i18n=Revoke Person Certificate
-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Add Text Document</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_erp5_page_slap_person_revoke_certificate.js"></script>
</head>
<body>
<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>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
import json
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
web_site = context.getWebSiteValue()
request_url = "%s/%s" % (
web_site.getLayoutProperty(
"configuration_slapos_master_web_url",
default=web_site.absolute_url()
),
"Person_getCertificate"
)
person.requestToken(request_url=request_url)
access_token_id = context.REQUEST.get("token")
request = context.REQUEST
response = request.RESPONSE
response.setHeader('Content-Type', "application/json")
return json.dumps({'access_token': access_token_id,
'command_line': "slapos configure client"})
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getCredentialToken</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
import json
edit_kw = {}
person = context.getPortalObject().portal_membership.getAuthenticatedMember().getUserValue()
if person != context.getParentValue():
raise Unauthorized
original_login = context.getReference()
if reference is not None:
edit_kw["reference"] = reference
if password is not None:
edit_kw["password"] = password
if len(edit_kw):
context.edit(**edit_kw)
# This will raise if login is duplicated.
# XXX Improve this later by
context.Base_checkConsistency()
current_username = context.getPortalObject().portal_membership.getAuthenticatedMember().getUserName()
if current_username == original_login:
# We should logout immediately
if 'portal_skin' in context.REQUEST:
context.portal_skins.clearSkinCookie()
context.REQUEST.RESPONSE.expireCookie('__ac', path='/')
context.REQUEST.RESPONSE.expireCookie('__ac_google_hash', path='/')
context.REQUEST.RESPONSE.expireCookie('__ac_facebook_hash', path='/')
context.REQUEST.RESPONSE.setHeader('Location', context.getPermanentURL(context))
context.REQUEST.RESPONSE.setStatus('303')
return json.dumps(context.getRelativeUrl())
This diff is collapsed.
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