Coverage for middle_layer/propose/domain_layer/services/permissions_service.py: 100.00%
8 statements
« prev ^ index » next coverage.py v7.10.5, created at 2026-03-09 06:13 +0000
« 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.permissions_service import is_active_tac
20from common.domain_layer.entities.user import User
21from propose.domain_layer.entities.proposal import Proposal
24def get_visible_proposals(
25 user: User,
26 repo: ORMRepository,
27 args: dict,
28) -> list[Proposal]:
29 """This is a stub of a service that will manager permission checks for proposals.
31 :param user: the user to check visibility for
32 :param repo: the repository to retrieve from
33 :param args: any filtering criteria
35 :return: The redacted list of proposals (or unredacted) depending on permissions
36 """
37 # check if the user has permission to see other people's proposals:
38 # If the user requesting isn't a TTA member and they aren't an active TAC member then filter to return only the
39 # proposals that the requesting user is an author
40 if not user.roles.__contains__("tta_member") and not is_active_tac(args["solicitation_id"], user.user_id, repo):
41 args["visibility_user_id"] = user.user_id
43 return repo.proposal_repo.list_filtered(**args)