cancel
Showing results for 
Search instead for 
Did you mean: 

[Solved] Problem with move function

olivierdz
Champ in-the-making
Champ in-the-making
Hi,
I created a javascript script that move a file to another space according to some parameters.
This script is automatically executed when some data in the file has changed.
The user has collaborator rights on source space and also collaborator rights on destination space.
The problem is the following :
If the user is "admin", I have no problem.
If the user is not admin, the script crash at the document.move call.
If the user is not admin and document.move is commented, the script is executed correctly.
So, I think this is a problem of rights, but I cannot find out what is the problem.
Here is the code :


var fName = "";
if ( document.properties["sige:Confidential"] )
   fName = "DATA/Archives/Confidentiel";
else
   fName = "DATA/Archives/" + document.properties["sige:ArType"];

var destFolder = companyhome.childByNamePath(fName);

if ( destFolder )
{
   // Some debug info
   var d = companyhome.childByNamePath("debug.log");
   var c = d.content;
   c = c + "Ok : " + destFolder.properties.name + "\n";
   d.content = c;
   d.save();

   document.move(destFolder);  // <= crash here if not admin user
}
else
{
   // Some debug info
   var d = companyhome.childByNamePath("debug.log");
   var c = d.content;
   d.content = c + "Cannot get object for " + fName + "\n";
   d.save();
}

function result()
{
   return 1;
}
result();

The error is the following :
Une erreur système s'est produite pendant l'opération : 00140010 Failed to execute script 'workspace://SpacesStore/5c121eae-5458-4af1-8a76-ba059617385e': 00140009 Access refusé. Vous n'avez pas la permission de réaliser cette opération.
Translated : System error during operation : ……. : Access refused. You are not allowed to do this operation.

The log file says no more than the message above.

Thanks for your help.
Olivier
2 REPLIES 2

invictus9
Champ in-the-making
Champ in-the-making
To deal with a similar problem, I put

if ( destFolder.hasPermission("CreateChildren") ) {
   … move the file …
}

around the move(). It prevents the crash, which is always a good thing.

From the code above, I wonder if your non-admin account does have CreateChildren permission on the destination folder.

olivierdz
Champ in-the-making
Champ in-the-making
The user has permission to create children on destFolder.
But I made some check with "hasPermission" function and found that the user doesn't have the "Delete" permission on source folder ("collaborator" role doesn't allow to delete). As the move function have to delete file after copy, that's normal that this does not work.
I give "coordinator" role to my user on source folder, and that's ok now.