Commit 7e382c9b authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: An user can invite another user to its organisation

parent bd7b6ca5
......@@ -30,6 +30,48 @@
});
})
.allowPublicAcquisition("jio_allDocs", function (param_list) {
var gadget = this;
return gadget.jio_allDocs(param_list[0])
.push(function (result) {
var i, value, jio_key_value, len = result.data.total_rows;
for (i = 0; i < len; i += 1) {
if (1 || (result.data.rows[i].value.hasOwnProperty("title"))) {
value = result.data.rows[i].value.title;
result.data.rows[i].value.title = {
field_gadget_param : {
css_class: "",
"default": value,
key: "title",
editable: 1,
url: "gadget_slapos_label_listbox_field.html",
title: "Title",
type: "GadgetField"
}
};
value = result.data.rows[i].value.default_email_text;
result.data.rows[i].value.default_email_text = {
field_gadget_param : {
css_class: "",
"default": value,
key: "default_email_text",
editable: 1,
url: "gadget_slapos_label_listbox_field.html",
title: "Status",
type: "GadgetField"
}
};
result.data.rows[i].value["listbox_uid:list"] = {
key: "listbox_uid:list",
value: 2713
};
}
}
return result;
});
})
.onEvent('submit', function () {
var gadget = this;
return gadget.notifySubmitting()
......@@ -61,7 +103,10 @@
]);
})
.push(function (result) {
var column_list = [],
var column_list = [
['title', 'Title'],
['default_email_text', 'Email']
],
editable = gadget.state.editable;
return result[0].render({
erp5_document: {
......@@ -92,13 +137,13 @@
"column_list": column_list,
"show_anchor": 0,
"default_params": {},
"editable": 0,
"editable": 1,
"editable_column_list": [],
"key": "slap_organisation_computer_listbox",
"lines": 10,
"list_method": "Organisation_getComputerTrackingList",
"list_method": "Organisation_getAssociatedPersonList",
"list_method_template": result[1] + "ERP5Document_getHateoas?mode=search&" +
"list_method=Organisation_getComputerTrackingList&relative_url=" +
"list_method=Organisation_getAssociatedPersonList&relative_url=" +
gadget.state.jio_key + "&default_param_json=eyJpZ25vcmVfdW5rbm93bl9jb2x1bW5zIjogdHJ1ZX0={&query,select_list*,limit*,sort_on*,local_roles*}",
"query": "urn:jio:allDocs?query=",
"portal_type": [],
......@@ -119,12 +164,7 @@
form_definition: {
group_list: [[
"left",
[["my_title"], ["my_reference"], ['my_monitoring_status'],
["my_default_geographical_location_longitude"],
["my_default_geographical_location_latitude"]]
], [
"right",
[['my_organisation_map']]
[["my_title"], ["my_reference"]]
], [
"bottom",
[["listbox"]]
......@@ -135,15 +175,17 @@
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: "change", options: {editable: true}}),
gadget.getUrlFor({command: 'history_previous'}),
gadget.getUrlFor({command: "change", options: {page: "slap_delete_organisation"}})
gadget.getUrlFor({command: "change", options: {page: "slap_person_view"}}),
gadget.getUrlFor({command: "change", options: {page: "slap_delete_organisation"}}),
gadget.getUrlFor({command: "change", options: {page: "slap_organisation_get_invitation_link"}})
]);
})
.push(function (url_list) {
var header_dict = {
selection_url: url_list[1],
page_title: "Site : " + gadget.state.doc.title,
page_title: "Organisation : " + gadget.state.doc.title,
delete_url: url_list[2],
invitation_url: url_list[3],
save_action: true
};
if (!gadget.state.editable) {
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.40660.54394.14284</string> </value>
<value> <string>976.51816.56601.26897</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1561428006.67</float>
<float>1562012361.29</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -43,6 +43,7 @@
['add_login_url', 'Add Login', 'plus'],
['add_organisation_url', 'Add Organisation', 'plus'],
['token_url', 'Token', 'key'],
['invitation_url', 'Invite User', 'key'],
['request_certificate_url', 'Request Certificate', 'certificate'],
['revoke_certificate_url', 'Revoke Certificate', 'ban'],
['rss_url', 'RSS', 'rss'],
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>976.9867.41515.40260</string> </value>
<value> <string>976.40547.45717.53213</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1561421021.85</float>
<float>1561750946.36</float>
<string>UTC</string>
</tuple>
</state>
......
import json
from zExceptions import Unauthorized
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if context.getPortalType() != "Organisation":
raise Unauthorized
web_site = context.getWebSiteValue()
request_method = "POST"
request_url = "%s/%s/%s" % (web_site.absolute_url(), context.getRelativeUrl(), "Organisation_acceptInvitation")
# Maybe it would be better to use another portal_type
access_token = portal.invitation_token_module.newContent(
portal_type="Invitation Token",
source_value=person,
url_string=request_url,
url_method=request_method
)
access_token.validate()
request = context.REQUEST
response = request.RESPONSE
response.setHeader('Content-Type', "application/json")
return json.dumps({'invitation_link': "%s?invitation_token=%s" % (request_url, access_token.getId())})
<?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></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>Base_getInvitationLink</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
portal = context.getPortalObject()
if invitation_token is None:
raise ValueError("Invitation Token is required")
if context.getPortalType() != "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:
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 Site %s" % context.getTitle(),
portal_type="Assignment",
destination_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>Organisation_acceptInvitation</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from Products.ERP5Type.Document import newTempDocument
temp_object_list = []
for assignment in context.getDestinationRelatedValueList(portal_type="Assignment"):
person = assignment.getParentValue()
temp_object_list.append(
newTempDocument(
context, str(person.getId()),
title=person.getTitle(),
default_email_text=person.getDefaultEmailText()
)
)
return temp_object_list
<?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>**kw</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>Organisation_getAssociatedPersonList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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