Coverage for middle_layer/common/application_layer/services/permissions_service.py: 72.41%

29 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 allocate.domain_layer.entities.tac_member import TACMember 

19from common.application_layer.orm_repositories.orm_repository import ORMRepository 

20from solicit.domain_layer.entities.solicitation import Solicitation 

21 

22 

23def is_active_tac(solicitation_id: int, user_id: int, repo: ORMRepository) -> bool: 

24 

25 # Currently, only the process, Panel Proposal Review (PPR), has the concept of a TAC and TAC member 

26 # If solicitation is PPR, then we need to check if the user is a TAC member 

27 # Otherwise, return False 

28 

29 sol: Solicitation = repo.solicitation_repo.by_id(solicitation_id) 

30 if sol.proposal_process.proposal_process_name != "Panel Proposal Review": 

31 return False 

32 

33 tac_members: list[TACMember] = repo.tac_member_repo.list_by_solicitation_id(solicitation_id) 

34 

35 active_member_ids = [member.user_id for member in tac_members if member.is_active] 

36 if user_id in active_member_ids: 

37 return True 

38 

39 return False 

40 

41 

42def is_active_tac_chair(solicitation_id: int, user_id: int, repo: ORMRepository) -> bool: 

43 

44 # Currently, only the process, Panel Proposal Review (PPR), has the concept of a TAC and TAC member 

45 # If solicitation is PPR, then we need to check if the user is a TAC chair 

46 # Otherwise, return False 

47 

48 sol: Solicitation = repo.solicitation_repo.by_id(solicitation_id) 

49 if sol.proposal_process.proposal_process_name != "Panel Proposal Review": 

50 return False 

51 

52 tac_members: list[TACMember] = repo.tac_member_repo.list_by_solicitation_id(solicitation_id) 

53 

54 active_chair_ids = [member.user_id for member in tac_members if (member.is_active and member.is_chair)] 

55 if user_id in active_chair_ids: 

56 return True 

57 

58 return False 

59 

60 

61def is_author_of_completed_proposal(user_id: int, proposal_dispositions: list, repo=None) -> bool: 

62 """ 

63 Check if a user is an author of a completed proposal in a list of proposal dispositions. 

64 

65 :param user_id: The user ID to check 

66 :param proposal_dispositions: List of ProposalDisposition objects to check 

67 :param repo: Repository instance (optional, not used in current implementation) 

68 :return: True if the user is an author of any completed proposal in the list, False otherwise 

69 """ 

70 for pd in proposal_dispositions: 

71 proposal = pd.proposal 

72 if proposal and proposal.state == "Completed": 

73 for author in proposal.authors: 

74 if author.user_id == user_id: 

75 return True 

76 return False