Skip to content

Commit

Permalink
Fix shared folders: fix dragging templates
Browse files Browse the repository at this point in the history
  • Loading branch information
torinfo committed Mar 14, 2023
1 parent 018add6 commit 1f07251
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 45 deletions.
3 changes: 2 additions & 1 deletion website_code/php/folder_library.php
Expand Up @@ -30,6 +30,7 @@
}
require_once('file_library.php');
require_once('user_library.php');
require_once('folder_status.php');

_load_language_file("/website_code/php/folder_library.inc");

Expand Down Expand Up @@ -157,7 +158,7 @@ function move_file($template_id,$destination)
// Not updated, so this is probably a project in a shared folder not owned by you
// Check if the project has a shared folder that is the same as the destination folder
$ancestor = get_shared_ancestor($template_id);
if ($ancestor == get_shared_ancestor($destination))
if ($ancestor !== false && $ancestor === get_shared_folder_ancestor($destination))
{
// The project is in a shared folder, and the destination is the same shared folder
// So we may update the project
Expand Down
12 changes: 6 additions & 6 deletions website_code/php/folder_status.php
Expand Up @@ -322,19 +322,19 @@ function get_shared_groups_of_folder($folder_id){
return $result;
}

function get_shared_folder($template_id)
function get_shared_ancestor($template_id)
{
global $xerte_toolkits_site;
$prefix = $xerte_toolkits_site->database_table_prefix;
// Get the folder id of the template

$query = "select folder_id from {$prefix}templaterights where template_id=? and role='creator'";
$query = "select folder from {$prefix}templaterights where template_id=? and role='creator'";
$folder_id = db_query_one($query, array($template_id));

return get_shared_folder_ancestor($folder_id['folder_id']);
return get_shared_folder_ancestor($folder_id['folder'], true);
}

function get_shared_folder_ancestor($folder_id)
function get_shared_folder_ancestor($folder_id, $is_parent_of_template = false)
{
global $xerte_toolkits_site;
$prefix = $xerte_toolkits_site->database_table_prefix;
Expand All @@ -350,7 +350,7 @@ function get_shared_folder_ancestor($folder_id)
// Check if folder itself is shared
$sql = "select fr.folder_parent, count(fr2.folder_id) as nrshared from {$prefix}folderrights fr, {$prefix}folderrights fr2 where fr.folder_id=? and fr.login_id=? and fr2.folder_id=fr.folder_id group by fr2.folder_id, fr.folder_parent";
$result = db_query_one($sql, array($folder, $_SESSION['toolkits_logon_id']));
if ($result != null && $result['nrshared'] > 1 && $folder != $folder_id) {
if ($result != null && $result['nrshared'] > 1) {
return $folder;
}
else{
Expand All @@ -362,7 +362,7 @@ function get_shared_folder_ancestor($folder_id)
}
else
{
if ($folder != $folder_id) {
if ($folder != $folder_id || $is_parent_of_template) {
return $folder;
}
else{
Expand Down
68 changes: 31 additions & 37 deletions website_code/scripts/folders.js
Expand Up @@ -269,66 +269,60 @@ function copy_to_folder(data) {
var node = workspace.nodes[data.node.id];
var destination = workspace.nodes[data.parent];
// Ok, check all the instances where moving is NOT allowed
if(node.type === "folder" && destination.type.includes("_shared") && destination.role != 'creator') {
if (node.type === "folder" && destination.type.includes("_shared") && destination.role != 'creator') {
alert(FOLDER_MOVE_NOT_CREATOR);
refresh_workspace();
return;
}
else if(node.type === "sub_folder_shared")
{
if (node.type === "sub_folder_shared") {
const shared_ancestor = get_shared_ancestor(node);
if (shared_ancestor !== false && shared_ancestor !== get_shared_ancestor(destination))
{
if (shared_ancestor !== false && shared_ancestor !== get_shared_ancestor(destination)) {
// Check contents of node (everything must be owned by the same user)
const contents = get_shared_contents(node);
const roles = contents.map(c => c.role);
if (!roles.every(r => r === 'creator'))
{
if (!roles.every(r => r === 'creator')) {
alert(FOLDER_MOVE_CONTENT_NOT_OWNED);
refresh_workspace();
return;
}
}
if (node.role != 'creator')
{
if (node.role != 'creator') {
alert(FOLDER_MOVE_WITHIN_SHARED_FOLDER_NOT_CREATOR);
refresh_workspace();
return;
}
}else if (node.xot_type == 'file') {
}
if (node.xot_type == 'file') {
const shared_ancestor = get_shared_ancestor(node);
if (shared_ancestor !== false && shared_ancestor !== get_shared_ancestor(destination))
{
if (shared_ancestor !== false && shared_ancestor !== get_shared_ancestor(destination)) {
alert(PROJECT_MOVE_CONTENT_NOT_OWNED);
refresh_workspace();
return;
}
}
else{
setTimeout(function () {
tree.open_node(destination.id)
}, 250);


if (node.xot_type == "folder") {
var data = {
folder_id: node.xot_id,
destination: destination.xot_id
};
} else {
var data = {
template_id: node.xot_id,
destination: destination.xot_id
};
}
$.ajax({
type: "POST",
url: "website_code/php/folders/copy_to_new_folder.php",
data: data,
})
.done(function (response) {
refresh_workspace();
});
setTimeout(function () {
tree.open_node(destination.id)
}, 250);


if (node.xot_type == "folder") {
var data = {
folder_id: node.xot_id,
destination: destination.xot_id
};
} else {
var data = {
template_id: node.xot_id,
destination: destination.xot_id
};
}
$.ajax({
type: "POST",
url: "website_code/php/folders/copy_to_new_folder.php",
data: data,
})
.done(function (response) {
refresh_workspace();
});

}
2 changes: 1 addition & 1 deletion website_code/scripts/screen_display.js
Expand Up @@ -853,7 +853,7 @@ function init_workspace()
"dnd": {
"is_draggable" : function(node) {
console.log('is_draggable called: ', node[0]);
if (node[0].type.includes("_group") || (node[0].type.includes("folder_shared") && workspace.nodes[node[0].id].role !== "creator") || (node[0].original.ChildOfShared && workspace.nodes[node[0].id].role !== "creator") ) {
if (node[0].type.includes("_group") || (node[0].type.includes("folder_shared") && workspace.nodes[node[0].id].role !== "creator")) {
return false;
}
return true;
Expand Down

0 comments on commit 1f07251

Please sign in to comment.