def check_jira_all_projects_have_permissions()

in jbi/jira/service.py [0:0]


    def check_jira_all_projects_have_permissions(self, actions):
        """Fetches and validates that required permissions exist for the configured projects"""

        # Do not bother executing the rest of checks if connection fails.
        if messages := self.check_jira_connection():
            return messages

        try:
            projects = self.client.permitted_projects(JIRA_REQUIRED_PERMISSIONS)
        except requests.HTTPError:
            return [
                checks.Error(
                    "Error fetching permitted Jira projects", id="jira.permitted.error"
                )
            ]

        projects_with_required_perms = {project["key"] for project in projects}
        missing_perms = (
            actions.configured_jira_projects_keys - projects_with_required_perms
        )
        if missing_perms:
            missing = ", ".join(missing_perms)
            return [
                checks.Warning(
                    f"Missing permissions for projects {missing}",
                    id="jira.permitted.missing",
                )
            ]

        return []