Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please disconnect delete and rename #1545

Closed
paulcanning opened this issue Jul 21, 2016 · 8 comments
Closed

Please disconnect delete and rename #1545

paulcanning opened this issue Jul 21, 2016 · 8 comments
Labels

Comments

@paulcanning
Copy link

So it seems that the only way to allow renaming of a file is to have it unlocked (locked = 0)

But doing so also lets the user delete the file.

I want to let users rename, but not delete.

Can you either add in a flag for delete protection, or disconnect rename and delete so I can do one but not the other?

@nao-pon
Copy link
Member

nao-pon commented Jul 22, 2016

@paulcanning

I want to let users rename, but not delete.

What about write = 0?

elFinder complies with the file attributes of a typical file system.

@paulcanning
Copy link
Author

paulcanning commented Jul 22, 2016

I tried read, write and locked with all combinations of 0 and 1.

Files were only re-nameable when locked was set to 0

NB setting write to 0 makes no sense anyway, if the file is un-writable, you shouldn't be able to rename it!

@paulcanning
Copy link
Author

Here is a screenshot showing a file that has the following attributes:

read = 1
write = 0
locked = 0

As you can see, the rename icon is clickable (not muted/greyed out)

@nao-pon
Copy link
Member

nao-pon commented Jul 22, 2016

Renamable operate on files of the write-protected is a specification of the common file system, such as Linux.

@paulcanning
Copy link
Author

I am running this on a Linux server, connected to Google Cloud Storage.

I have provided evidence that write does not effect renaming, and that renaming and delete are both connected to locked.

They need to be separated.

@nao-pon
Copy link
Member

nao-pon commented Jul 23, 2016

The operation of elFinder by the file attribute is by design. If you need to change the specifications, please customize the elFinder.

@nao-pon nao-pon closed this as completed Jul 23, 2016
@paulcanning
Copy link
Author

If that is the case, can you provide information on how to enable/disable certain toolbar icons based on specific file attributes?

Example, if I give a file an extra attribute of rename = false then the rename icon only is disabled.

nao-pon added a commit that referenced this issue Jul 26, 2016
for easy customization of the ui-command for each volume.

rel. #1545, #1549.

**Example to disable `rm` of not writable items in selected volume**

- Front end  - JavaScript
```javascript
// command `rm2` extends `rm`
(elFinder.prototype.commands.rm2 = function() {
	this.getstate = function(sel) {
		var fm = this.fm;
		sel = sel || fm.selected();
		return !this._disabled && sel.length &&
			// check `write` too
			$.map(sel, function(h) { var f = fm.file(h);
return f && f.phash && !f.locked && f.write ? h : null }).length ==
sel.length
			? 0 : -1;
	};
}).prototype = {
	extendsCmd : 'rm', // extends command name
	forceLoad    : true // to force load
};

var options = {
    url  : 'php/connector.php',
}
$('#elfinder').elfinder(options);

```
- Back end - PHP connector
```php
// customized volume driver
class elFinderMyVolumeLocalFileSystem extends
elFinderVolumeLocalFileSystem extends
{
    protected function remove($path, $force = false) {
        if (! $force && ($stat = $this->stat($path)) && !
$stat['write']) {
            return $this->setError(elFinder::ERROR_PERM_DENIED,
$this->path($stat['hash']));
        }
        return parent::remove($path, $force);
    }
}

$opts = array(
    'roots'  => array(
        array(
            'driver' => 'LocalFileSystem',
            'path'   => '/path/to/files/',
            'URL'    => 'http://localhost/to/files/',
        ),
        array(
            'driver' => 'MyLocalFileSystem',
            'path'   => '/path/to/files2/',
            'URL'    => 'http://localhost/to/files2/',
            'uiCmdMap' => 'array('rm' => 'rm2'), // use `rm2` instead `rm`
        ),
    )
);

// run elFinder
$connector = new elFinderConnector(new elFinder($opts));
$connector->run();
```
@nao-pon nao-pon added the howto label Aug 25, 2016
@nao-pon
Copy link
Member

nao-pon commented Aug 25, 2016

Example to disable rm of not writable items in selected volume elFinder >= 2.1.15

  • Front end - JavaScript
// command `rm2` extends `rm`
(elFinder.prototype.commands.rm2 = function() {
    this.getstate = function(sel) {
        var fm = this.fm;
        sel = sel || fm.selected();
        return !this._disabled && sel.length &&
            // check `write` too
            $.map(sel, function(h) { var f = fm.file(h);
return f && f.phash && !f.locked && f.write ? h : null }).length ==
sel.length
            ? 0 : -1;
    };
}).prototype = {
    extendsCmd : 'rm', // extends command name
    forceLoad    : true // to force load
};

var options = {
    url  : 'php/connector.php',
}
$('#elfinder').elfinder(options);
  • Back end - PHP connector
// customized volume driver
class elFinderMyVolumeLocalFileSystem extends
elFinderVolumeLocalFileSystem extends
{
    protected function remove($path, $force = false) {
        if (! $force && ($stat = $this->stat($path)) && !
$stat['write']) {
            return $this->setError(elFinder::ERROR_PERM_DENIED,
$this->path($stat['hash']));
        }
        return parent::remove($path, $force);
    }
}

$opts = array(
    'roots'  => array(
        array(
            'driver' => 'LocalFileSystem',
            'path'   => '/path/to/files/',
            'URL'    => 'http://localhost/to/files/',
        ),
        array(
            'driver' => 'MyLocalFileSystem',
            'path'   => '/path/to/files2/',
            'URL'    => 'http://localhost/to/files2/',
            'uiCmdMap' => 'array('rm' => 'rm2'), // use `rm2` instead `rm`
        ),
    )
);

// run elFinder
$connector = new elFinderConnector(new elFinder($opts));
$connector->run();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants