Skip to content

Commit 95db364

Browse files
authored
Profile Twig UI Part 2 (Assets and Assistance)
1 parent 84c8273 commit 95db364

File tree

8 files changed

+436
-500
lines changed

8 files changed

+436
-500
lines changed

js/RichText/UserMention.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ window.GLPI.RichText.UserMention = class {
9999
searchText: pattern,
100100
_idor_token: this.idorToken,
101101
}
102-
).done(
102+
).then(
103103
(data) => {
104104
let results = data.results;
105105

phpunit/functional/Glpi/RichText/UserMentionTest.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@
3737
use CommonITILActor;
3838
use CommonITILObject;
3939
use DbTestCase;
40+
use Glpi\RichText\UserMention;
4041
use Notification;
4142
use Notification_NotificationTemplate;
4243
use NotificationTarget;
4344
use NotificationTemplate;
4445
use NotificationTemplateTranslation;
4546
use PHPUnit\Framework\Attributes\DataProvider;
47+
use Profile;
4648
use Session;
4749
use Ticket;
4850
use Ticket_User;
@@ -610,4 +612,91 @@ private function createNotification(string $itemtype): void
610612
);
611613
$this->assertGreaterThan(0, $target_id);
612614
}
615+
616+
public function testDisableMentions()
617+
{
618+
global $CFG_GLPI;
619+
$CFG_GLPI['use_notifications'] = 1;
620+
$CFG_GLPI['notifications_mailing'] = 1;
621+
622+
$this->login();
623+
$profiles_id = $_SESSION['glpiactiveprofile']['id'];
624+
$profile = new Profile();
625+
$profile->update([
626+
'id' => $profiles_id,
627+
'use_mentions' => UserMention::USER_MENTION_DISABLED,
628+
]);
629+
630+
$ticket = new Ticket();
631+
$ticket->add([
632+
'name' => __FUNCTION__,
633+
'content' => __FUNCTION__,
634+
'entities_id' => $this->getTestRootEntity(true),
635+
]);
636+
637+
$options = UserMention::getMentionOptions($ticket);
638+
$this->assertEmpty($options['users']);
639+
$this->assertFalse($options['full']);
640+
}
641+
642+
public function testRestrictMentions()
643+
{
644+
global $CFG_GLPI;
645+
$CFG_GLPI['use_notifications'] = 1;
646+
$CFG_GLPI['notifications_mailing'] = 1;
647+
648+
$this->login();
649+
$profiles_id = $_SESSION['glpiactiveprofile']['id'];
650+
$profile = new Profile();
651+
$profile->update([
652+
'id' => $profiles_id,
653+
'use_mentions' => UserMention::USER_MENTION_RESTRICTED,
654+
]);
655+
656+
$ticket = new Ticket();
657+
$ticket->add([
658+
'name' => __FUNCTION__,
659+
'content' => __FUNCTION__,
660+
'entities_id' => $this->getTestRootEntity(true),
661+
]);
662+
$options = UserMention::getMentionOptions($ticket);
663+
$this->assertEmpty($options['users']);
664+
$this->assertFalse($options['full']);
665+
666+
$ticket_user = new Ticket_User();
667+
$ticket_user->add([
668+
'tickets_id' => $ticket->getID(),
669+
'users_id' => Session::getLoginUserID(),
670+
'type' => 2,
671+
]);
672+
673+
$options = UserMention::getMentionOptions($ticket);
674+
$this->assertCount(1, $options['users']);
675+
$this->assertFalse($options['full']);
676+
}
677+
678+
public function testFullMentions()
679+
{
680+
global $CFG_GLPI;
681+
$CFG_GLPI['use_notifications'] = 1;
682+
$CFG_GLPI['notifications_mailing'] = 1;
683+
684+
$this->login();
685+
$profiles_id = $_SESSION['glpiactiveprofile']['id'];
686+
$profile = new Profile();
687+
$profile->update([
688+
'id' => $profiles_id,
689+
'use_mentions' => UserMention::USER_MENTION_FULL,
690+
]);
691+
692+
$ticket = new Ticket();
693+
$ticket->add([
694+
'name' => __FUNCTION__,
695+
'content' => __FUNCTION__,
696+
'entities_id' => $this->getTestRootEntity(true),
697+
]);
698+
$options = UserMention::getMentionOptions($ticket);
699+
$this->assertEmpty($options['users']);
700+
$this->assertTrue($options['full']);
701+
}
613702
}

0 commit comments

Comments
 (0)