Additional information on ox.JSON can be found here: http://software.open-xchange.com/OX6...s/ox.JSON.html
And here is a draft version of the register.js file. I should obviously be improved, but it already gives the general idea of the approach.
Code:
var all_users_id; var root_folder_id; var user_calendar_id; var user_calendar_timestamp; start_user_env_initialization(); // entry point for the initialization function start_user_env_initialization() { // set proper permissions on user Calendar so that the calendar is visible // by everyone set_default_user_calendar_permissions(); } function set_default_user_calendar_permissions() { // search for the id of the "All users" group ox.JSON.put(AjaxRoot + "/group?action=search&session=" + session, {"pattern":"All users"}, all_users_ok, operation_nok, false); // search for the id of the user's main calendar ox.JSON.get(AjaxRoot + "/folders?action=root&session=" + session + "&columns=1,300,301", root_folder_ok, operation_nok, false); } function change_user_calendar_permissions() { // change access rights of user Calendar folder // permission bits set to 403710016 correspond to: // - all persmissions everywhere // - admin flag set // 01000000100000010000001000000 // permission bits set to 257 correspond to: // - see the folder => 0000001 // - read all objects => 0000010 // - no permission to modify // - no permission to delete // which leads to the following set of bits: // 00000100000001 => 257 // user should have admin rights // All users should have read-only permissions var calendar_permissions = '{"permissions": [\ {"bits":403710016,\ "entity":"' + config.identifier + '",\ "rights":"",\ "group":false},\ {"bits":257,\ "entity":"' + all_users_id + '",\ "rights":"",\ "group":true}\ ]\ }'; // transform the string into a JSON object var JSON_calendar_permissions = eval('(' + calendar_permissions + ')'); // change calendar permissions ox.JSON.put(AjaxRoot + "/folders?action=update&session=" + session + "&id=" + user_calendar_id + "×tamp=" + user_calendar_timestamp, JSON_calendar_permissions, change_access_rights_ok, operation_nok, true); } function root_folder_ok(reply) { // root folder objectId is the first item in the column retrieved, as // requested by the JSON query root_folder_id = reply.data[0][0] ox.JSON.get(AjaxRoot + "/folders?action=list&session=" + session + "&parent="+ root_folder_id + "&allowed_modules=calendar&columns=1,300,301,6", user_folder_ok, operation_nok, false); } // try to find a folder named "Calendar" and put its corresponding Id in // user_calendar_id function user_folder_ok(reply) { for (r in reply.data) { if (reply.data[r][1] == "Calendar") { user_calendar_id = reply.data[r][0]; user_calendar_timestamp = reply.data[r][3]; break; } } change_user_calendar_permissions(); } function change_access_rights_ok(reply) { } function all_users_ok(reply) { all_users_id = reply.data[0].id; }
Leave a comment: