Skip to content

Commit

Permalink
Several fixes and enhancements for folder sharing
Browse files Browse the repository at this point in the history
 - Show who is in the group when selecting a group folder
 - Show correct sharing information
 - Prohibit creating folders in a shared folder if not owner
  • Loading branch information
torinfo committed Feb 28, 2023
1 parent 3ef7532 commit c561589
Show file tree
Hide file tree
Showing 11 changed files with 418 additions and 123 deletions.
Expand Up @@ -24,6 +24,12 @@

define("SHARING_READONLY","Read only");

define("SHARING_SOURCE","from ");

define("SHARING_SOURCE_FOLDER","folder");

define("SHARING_SOURCE_TEMPLATE","project");

define("SHARING_REMOVE_DESCRIPTION", "Press the button below to remove any sharing rights");

define("SHARING_REMOVE", "Remove");
Expand Down
Expand Up @@ -61,7 +61,7 @@

define ("PROJECT_INFO_NOTSHARED", "Not shared");

define("PROJECT_INFO_OAI", "Oai status");
define("PROJECT_INFO_OAI", "Harvesting status");

define ("PROJECT_INFO_PRIVATE", "Private");

Expand Down Expand Up @@ -89,6 +89,10 @@

define("PROJECT_INFO_XAPI_PUBLISHED", "xAPI: xAPI is enabled for this project through the following link:");

define("GROUP_INFO_NAME", "Name");

define("GROUP_INFO_MEMBERS", "Members");

// PROJECT TAB

define("PROPERTIES_LIBRARY_PROJECT", "Project");
Expand Down
Expand Up @@ -26,6 +26,12 @@

define("SHARING_READONLY","Read only");

define("SHARING_SOURCE","from ");

define("SHARING_SOURCE_FOLDER","folder");

define("SHARING_SOURCE_TEMPLATE","project");

define("SHARING_REMOVE_DESCRIPTION", "Press the button below to remove any sharing rights");

define("SHARING_REMOVE", "Remove");
Expand Down
5 changes: 1 addition & 4 deletions modules/xerte/edithtml.php
Expand Up @@ -277,10 +277,7 @@ function output_editor_code($row_edit, $xerte_toolkits_site, $read_status, $vers
//$pos = strrpos($edit_organisational_logo, '/') + 1;
//$edit_organisational_logo = substr($edit_organisational_logo,0,$pos) . "edit_" . substr($edit_organisational_logo,$pos);

/**
* set up the onunload function used in version control
*/
/* Set flag of whther oai-pmh harvesting is configured and available */
/* Set flag of whether oai-pmh harvesting is configured and available */
$oai_pmh = file_exists($xerte_toolkits_site->root_file_path . "oai-pmh/oai_config.php");

_debug("Starting editor page");
Expand Down
59 changes: 51 additions & 8 deletions website_code/php/display_library.php
Expand Up @@ -433,7 +433,7 @@ function get_folders_in_this_folder($folder_id, $tree_id, $sort_type, $copy_only
$item->text = $row['folder_name'];
$item->role = $row['role'];
$shared = "";
if ($row['role'] != 'creator' && $newtype != 'group'){
if ($row['role'] != 'creator' || $type == 'group_top'){
$shared = 'shared';
}
$item->type = ($shared == "") ? "folder" : "folder" . _ .$shared;
Expand Down Expand Up @@ -876,7 +876,9 @@ function get_workspace_folders($folder_id, $tree_id, $sort_type, $copy_only=fals
$query_response[$index]['type'] = ($shared == "") ? "folder" : "folder_" .$shared;

}
while ($unassigned_found)
$max_depth = 50;
$level = 0;
while ($unassigned_found && $level < $max_depth)
{
$currlevel = $nextlevel;
$nextlevel = array();
Expand All @@ -901,8 +903,25 @@ function get_workspace_folders($folder_id, $tree_id, $sort_type, $copy_only=fals
}
}
}
$level++;
}

if ($unassigned_found)
{
// Something went wrong here, parent is not found even at depth level $max_depth
// Log to error log
$incomplete_rows = array();
foreach($query_response as $index=>$row)
{
if (!isset($row['tree_id']) && $query_response[$index]['role'] == 'creator')
{
$incomplete_rows[] = $row;
}
}
$error_msg = "Incomplete rows in folder tree. Depth level: $max_depth. Rows: " . print_r($incomplete_rows, true);
error_log("Error in get_workspace_folders: " . $error_msg);
_debug("Error in get_workspace_folders: " . $error_msg);
}

$sharedFolders = [];
foreach ($query_response as $index => $folder){
Expand All @@ -927,9 +946,6 @@ function get_workspace_folders($folder_id, $tree_id, $sort_type, $copy_only=fals
}
}




/*$query = "SELECT * FROM folderdetails where";
$params = [];
foreach ($query_response as $folder){
Expand Down Expand Up @@ -1049,6 +1065,29 @@ function get_group_contents($group_id, $tree_id, $sort_type, $copy_only) {
return $files;
}

function insert_groupitems_into_workspace_items($workspace_items, $group_items){
// Get ID of root folder
$root_id = $workspace_items[0]->id;

// Create a new array and start copying $workspace_itmes until we find the first item with xot_type file and parent = $root_id
$new_workspace_items = array();
$i = 0;
while ($workspace_items[$i]->xot_type != 'file' || $workspace_items[$i]->parent != $root_id) {
$new_workspace_items[] = $workspace_items[$i];
$i++;
}
// Copy in all the group_items
foreach ($group_items as $group_item) {
$new_workspace_items[] = $group_item;
}
// Copy in the rest of the workspace_items
while ($i < count($workspace_items)) {
$new_workspace_items[] = $workspace_items[$i];
$i++;
}
return $new_workspace_items;
}


/**
* Builds an array with the whole structure of the workspace suitable for jsTree
Expand Down Expand Up @@ -1135,6 +1174,8 @@ function get_users_projects($sort_type, $copy_only=false)
$groups = db_query($query, array($_SESSION['toolkits_logon_id']));
$workspace->groups = array();
$counter = 0;
$group_items = array();

foreach ($groups as $group){
$workspace->groups[$counter] = "ID_" . $_SESSION['toolkits_logon_id'] . "_G" . $group['group_id'];
$item = new stdClass();
Expand All @@ -1145,13 +1186,12 @@ function get_users_projects($sort_type, $copy_only=false)
$item->type = "group";
$item->xot_type = "group";

$workspace->items[] = $item;
$group_items[] = $item;
$workspace->nodes[$item->id] = $item;
$items = get_folder_contents($item->xot_id, $item->id, $sort_type, $copy_only, $type = "group_top");
if ($items) {

$workspace->items = array_merge($workspace->items, $items);

$group_items = array_merge($group_items, $items);

foreach($items as $item)
{
Expand All @@ -1162,6 +1202,9 @@ function get_users_projects($sort_type, $copy_only=false)
$counter++;
}

// Now insert the group items into the workspace items after the normal folders
$workspace->items = insert_groupitems_into_workspace_items($workspace->items, $group_items);

//recycle bin content
$query = "select folder_id from {$prefix}folderdetails where folder_name=? AND login_id = ?";
$params = array("recyclebin", $_SESSION['toolkits_logon_id']);
Expand Down
77 changes: 65 additions & 12 deletions website_code/php/folderproperties/remove_sharing_folder.php
Expand Up @@ -57,13 +57,21 @@
db_query($query_to_delete_share, $params);


$query_to_get_user_workspace = "SELECT * FROM {$prefix}folderdetails where login_id = ? and folder_name != ?";
$workspaceId = db_query($query_to_get_user_workspace, array($id, "recyclebin"));

//uit folderrights halen
//remove from folderrights
$query_to_get_folders = "SELECT folder_id, folder_parent FROM {$prefix}folderdetails where folder_parent != 0";
$folders = db_query($query_to_get_folders, array());

// Place all items that are not shared anymore in the user's private folder
// - 1. Templates owned by the user
// - 2. Folders owned by the user
// - 3. Templates owned by anyone else then the user and stored in folders from 2.
//
// Step 1. Templates owned by the user (that is being unshared)
$workspaceId = get_user_root_folder_by_id($id);

$changeParams = array($workspaceId, $id);

$foldersToCheck = array($folder_id);
for ($i = 0; $i < count($foldersToCheck); $i++){
foreach ($folders as $index =>$folder){
Expand All @@ -73,24 +81,69 @@
}
}

$changeParams = array($workspaceId[0]["folder_id"], $id, "creator");
$query_to_change_folder = "UPDATE {$prefix}templaterights SET folder = ? where user_id = ? and role = ? and (";
$query_to_change_folder = "UPDATE {$prefix}templaterights SET folder = ? where user_id = ? and role = 'creator' and folder in (";
$first = true;
foreach ($foldersToCheck as $folder){
if($folder_id == $folder){
$query_to_change_folder .= " folder = ? ";
array_push($changeParams, $folder);
}else{
$query_to_change_folder .= " or folder = ? ";
array_push($changeParams, $folder);
if(!$first){
$query_to_change_folder .= ", ";
}
$query_to_change_folder .= "?";
array_push($changeParams, $folder);
}

$query_to_change_folder .= ")";

db_query($query_to_change_folder, $changeParams);


// Step 2. Folders owned by the user (that is being unshared)
// Do not only update the folders, but get the ids of the folders as well, we will use those again in step 3.
$getParams = array($id);
$changeParams = array($workspaceId, $id);


$query_to_get_folders = "SELECT folder_id FROM {$prefix}folderrights where login_id = ? and role='creator' and folder_parent in (";
$query_to_change_folders = "UPDATE {$prefix}folderrights SET folder_parent = ? where login_id = ? and role='creator' and folder_parent in (";
$first = true;
foreach ($foldersToCheck as $folder){
if(!$first){
$query_to_get_folder .= ", ";
$query_to_change_folder .= ", ";
}
$query_to_get_folder .= "?";
$query_to_change_folder .= "?";
array_push($getParams, $folder);
array_push($changeParams, $folder);
}
$query_to_get_folders .= ")";
$query_to_change_folders .= ")";
$folders = db_query($query_to_get_folders, $getParams);
db_query($query_to_change_folders, $changeParams);

// Step 3. Templates owned by anyone else then the user and stored in folders from 2 need to be moved to the workspace of the owner
$getParams = array($id);
$query_to_get_templates = "SELECT template_id, user_id FROM {$prefix}templaterights where user_id != ? and role='creator' and folder in (";
$first = true;
foreach ($folders as $folder){
if(!$first){
$query_to_get_templates .= ", ";
}
$query_to_get_templates .= "?";
array_push($getParams, $folder);
}
$query_to_get_templates .= ")";

$templates = db_query($query_to_get_templates, $getParams);
// Step 3b for each user, move templates to the root folder of that user
$changeParams = array();
$query_to_change_folder = "";
foreach ($templates as $template)
{
$workspaceId = get_user_root_folder_by_id($template['user_id']);
$query_to_change_folder .= "UPDATE {$prefix}templaterights SET folder = ? where template_id = ? and user_id = ?;";
$changeParams[] = $workspaceId;
$changeParams[] = $template['template_id'];
$changeParams[] = $template['user_id'];
}
db_query($query_to_change_folder, $params);
}
}
19 changes: 5 additions & 14 deletions website_code/php/properties/gift_this_template.php
Expand Up @@ -86,6 +86,7 @@ function copy_loop($start_path, $final_path){

include "../template_library.php";
include "../template_status.php";
include "../user_library.php";


if (!isset($_SESSION['toolkits_logon_id']))
Expand Down Expand Up @@ -136,14 +137,10 @@ function copy_loop($start_path, $final_path){

$ok = db_query($query_to_gift, $params);

$query_for_root_folder = "select folder_id from {prefix}folderdetails where login_id= ? and folder_name != ?";
$params = array($user_id, 'recyclebin');

$row_folder = db_query_one($query_for_root_folder, $params);

$root_folder = get_user_root_folder_by_id($user_id);

$query_to_gift = "update {$prefix}templaterights set user_id = ?, folder = ? WHERE template_id = ?";
$params = array($user_id, $row_folder['folder_id'], $tutorial_id);
$params = array($user_id, $root_folder, $tutorial_id);

db_query($query_to_gift, $params);

Expand Down Expand Up @@ -192,19 +189,13 @@ function copy_loop($start_path, $final_path){

$row_currentrights = db_query_one($query_for_currentdetails, $params);

$query_for_root_folder = "select folder_id from {$prefix}folderdetails where login_id= ? AND folder_name != ? AND folder_parent=0";
$params = array($user_id, 'recyclebin');

$row_folder = db_query_one($query_for_root_folder, $params);
$root_folder = get_user_root_folder_by_id($user_id);

$create_rights_query = "INSERT INTO {$prefix}templaterights (template_id, user_id, role,folder,notes) VALUES (?,?,?,?,?)";
$params = array($new_template_id, $user_id, "creator", $row_folder['folder_id'], '');
$params = array($new_template_id, $user_id, "creator", $root_folder, '');

db_query($create_rights_query, $params);




$query_for_new_login = "select firstname, surname, username from {$prefix}logindetails where login_id= ?";
$params = array($user_id);

Expand Down

0 comments on commit c561589

Please sign in to comment.