Accept more file types for FileLinkProvider

This commit is contained in:
Frederic Guillot
2016-10-09 21:17:14 -04:00
parent 9302ff82f3
commit 26e901dfe6
3 changed files with 39 additions and 3 deletions

View File

@@ -12,6 +12,11 @@ use Kanboard\Core\ExternalLink\ExternalLinkProviderInterface;
*/ */
class FileLinkProvider extends BaseLinkProvider implements ExternalLinkProviderInterface class FileLinkProvider extends BaseLinkProvider implements ExternalLinkProviderInterface
{ {
protected $excludedPrefixes= array(
'http',
'ftp',
);
/** /**
* Get provider name * Get provider name
* *
@@ -55,7 +60,17 @@ class FileLinkProvider extends BaseLinkProvider implements ExternalLinkProviderI
*/ */
public function match() public function match()
{ {
return strpos($this->userInput, 'file://') === 0; if (strpos($this->userInput, '://') === false) {
return false;
}
foreach ($this->excludedPrefixes as $prefix) {
if (strpos($this->userInput, $prefix) === 0) {
return false;
}
}
return true;
} }
/** /**

View File

@@ -32,8 +32,14 @@
<div class="dropdown"> <div class="dropdown">
<a href="#" class="dropdown-menu dropdown-menu-link-icon"><i class="fa fa-cog fa-fw"></i><i class="fa fa-caret-down"></i></a> <a href="#" class="dropdown-menu dropdown-menu-link-icon"><i class="fa fa-cog fa-fw"></i><i class="fa fa-caret-down"></i></a>
<ul> <ul>
<li><?= $this->url->link(t('Edit'), 'TaskExternalLinkController', 'edit', array('link_id' => $link['id'], 'task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'popover') ?></li> <li>
<li><?= $this->url->link(t('Remove'), 'TaskExternalLinkController', 'confirm', array('link_id' => $link['id'], 'task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'popover') ?></li> <i class="fa fa-edit fa-fw"></i>
<?= $this->url->link(t('Edit'), 'TaskExternalLinkController', 'edit', array('link_id' => $link['id'], 'task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'popover') ?>
</li>
<li>
<i class="fa fa-trash-o fa-fw"></i>
<?= $this->url->link(t('Remove'), 'TaskExternalLinkController', 'confirm', array('link_id' => $link['id'], 'task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'popover') ?>
</li>
</ul> </ul>
</div> </div>
</td> </td>

View File

@@ -31,6 +31,21 @@ class FileLinkProviderTest extends Base
$attachmentLinkProvider->setUserTextInput('file:///tmp/test.txt'); $attachmentLinkProvider->setUserTextInput('file:///tmp/test.txt');
$this->assertTrue($attachmentLinkProvider->match()); $this->assertTrue($attachmentLinkProvider->match());
$attachmentLinkProvider->setUserTextInput('owncloud:///tmp/test.txt');
$this->assertTrue($attachmentLinkProvider->match());
$attachmentLinkProvider->setUserTextInput('notebooks:///tmp/test.txt');
$this->assertTrue($attachmentLinkProvider->match());
$attachmentLinkProvider->setUserTextInput('http://google.com/');
$this->assertFalse($attachmentLinkProvider->match());
$attachmentLinkProvider->setUserTextInput('https://google.com/');
$this->assertFalse($attachmentLinkProvider->match());
$attachmentLinkProvider->setUserTextInput('ftp://google.com/');
$this->assertFalse($attachmentLinkProvider->match());
$attachmentLinkProvider->setUserTextInput(''); $attachmentLinkProvider->setUserTextInput('');
$this->assertFalse($attachmentLinkProvider->match()); $this->assertFalse($attachmentLinkProvider->match());
} }