Skip to content
New issue

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

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

Already on GitHub? # to your account

[issue_tracker] Do not display inactive users in issue form #8841

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions modules/issue_tracker/php/edit.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class Edit extends \NDB_Page implements ETagCalculator
$inactive_users = [];
if ($user->hasPermission('access_all_profiles')) {
$assignee_expanded = $db->pselect(
"SELECT Real_name, UserID FROM users",
"SELECT Real_name, UserID FROM users
WHERE Active='Y' AND Pending_approval='N'",
[]
);

Expand All @@ -84,7 +85,8 @@ class Edit extends \NDB_Page implements ETagCalculator
$assignee_expanded = $db->pselect(
"SELECT DISTINCT u.Real_name, u.UserID FROM users u
LEFT JOIN user_psc_rel upr ON (upr.UserID=u.ID)
WHERE FIND_IN_SET(upr.CenterID,:CenterID) OR (upr.CenterID=:DCC)",
WHERE FIND_IN_SET(upr.CenterID,:CenterID) OR (upr.CenterID=:DCC)
AND Active='Y' AND Pending_approval='N'",
[
'CenterID' => $CenterID,
'DCC' => $DCCID,
Expand Down Expand Up @@ -113,7 +115,8 @@ class Edit extends \NDB_Page implements ETagCalculator

$otherWatchers = [];
$potential_watchers_expanded = $db->pselect(
"SELECT Real_name, UserID FROM users",
"SELECT Real_name, UserID FROM users
WHERE Active='Y' AND Pending_approval='N'",
[]
);
foreach ($potential_watchers_expanded as $w_row) {
Expand Down Expand Up @@ -189,19 +192,36 @@ class Edit extends \NDB_Page implements ETagCalculator
->withDataFrom($provisioner)
->toArray($user);

$isWatching = $db->pselectOne(
$isWatching = $db->pselectOne(
"SELECT userID, issueID FROM issues_watching
WHERE issueID=:issueID AND userID=:userID",
[
'issueID' => $issueID,
'userID' => $user->getUsername(),
]
);
$issueData['watching'] = $isWatching === null ? 'No' : 'Yes';

// Add current assignee in assignees dropdown even if not active
if (!isset($assignees[$issueData['assignee']])) {
$assignees[$issueData['assignee']] = $db->pselectOne(
"SELECT Real_name FROM users
WHERE UserID=:userID",
[
'userID' => $issueData['assignee']
]
);
}

$othersWatching = $this->getWatching($issueID);
// add current watchers to others watching, even if not active
$otherWatchers = array_merge($otherWatchers, $othersWatching);
unset($otherWatchers[$user->getUserName()]);

$issueData['watching'] = $isWatching === null ? 'No' : 'Yes';
$issueData['commentHistory'] = $this->getComments($issueID);
$issueData['attachments'] = $attachments;
$issueData['whoami'] = $user->getUsername();
$issueData['othersWatching'] = $this->getWatching($issueID);
$issueData['othersWatching'] = array_keys($othersWatching);

// We need to unescape the string here:
// React is escaping the string in the template
Expand Down Expand Up @@ -340,20 +360,23 @@ class Edit extends \NDB_Page implements ETagCalculator
*
* @param int $issueID the relevant issue
*
* @return array those who are watching
* @return array [Real_name => userID] of
* those who are watching
*/
function getWatching(int $issueID): array
{
$db = $this->loris->getDatabaseConnection();

$watching = $db->pselect(
"SELECT userID from issues_watching WHERE issueID=:issueID",
"SELECT Real_name, UserID from users
WHERE UserID IN
(SELECT UserID FROM issues_watching WHERE issueID=:issueID)",
['issueID' => $issueID]
);

$whoIsWatching = [];
foreach ($watching as $watcher) {
$whoIsWatching[] = $watcher['userID'];
$whoIsWatching[$watcher['UserID']] = $watcher['Real_name'];
}
return $whoIsWatching;
}
Expand Down Expand Up @@ -823,13 +846,13 @@ class Edit extends \NDB_Page implements ETagCalculator
/**
* Puts updated fields into the issues_comments table.
*
* @param string $comment new issue comment
* @param int $issueID the issue ID
* @param \User $user the user
* @param ?string $comment new issue comment
* @param int $issueID the issue ID
* @param \User $user the user
*
* @return void
*/
function updateComments(string $comment, int $issueID, \User $user)
function updateComments(?string $comment, int $issueID, \User $user)
{
$db = $this->loris->getDatabaseConnection();
if (isset($comment) && $comment != "null") {
Expand Down
17 changes: 17 additions & 0 deletions modules/issue_tracker/php/issue.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,21 @@ class Issue extends \NDB_Form
// the ajax/EditIssue.php hack.
return parent::handle($request);
}

/**
* Generate a breadcrumb trail for this page.
*
* @return \LORIS\BreadcrumbTrail
*/
public function getBreadcrumbs(): \LORIS\BreadcrumbTrail
{
$label = ucwords(str_replace('_', ' ', $this->name));
return new \LORIS\BreadcrumbTrail(
new \LORIS\Breadcrumb($label, "/$this->name"),
new \LORIS\Breadcrumb(
'Issue',
"/issue_tracker/issue/$this->issueID"
)
);
}
}
4 changes: 2 additions & 2 deletions modules/issue_tracker/php/issue_tracker.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Issue_Tracker extends \NDB_Menu_Filter_Form
//reporters
$reporters = [];
$reporter_expanded = $db->pselect(
"SELECT u.UserID,
"SELECT DISTINCT u.UserID,
u.Real_name
FROM issues i
INNER JOIN users u
Expand All @@ -129,7 +129,7 @@ class Issue_Tracker extends \NDB_Menu_Filter_Form
//assignees
$assignees = [];
$assignee_expanded = $db->pselect(
"SELECT u.UserID,
"SELECT DISTINCT u.UserID,
u.Real_name
FROM issues i
INNER JOIN users u
Expand Down
Loading