Commit d8627d41 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Make acceptInvitation renderjs-friendly

Redirect to a renderjs page to display a message and return to the site
parent 839922e4
<!DOCTYPE html>
<html>
<!--
data-i18n=Slapos
-->
<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>
<script src="handlebars.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_erp5_page_slap_notify_and_redirect.js" type="text/javascript"></script>
<script id="message-template" type="text/x-handlebars-template">
<p> <center><strong>{{message_to_acknowledge}} </strong> </center> </p>
<p> </p>
<p> <center><a class="ui-btn ui-first-child ui-btn-icon-center" data-i18n="Continue" href="{{redirect_url}}"> Continue </a></center> </p>
</script>
</head>
</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>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Page" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_slap_notify_and_redirect.html</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>rjs_gadget_erp5_page_slap_notify_and_redirect_html</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value> <string>en</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Page</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Gadget SlapOS Notify And Redirect</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>003</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
/*globals console, window, rJS, RSVP, loopEventListener, i18n, Handlebars, $*/
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, rJS, RSVP, Handlebars) {
"use strict";
var gadget_klass = rJS(window),
message_source = gadget_klass.__template_element
.getElementById("message-template")
.innerHTML,
message_template = Handlebars.compile(message_source);
gadget_klass
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareMethod("getContent", function () {
return {};
})
.declareMethod("render", function (options) {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getElement(),
gadget.getUrlFor({command: 'change',
options: {jio_key: "/", page: "slapos"}})
]);
})
.push(function (result) {
var redirect_url = result[1],
element = result[0],
message = options.portal_status_message, advice, page_title;
if (options.message_type === "success") {
page_title = "Success...";
} else if (options.message_type === "error") {
page_title = "Fail...";
} else {
throw new Error("Unknown action to take: " + options.result);
}
element.innerHTML = message_template({
message_to_acknowledge: message,
redirect_url: redirect_url
});
return page_title;
})
.push(function (page_title) {
var header_dict = {
page_title: page_title
};
return gadget.updateHeader(header_dict);
});
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>contributor/person_module/1</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>creators</string> </key>
<value>
<tuple>
<string>cedric.le.ninivin</string>
</tuple>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_slap_notify_and_redirect.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>rjs_gadget_erp5_page_slap_notify_and_redirect_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>modification_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1455284351.49</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>SlapOS Notify and Redirect</string> </value>
</item>
<item>
<key> <string>url_string</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -384,6 +384,8 @@ gadget_erp5_page_slap_invalidate_login.js\n ...@@ -384,6 +384,8 @@ gadget_erp5_page_slap_invalidate_login.js\n
gadget_erp5_page_slap_invalidate_login.html\n gadget_erp5_page_slap_invalidate_login.html\n
gadget_erp5_page_slap_person_add_erp5_login.js\n gadget_erp5_page_slap_person_add_erp5_login.js\n
gadget_erp5_page_slap_person_add_erp5_login.html\n gadget_erp5_page_slap_person_add_erp5_login.html\n
gadget_erp5_page_slap_notify_and_redirect.html\n
gadget_erp5_page_slap_notify_and_redirect.js\n
gadget_erp5_page_slapos.css\n gadget_erp5_page_slapos.css\n
gadget_erp5_page_slapos.html\n gadget_erp5_page_slapos.html\n
gadget_erp5_page_slapos.js\n gadget_erp5_page_slapos.js\n
...@@ -577,7 +579,7 @@ NETWORK:\n ...@@ -577,7 +579,7 @@ NETWORK:\n
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>976.53590.39649.887</string> </value> <value> <string>976.54528.36329.11827</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -595,7 +597,7 @@ NETWORK:\n ...@@ -595,7 +597,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1562173473.25</float> <float>1562426386.8</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
from zExceptions import Unauthorized from zExceptions import Unauthorized
portal = context.getPortalObject() portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person is None:
message_str = "Please login before access the invitation link."
return context.REQUEST.RESPONSE.redirect(
context.getWebSectionValue().absolute_url() + \
"/join_form?portal_status_message=" + \
context.Base_translateString(message_str))
def redirect(message, message_type):
return context.REQUEST.RESPONSE.redirect(
context.getWebSiteValue().absolute_url() + \
"/#/?page=slap_notify_and_redirect&message_type=%s" % message_type + \
"&portal_status_message=%s" % context.Base_translateString(message))
if invitation_token is None: if invitation_token is None:
raise ValueError("Invitation Token is required") message_str = "The Invitation Token is not present on the URL, please review the URL."
return redirect(message_str, "error")
if context.getPortalType() != "Organisation": if context.getPortalType() != "Organisation":
raise Unauthorized("Context is not an Organisation") raise Unauthorized("Context is not an Organisation")
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person is None:
raise ValueError("You must be logged in!")
try: try:
invitation_token = portal.invitation_token_module[invitation_token] invitation_token = portal.invitation_token_module[invitation_token]
except KeyError: except KeyError:
raise ValueError("Invitation Token is not found.") message_str = "The Invitation Token can't be found, please review the URL."
return redirect(message_str, "error")
if invitation_token.getPortalType() != "Invitation Token": if invitation_token.getPortalType() != "Invitation Token":
raise ValueError("Invitation Token is not found.") message_str = "The Invitation Token can't be found, please review the URL."
return redirect(message_str, "error")
if invitation_token.getValidationState() != "validated": if invitation_token.getValidationState() != "validated":
raise ValueError("Invitation Token was already used.") message_str = "The Invitation Token was already used and it cannot be reused, please ask a new one."
return redirect(message_str, "error")
if invitation_token.getSourceValue() == person: if invitation_token.getSourceValue() == person:
raise ValueError("Invitation Token cannot be used by the same user that generated the token!") message_str = "Invitation Token cannot be used by the same user that generated the token!"
return redirect(message_str, "error")
for assignment in person.objectValues(portal_type="Assignment"): for assignment in person.objectValues(portal_type="Assignment"):
if assignment.getSubordination() == context.getRelativeUrl(): if assignment.getSubordination() == context.getRelativeUrl():
invitation_token.invalidate(comment="User already has assignment to the Person") invitation_token.invalidate(comment="User already has assignment to the Person")
return "Already had stuff" message_str = "You sucessfully join a new organisation: %s." % context.getTitle()
return redirect(message_str, "success")
person.newContent( person.newContent(
title="Assigment for Organisation %s" % context.getTitle(), title="Assigment for Organisation %s" % context.getTitle(),
...@@ -38,4 +53,5 @@ person.newContent( ...@@ -38,4 +53,5 @@ person.newContent(
invitation_token.invalidate() invitation_token.invalidate()
return 'Go charlie' message_str = "You sucessfully join a new organisation: %s." % context.getTitle()
return redirect(message_str, "success")
from zExceptions import Unauthorized from zExceptions import Unauthorized
portal = context.getPortalObject() portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person is None:
message_str = "Please login before access the invitation link."
return context.REQUEST.RESPONSE.redirect(
context.getWebSectionValue().absolute_url() + \
"/join_form?portal_status_message=" + \
context.Base_translateString(message_str))
def redirect(message, message_type):
return context.REQUEST.RESPONSE.redirect(
context.getWebSiteValue().absolute_url() + \
"/#/?page=slap_notify_and_redirect&message_type=%s" % message_type + \
"&portal_status_message=%s" % context.Base_translateString(message))
if invitation_token is None: if invitation_token is None:
raise ValueError("Invitation Token is required") message_str = "The Invitation Token is not present on the URL, please review the URL."
return redirect(message_str, "error")
if context.getPortalType() != "Project": if context.getPortalType() != "Project":
raise Unauthorized("Context is not an Organisation") raise Unauthorized("Context is not an Project, please review your URL.")
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person is None:
raise ValueError("You must be logged in!")
try: try:
invitation_token = portal.invitation_token_module[invitation_token] invitation_token = portal.invitation_token_module[invitation_token]
except KeyError: except KeyError:
raise ValueError("Invitation Token is not found.") message_str = "The Invitation Token can't be found, please review the URL."
return redirect(message_str, "error")
if invitation_token.getPortalType() != "Invitation Token": if invitation_token.getPortalType() != "Invitation Token":
raise ValueError("Invitation Token is not found.") message_str = "The Invitation Token can't be found, please review the URL."
return redirect(message_str, "error")
if invitation_token.getValidationState() != "validated": if invitation_token.getValidationState() != "validated":
raise ValueError("Invitation Token was already used.") message_str = "The Invitation Token was already used and it cannot be reused, please ask a new one."
return redirect(message_str, "error")
if invitation_token.getSourceValue() == person: if invitation_token.getSourceValue() == person:
raise ValueError("Invitation Token cannot be used by the same user that generated the token!") message_str = "Invitation Token cannot be used by the same user that generated the token!"
return redirect(message_str, "error")
for assignment in person.objectValues(portal_type="Assignment"): for assignment in person.objectValues(portal_type="Assignment"):
if assignment.getSubordination() == context.getRelativeUrl(): if assignment.getDestinationProject() == context.getRelativeUrl():
invitation_token.invalidate(comment="User already has assignment to the Person") invitation_token.invalidate(comment="User already has assignment to the Person")
return "Already had stuff" message_str = "You sucessfully join a new project: %s." % context.getTitle()
return redirect(message_str, "success")
person.newContent( person.newContent(
title="Assigment for Project %s" % context.getTitle(), title="Assigment for Project %s" % context.getTitle(),
...@@ -38,4 +53,5 @@ person.newContent( ...@@ -38,4 +53,5 @@ person.newContent(
invitation_token.invalidate() invitation_token.invalidate()
return 'Go charlie' message_str = "You sucessfully join a new project: %s." % context.getTitle()
return redirect(message_str, "success")
...@@ -71,6 +71,8 @@ web_page_module/rjs_gadget_erp5_page_slap_load_schema_html ...@@ -71,6 +71,8 @@ web_page_module/rjs_gadget_erp5_page_slap_load_schema_html
web_page_module/rjs_gadget_erp5_page_slap_load_schema_js web_page_module/rjs_gadget_erp5_page_slap_load_schema_js
web_page_module/rjs_gadget_erp5_page_slap_network_list_html web_page_module/rjs_gadget_erp5_page_slap_network_list_html
web_page_module/rjs_gadget_erp5_page_slap_network_list_js web_page_module/rjs_gadget_erp5_page_slap_network_list_js
web_page_module/rjs_gadget_erp5_page_slap_notify_and_redirect_html
web_page_module/rjs_gadget_erp5_page_slap_notify_and_redirect_js
web_page_module/rjs_gadget_erp5_page_slap_organisation_get_invitation_link_html web_page_module/rjs_gadget_erp5_page_slap_organisation_get_invitation_link_html
web_page_module/rjs_gadget_erp5_page_slap_organisation_get_invitation_link_js web_page_module/rjs_gadget_erp5_page_slap_organisation_get_invitation_link_js
web_page_module/rjs_gadget_erp5_page_slap_organisation_view_html web_page_module/rjs_gadget_erp5_page_slap_organisation_view_html
......
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