Coverage for middle_layer/review/application_layer/services/notify_tta_members_srp_isrs_finalized.py: 100.00%

16 statements  

« prev     ^ index     » next       coverage.py v7.10.5, created at 2026-03-09 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_srp_isrs_finalized(srp: ScienceReviewPanel, repo: ORMRepository) -> bool: 

25 """Notify TTA Members if a given ScienceReviewPanel's non-None, non-Closed IndividualScienceReviews are Finalized 

26 

27 :param srp: ScienceReviewPanel to examine 

28 :param repo: Repository for database querying 

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

30 """ 

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

32 if not context or context.do_notify: 

33 isrs = repo.individual_science_review_repo.list_by_srp_id(srp.science_review_panel_id) 

34 for isr in isrs: 

35 if isr.review_state != "Finalized" and isr.review_type != "None" and isr.review_type != "Closed": 

36 return False 

37 

38 sci_cats = [] 

39 for sci_cat in srp.science_categories: 

40 sci_cats.append(sci_cat.short_name) 

41 

42 send_basic_notification( 

43 f"{srp.science_review_panel_name} ({', '.join(sci_cats)})" 

44 f" - all individual science reviews have been finalized.", 

45 f"{srp.science_review_panel_name} ({', '.join(sci_cats)}) - individual science reviews " f"finalized", 

46 NOTIFICATION_MAILING_LIST, 

47 ) 

48 

49 return True