Handle username with dots in user mentions
This commit is contained in:
parent
b6ea1ac9a4
commit
aafa1de4d5
|
|
@ -7,6 +7,7 @@ New features:
|
|||
|
||||
Improvements:
|
||||
|
||||
* Handle username with dots in user mentions
|
||||
* Replace Chosen jQuery plugin by custom UI component
|
||||
* Rewrite UI component that change user/group roles
|
||||
|
||||
|
|
|
|||
|
|
@ -86,18 +86,23 @@ class Markdown extends Parsedown
|
|||
*/
|
||||
protected function inlineUserLink(array $Excerpt)
|
||||
{
|
||||
if (! $this->isPublicLink && preg_match('/^@([^\s,!.:?]+)/', $Excerpt['text'], $matches)) {
|
||||
$user_id = $this->container['userModel']->getIdByUsername($matches[1]);
|
||||
if (! $this->isPublicLink && preg_match('/^@([^\s,!:?]+)/', $Excerpt['text'], $matches)) {
|
||||
$username = rtrim($matches[1], '.');
|
||||
$user = $this->container['userModel']->getByUsername($username);
|
||||
|
||||
if (! empty($user_id)) {
|
||||
$url = $this->container['helper']->url->href('UserViewController', 'profile', array('user_id' => $user_id));
|
||||
if (! empty($user)) {
|
||||
$url = $this->container['helper']->url->href('UserViewController', 'profile', array('user_id' => $user['id']));
|
||||
|
||||
return array(
|
||||
'extent' => strlen($matches[0]),
|
||||
'extent' => strlen($username) + 1,
|
||||
'element' => array(
|
||||
'name' => 'a',
|
||||
'text' => $matches[0],
|
||||
'attributes' => array('href' => $url, 'class' => 'user-mention-link'),
|
||||
'text' => '@' . $username,
|
||||
'attributes' => array(
|
||||
'href' => $url,
|
||||
'class' => 'user-mention-link',
|
||||
'title' => $user['name'] ?: $user['username'],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ class UserMentionJob extends BaseJob
|
|||
{
|
||||
$users = array();
|
||||
|
||||
if (preg_match_all('/@([^\s,!.:?]+)/', $text, $matches)) {
|
||||
if (preg_match_all('/@([^\s,!:?]+)/', $text, $matches)) {
|
||||
array_walk($matches[1], function (&$username) { $username = rtrim($username, '.'); });
|
||||
$users = $this->db->table(UserModel::TABLE)
|
||||
->columns('id', 'username', 'name', 'email', 'language')
|
||||
->eq('notifications_enabled', 1)
|
||||
|
|
|
|||
|
|
@ -5,12 +5,13 @@ require_once __DIR__.'/../Base.php';
|
|||
use Kanboard\Helper\TextHelper;
|
||||
use Kanboard\Model\ProjectModel;
|
||||
use Kanboard\Model\TaskCreationModel;
|
||||
use Kanboard\Model\UserModel;
|
||||
|
||||
class TextHelperTest extends Base
|
||||
{
|
||||
public function testMarkdownTaskLink()
|
||||
{
|
||||
$helper = new TextHelper($this->container);
|
||||
$textHelper = new TextHelper($this->container);
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
|
||||
|
|
@ -19,26 +20,26 @@ class TextHelperTest extends Base
|
|||
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
|
||||
$project = $projectModel->getById(1);
|
||||
|
||||
$this->assertEquals('<p>Test</p>', $helper->markdown('Test'));
|
||||
$this->assertEquals('<p>Test</p>', $textHelper->markdown('Test'));
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Task <a href="?controller=TaskViewController&action=show&task_id=123">#123</a></p>',
|
||||
$helper->markdown('Task #123')
|
||||
$textHelper->markdown('Task #123')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Task #123</p>',
|
||||
$helper->markdown('Task #123', true)
|
||||
$textHelper->markdown('Task #123', true)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Task <a href="http://localhost/?controller=TaskViewController&action=readonly&token='.$project['token'].'&task_id=1">#1</a></p>',
|
||||
$helper->markdown('Task #1', true)
|
||||
$textHelper->markdown('Task #1', true)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Check that: <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454</a></p>',
|
||||
$helper->markdown(
|
||||
$textHelper->markdown(
|
||||
'Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454'
|
||||
)
|
||||
);
|
||||
|
|
@ -46,44 +47,82 @@ class TextHelperTest extends Base
|
|||
|
||||
public function testMarkdownUserLink()
|
||||
{
|
||||
$h = new TextHelper($this->container);
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>,</p>', $h->markdown('Text @admin,'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>!</p>', $h->markdown('Text @admin!'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>? </p>', $h->markdown('Text @admin? '));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>.</p>', $h->markdown('Text @admin.'));
|
||||
$this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a>: test</p>', $h->markdown('Text @admin: test'));
|
||||
$this->assertEquals('<p>Text @admin @notfound</p>', $h->markdown('Text @admin @notfound', true));
|
||||
$textHelper = new TextHelper($this->container);
|
||||
$userModel = new UserModel($this->container);
|
||||
|
||||
$this->assertEquals(2, $userModel->create(array('username' => 'firstname.lastname', 'name' => 'Firstname Lastname')));
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a> @notfound</p>',
|
||||
$textHelper->markdown('Text @admin @notfound')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a>,</p>',
|
||||
$textHelper->markdown('Text @admin,')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a>!</p>',
|
||||
$textHelper->markdown('Text @admin!')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a>? </p>',
|
||||
$textHelper->markdown('Text @admin? ')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a>.</p>',
|
||||
$textHelper->markdown('Text @admin.')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a>: test</p>',
|
||||
$textHelper->markdown('Text @admin: test')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a>: test</p>',
|
||||
$textHelper->markdown('Text @admin: test')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Text <a href="?controller=UserViewController&action=profile&user_id=2" class="user-mention-link" title="Firstname Lastname">@firstname.lastname</a>. test</p>',
|
||||
$textHelper->markdown('Text @firstname.lastname. test')
|
||||
);
|
||||
|
||||
$this->assertEquals('<p>Text @admin @notfound</p>', $textHelper->markdown('Text @admin @notfound', true));
|
||||
}
|
||||
|
||||
public function testMarkdownAttribute()
|
||||
{
|
||||
$helper = new TextHelper($this->container);
|
||||
$this->assertEquals('<p>Ça marche</p>', $helper->markdownAttribute('Ça marche'));
|
||||
$this->assertEquals('<p>Test with &quot;double quotes&quot;</p>', $helper->markdownAttribute('Test with "double quotes"'));
|
||||
$this->assertEquals('<p>Test with 'single quotes'</p>', $helper->markdownAttribute("Test with 'single quotes'"));
|
||||
$textHelper = new TextHelper($this->container);
|
||||
$this->assertEquals('<p>Ça marche</p>', $textHelper->markdownAttribute('Ça marche'));
|
||||
$this->assertEquals('<p>Test with &quot;double quotes&quot;</p>', $textHelper->markdownAttribute('Test with "double quotes"'));
|
||||
$this->assertEquals('<p>Test with 'single quotes'</p>', $textHelper->markdownAttribute("Test with 'single quotes'"));
|
||||
}
|
||||
|
||||
public function testFormatBytes()
|
||||
{
|
||||
$h = new TextHelper($this->container);
|
||||
$textHelper = new TextHelper($this->container);
|
||||
|
||||
$this->assertEquals('1k', $h->bytes(1024));
|
||||
$this->assertEquals('33.71k', $h->bytes(34520));
|
||||
$this->assertEquals('1k', $textHelper->bytes(1024));
|
||||
$this->assertEquals('33.71k', $textHelper->bytes(34520));
|
||||
}
|
||||
|
||||
public function testContains()
|
||||
{
|
||||
$h = new TextHelper($this->container);
|
||||
$textHelper = new TextHelper($this->container);
|
||||
|
||||
$this->assertTrue($h->contains('abc', 'b'));
|
||||
$this->assertFalse($h->contains('abc', 'd'));
|
||||
$this->assertTrue($textHelper->contains('abc', 'b'));
|
||||
$this->assertFalse($textHelper->contains('abc', 'd'));
|
||||
}
|
||||
|
||||
public function testInList()
|
||||
{
|
||||
$h = new TextHelper($this->container);
|
||||
$this->assertEquals('?', $h->in('a', array('b' => 'c')));
|
||||
$this->assertEquals('c', $h->in('b', array('b' => 'c')));
|
||||
$textHelper = new TextHelper($this->container);
|
||||
$this->assertEquals('?', $textHelper->in('a', array('b' => 'c')));
|
||||
$this->assertEquals('c', $textHelper->in('b', array('b' => 'c')));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,13 +53,19 @@ class UserMentionJobTest extends Base
|
|||
|
||||
$this->assertNotFalse($userModel->create(array('username' => 'user1')));
|
||||
$this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1)));
|
||||
$this->assertNotFalse($userModel->create(array('username' => 'user3.with.dot', 'notifications_enabled' => 1)));
|
||||
|
||||
$users = $userMentionJob->getMentionedUsers('test @user2, test');
|
||||
$this->assertCount(1, $users);
|
||||
$users = $userMentionJob->getMentionedUsers('test @user2, test, @user3.with.dot.');
|
||||
$this->assertCount(2, $users);
|
||||
$this->assertEquals('user2', $users[0]['username']);
|
||||
$this->assertEquals('Foobar', $users[0]['name']);
|
||||
$this->assertEquals('', $users[0]['email']);
|
||||
$this->assertEquals('', $users[0]['language']);
|
||||
|
||||
$this->assertEquals('user3.with.dot', $users[1]['username']);
|
||||
$this->assertEquals('', $users[1]['name']);
|
||||
$this->assertEquals('', $users[1]['email']);
|
||||
$this->assertEquals('', $users[1]['language']);
|
||||
}
|
||||
|
||||
public function testGetMentionedUsersWithNotficationEnabledAndUserLoggedIn()
|
||||
|
|
|
|||
Loading…
Reference in New Issue