Commit 925a2770 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Allow User invite other user to a Project

parent f66a381c
<!doctype html>
<html>
<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_organisation_get_invitation_link.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>
<?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>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>content_type</string> </key>
<value> <string>text/html</string> </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_project_get_invitation_link.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_project_get_invitation_link_html</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.46</float>
<string>UTC</string>
</tuple>
</state>
</object>
</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>Slap Project Get Invitation Link</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>
/*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("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
/////////////////////////////////////////////////////////////////
// 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_getInvitationLink");
})
.push(function (result) {
return gadget.notifySubmitted({message: "New Invitation link generated.", 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;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('form_view')
]);
})
.push(function (result) {
return result[0].render({
erp5_document: {
"_embedded": {"_view": {
"my_relative_url": {
"description": "",
"title": "Parent Relative Url",
"default": options.jio_key,
"css_class": "",
"required": 1,
"editable": 1,
"key": "relative_url",
"hidden": 1,
"type": "StringField"
},
"my_invitation_link": {
"description": "",
"title": "Your Invitation Link",
"default": options.invitation_link,
"css_class": "",
"required": 1,
"editable": 0,
"key": "invitation_link",
"hidden": (options.invitation_link === undefined) ? 1: 0,
"type": "StringField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"center",
[["my_invitation_link"], ["my_relative_url"]]
]]
}
});
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: 'history_previous'})
]);
})
.push(function (url_list) {
var header_dict = {
page_title: "Generate New Invitation Link",
submit_action: true,
selection_url: url_list[0]
};
return gadget.updateHeader(header_dict);
});
});
}(window, rJS, RSVP));
\ 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_project_get_invitation_link.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_project_get_invitation_link_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 Project Get Invitation Link JS</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>
......@@ -194,7 +194,8 @@
return RSVP.all([
gadget.getUrlFor({command: "change", options: {editable: true}}),
gadget.getUrlFor({command: 'history_previous'}),
gadget.getUrlFor({command: "change", options: {page: "slap_delete_project"}})
gadget.getUrlFor({command: "change", options: {page: "slap_delete_project"}}),
gadget.getUrlFor({command: "change", options: {page: "slap_project_get_invitation_link"}})
]);
})
.push(function (url_list) {
......@@ -202,6 +203,7 @@
selection_url: url_list[1],
page_title: "Project : " + gadget.state.doc.title,
delete_url: url_list[2],
invitation_url: url_list[3],
save_action: true
};
if (!gadget.state.editable) {
......
......@@ -227,7 +227,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>superrafael</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -241,7 +241,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.51731.9751.49032</string> </value>
<value> <string>974.62049.17150.785</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -259,7 +259,7 @@
</tuple>
<state>
<tuple>
<float>1554315625.43</float>
<float>1562091422.13</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -261,6 +261,8 @@ gadget_erp5_page_slap_add_organisation.html\n
gadget_erp5_page_slap_add_organisation.js\n
gadget_erp5_page_slap_organisation_get_invitation_link.js\n
gadget_erp5_page_slap_organisation_get_invitation_link.html\n
gadget_erp5_page_slap_project_get_invitation_link.js\n
gadget_erp5_page_slap_project_get_invitation_link.html\n
gadget_erp5_page_slap_add_project.html\n
gadget_erp5_page_slap_add_project.js\n
gadget_erp5_page_slap_add_related_event.html\n
......@@ -571,7 +573,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.40666.4477.59699</string> </value>
<value> <string>976.53162.22511.22903</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -589,7 +591,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1562033682.52</float>
<float>1562093475.71</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -4,13 +4,15 @@ from zExceptions import Unauthorized
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if context.getPortalType() != "Organisation":
# Only Project and Organisation can generate an invitation
if context.getPortalType() not in ["Organisation", "Project"]:
raise Unauthorized
web_site = context.getWebSiteValue()
request_method = "POST"
script_name = "%s_acceptInvitation" % context.getPortalType()
request_url = "%s/%s/%s" % (web_site.absolute_url(), context.getRelativeUrl(), "Organisation_acceptInvitation")
request_url = "%s/%s/%s" % (web_site.absolute_url(), context.getRelativeUrl(), script_name)
# Maybe it would be better to use another portal_type
access_token = portal.invitation_token_module.newContent(
......
......@@ -32,7 +32,7 @@ for assignment in person.objectValues(portal_type="Assignment"):
return "Already had stuff"
person.newContent(
title="Assigment for Site %s" % context.getTitle(),
title="Assigment for Organisation %s" % context.getTitle(),
portal_type="Assignment",
destination_value=context).open()
......
from zExceptions import Unauthorized
portal = context.getPortalObject()
if invitation_token is None:
raise ValueError("Invitation Token is required")
if context.getPortalType() != "Project":
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:
invitation_token = portal.invitation_token_module[invitation_token]
except KeyError:
raise ValueError("Invitation Token is not found.")
if invitation_token.getPortalType() != "Invitation Token":
raise ValueError("Invitation Token is not found.")
if invitation_token.getValidationState() != "validated":
raise ValueError("Invitation Token was already used.")
if invitation_token.getSourceValue() == person:
raise ValueError("Invitation Token cannot be used by the same user that generated the token!")
for assignment in person.objectValues(portal_type="Assignment"):
if assignment.getSubordination() == context.getRelativeUrl():
invitation_token.invalidate(comment="User already has assignment to the Person")
return "Already had stuff"
person.newContent(
title="Assigment for Project %s" % context.getTitle(),
portal_type="Assignment",
destination_project_value=context).open()
invitation_token.invalidate()
return 'Go charlie'
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<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>invitation_token=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Project_acceptInvitation</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -91,6 +91,8 @@ web_page_module/rjs_gadget_erp5_page_slap_person_revoke_certificate_html
web_page_module/rjs_gadget_erp5_page_slap_person_revoke_certificate_js
web_page_module/rjs_gadget_erp5_page_slap_person_view_html
web_page_module/rjs_gadget_erp5_page_slap_person_view_js
web_page_module/rjs_gadget_erp5_page_slap_project_get_invitation_link_html
web_page_module/rjs_gadget_erp5_page_slap_project_get_invitation_link_js
web_page_module/rjs_gadget_erp5_page_slap_project_list_html
web_page_module/rjs_gadget_erp5_page_slap_project_list_js
web_page_module/rjs_gadget_erp5_page_slap_project_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