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

[BUG] issue 2196 continued :: User ID is not a good email address #2442

Closed
as1029 opened this issue Mar 26, 2024 · 1 comment
Closed

[BUG] issue 2196 continued :: User ID is not a good email address #2442

as1029 opened this issue Mar 26, 2024 · 1 comment

Comments

@as1029
Copy link

as1029 commented Mar 26, 2024

Hi Marcel,

Thanks for all your work on this project!

I just checked to see on the email issue (wanted to do a
code update - cos have more team members and it is
becoming a pain to forward email).

The mailer is still getting an ID instead of an email
address.

Please can you check and fix?
I have looked at the below code in version 3.05 3.06 3.07
and 3.1.0-beta

I think the issue is in this code (full file below for
your convenience issues here highlighted in bold) :

$taggedUser = $links->item($i)->getAttribute('data-tagged-
user-id');

is a numeric value not an email address?
$mailer->sendMail(array($taggedUser), $authorName);
first parameter sendMail should be an array of email
addresses - not an array of user ID's

Hope that helps

kind regards

Andy

app/Domain/Notifications/Services/Notifications.php

<?php

namespace Leantime\Domain\Notifications\Services {

use DOMDocument;
use
Illuminate\Contracts\Container\BindingResolutionException;
use Leantime\Core\Db as DbCore;
use Leantime\Core\Language as LanguageCore;
use Leantime\Core\Mailer as MailerCore;
use
Leantime\Domain\Notifications\Repositories\Notifications
as NotificationRepository;
use Leantime\Domain\Users\Repositories\Users as
UserRepository;

/**
*
*/
class Notifications
{
private DbCore $db;
private NotificationRepository $notificationsRepo;
private UserRepository $userRepository;
private LanguageCore $language;

/**
* __construct - get database connection
*
* [@access](https://github.com/access) public
*/
public function __construct(
DbCore $db,
NotificationRepository $notificationsRepo,
UserRepository $userRepository,
LanguageCore $language
) {
$this->db = $db;
$this->notificationsRepo = $notificationsRepo;
$this->userRepository = $userRepository;
$this->language = $language;
}

/**
* [@param](https://github.com/param) $userId
* [@param](https://github.com/param) $showNewOnly
* [@param](https://github.com/param) $limitStart
* [@param](https://github.com/param) $limitEnd
* [@param](https://github.com/param) $filterOptions
* [@return](https://github.com/return) array|false
*/
/**
* [@param](https://github.com/param) $userId
* [@param](https://github.com/param) int $showNewOnly
* [@param](https://github.com/param) int $limitStart
* [@param](https://github.com/param) int $limitEnd
* [@param](https://github.com/param) array $filterOptions
* [@return](https://github.com/return) array|false
*/
public function getAllNotifications($userId, int
$showNewOnly = 0, int $limitStart = 0, int $limitEnd =
100, array $filterOptions = array()): false|array
{

return $this->notificationsRepo-
getAllNotifications($userId, $showNewOnly, $limitStart,
$limitEnd, $filterOptions);
}


/**
* [@param](https://github.com/param) array $notifications
* [@return](https://github.com/return) bool|null
*/
public function addNotifications(array $notifications):
?bool
{

return $this->notificationsRepo-
addNotifications($notifications);
}

/**
* [@param](https://github.com/param) $id
* [@param](https://github.com/param) $userId
* [@return](https://github.com/return) bool
*/
/**
* [@param](https://github.com/param) $id
* [@param](https://github.com/param) $userId
* [@return](https://github.com/return) bool
*/
public function markNotificationRead($id, $userId): bool
{

if ($id == "all") {
return $this->notificationsRepo-
markAllNotificationRead($userId);
} else {
return $this->notificationsRepo-
markNotificationRead($id);
}
}

/**
* [@param](https://github.com/param) string $content
* [@param](https://github.com/param) string $module
* [@param](https://github.com/param) int $moduleId
* [@param](https://github.com/param) int $authorId
* [@param](https://github.com/param) string $url
* [@return](https://github.com/return) void
* [@throws](https://github.com/throws) BindingResolutionException
*/
public function processMentions(string $content, string
$module, int $moduleId, int $authorId, string $url): void
{

$dom = new DOMDocument();

//Content may not be well formatted. Suppress warnings.
@$dom->loadHTML($content);
$links = $dom->getElementsByTagName("a");

$author = $this->userRepository->getUser($authorId);
$authorName = $author['firstname'] ?? $this->language-
__('label.team_mate');
for ($i = 0; $i < $links->count(); $i++) {
$taggedUser = $links->item($i)->getAttribute('data-tagged-
user-id');

if ($taggedUser !== '' && is_numeric($taggedUser)) {
//Check if user was mentioned before
$userMentions = $this->getAllNotifications(
$taggedUser,
false,
0,
10,
array("type" => "mention", "module" => $module, "moduleId"
=> $moduleId)
);

if ($userMentions === false || (is_array($userMentions) &&
count($userMentions) == 0)) {
$notification = array(
"userId" => $taggedUser,
"read" => '0',
"type" => 'mention',
"module" => $module,
"moduleId" => $moduleId,
"message" => sprintf($this->language-
__('text.x_mentioned_you'), $authorName),
"datetime" => date("Y-m-d H:i:s"),
"url" => $url,
"authorId" => $authorId,
);

$this->addNotifications(array($notification));

//send email
$mailer = app()->make(MailerCore::class);
$mailer->setContext('notify_project_users');

$subject = sprintf($this->language-
__('text.x_mentioned_you'), $authorName);
$mailer->setSubject($subject);

$emailMessage = $subject;
$emailMessage .= sprintf($this->language-
__('text.click_here'), $url);
$mailer->setHtml($emailMessage);
**$mailer->sendMail(array($taggedUser), $authorName);**
}
}
}
}
}

}
@marcelfolaron
Copy link
Contributor

This is fixed as of 3.1.2.

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

No branches or pull requests

2 participants