Coverage for middle_layer/review/application_layer/services/notify_tta_members_if_insufficient_reviewers.py: 95.00%

20 statements  

« prev     ^ index     » next       coverage.py v7.10.5, created at 2026-04-13 06:13 +0000

1# Copyright 2024 Associated Universities, Inc. 

2# 

3# This file is part of Telescope Time Allocation Tools (TTAT). 

4# 

5# TTAT is free software: you can redistribute it and/or modify 

6# it under the terms of the GNU General Public License as published by 

7# the Free Software Foundation, either version 3 of the License, or 

8# any later version. 

9# 

10# TTAT is distributed in the hope that it will be useful, 

11# but WITHOUT ANY WARRANTY; without even the implied warranty of 

12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

13# GNU General Public License for more details. 

14# 

15# You should have received a copy of the GNU General Public License 

16# along with TTAT. If not, see <https://www.gnu.org/licenses/>. 

17 

18from common.application_layer.orm_repositories.orm_repository import ORMRepository 

19from common.application_layer.services.notification_sender_service import send_basic_notification 

20from common.utils.gitlab_secret_loader import NOTIFICATION_MAILING_LIST 

21from review.domain_layer.entities.science_review_panel import ScienceReviewPanel 

22 

23 

24def notify_tta_members_if_insufficient_reviewers(srp: ScienceReviewPanel, repo: ORMRepository) -> bool: 

25 """Notify TTA Members if any Proposal associated with a given ScienceReviewPanel lacks enough 

26 non-Conflicted ScienceReviewers 

27 

28 :param srp: ScienceReviewPanel to examine 

29 :param repo: Repository for database querying 

30 :return: Whether or not a notification was sent to TTA members 

31 """ 

32 context = repo.context_repo.by_id(srp.solicitation_id) 

33 if not context or context.do_notify: 

34 min_proposals = [] 

35 for prop in srp.proposals: 

36 cds = repo.conflict_declaration_repo.list_by_proposal_with_state_unknown_or_available(prop.proposal_id) 

37 if len(cds) < srp.minimum_science_reviewers_per_proposal: 

38 min_proposals.append(prop) 

39 

40 if not len(min_proposals): # No proposals with insufficent reviewers 

41 return False # No notification sent 

42 

43 message = ( 

44 f"{srp.solicitation.solicitation_name} ({srp.science_review_panel_name}) - insufficient reviewers found " 

45 f"for the following proposals:\n\n" 

46 ) 

47 for prop in min_proposals: 

48 message += f" {prop.proposal_code}\n" 

49 

50 send_basic_notification( 

51 message, 

52 f"{srp.solicitation.solicitation_name} ({srp.science_review_panel_name}) - insufficient reviewers", 

53 NOTIFICATION_MAILING_LIST, 

54 ) 

55 return True 

56 

57 return False