Tracker Scope Rules¶
Purpose: TrackerScopeRule provides fine-grained control over which organizations and projects within a tracker are synchronized and accessible. This allows users to focus on relevant data and reduce noise.
Data Model: Defined in backend/preloop/models/models/tracker_scope_rule.py
- Fields:
tracker_id: Foreign key to the Trackerscope_type: Enum -ORGANIZATIONorPROJECTrule_type: Enum -INCLUDEorEXCLUDEidentifier: String - the organization or project identifier (e.g.,"my-org"or"my-org/my-repo")
Filtering Logic: The following rules are applied consistently across all components (Preloop Sync scanner, API endpoints, cleanup scripts):
-
Organization Level (Required):
- An organization MUST have an
INCLUDErule to be processed. - Organizations can have
EXCLUDErules, but these are currently unused (organizations are opt-in viaINCLUDEonly). - If an organization is not explicitly included, all its projects are skipped.
- An organization MUST have an
-
Project Level (Within Included Organizations):
- For each included organization, projects are filtered using EITHER include rules OR exclude rules, NOT BOTH.
- Include Mode: If any
PROJECT+INCLUDErules exist for projects within an organization, ONLY those explicitly listed projects are processed. All other projects in that organization are skipped. - Exclude Mode: If only
PROJECT+EXCLUDErules exist for projects within an organization (and noPROJECT+INCLUDErules), then ALL projects EXCEPT the excluded ones are processed. - No Project Rules: If there are no project-level rules for an organization, ALL projects within that organization are processed (default behavior).
Important Constraints:
- Mutual Exclusivity: An organization MUST NOT have both
PROJECT+INCLUDEandPROJECT+EXCLUDErules. This would create ambiguous filtering logic.- ✅ Valid: Org has only
PROJECT+INCLUDErules (whitelist mode) - ✅ Valid: Org has only
PROJECT+EXCLUDErules (blacklist mode) - ✅ Valid: Org has no project-level rules (all projects included)
- ❌ Invalid: Org has both
PROJECT+INCLUDEandPROJECT+EXCLUDErules
- ✅ Valid: Org has only
Validation: The system should validate that no organization has conflicting project-level rules when scope rules are created or updated. This validation should be implemented at:
- API endpoints that create/update TrackerScopeRule records
- Database constraints (if feasible)
- UI validation when configuring tracker scopes
Implementation Locations:
- Scanner (Preloop Sync):
backend/preloop/sync/scanner/core.py- Lines 73-191- Filters organizations and projects during synchronization
- Skips organizations not in the include list
- Applies project include/exclude logic
- API (get_tracker_client):
backend/preloop/api/common.py- Lines 118-173- Validates scope when a user requests access to a specific organization/project
- Returns HTTP 403 if access is denied
- API (get_accessible_projects):
backend/preloop/api/common.py- Lines 326-422- Returns list of projects accessible to a user based on scope rules
- Used by search endpoints, project listing, and other features that query across projects
- API (Projects Endpoints):
backend/preloop/api/endpoints/projects.pyGET /projects- Lists only accessible projects based on scope rulesGET /organizations/{organization_id}/projects- Lists only accessible projects within an organization
- API (Search Endpoint):
backend/preloop/api/endpoints/search.pyGET /search- Applies scope filtering to all search results (similarity and fulltext)- Always filters by accessible projects, even when no project/org filter is specified
- Cleanup Script:
preloop/backend/preloop/scripts/cleanup_out_of_scope_issues.py- Lines 38-131- Identifies issues that violate current scope rules
- Allows administrators to clean up out-of-scope data
Example Configurations:
-
Scenario 1: Include specific organization, all projects
-
Scenario 2: Include specific organization, whitelist specific projects
-
Scenario 3: Include specific organization, blacklist specific projects
-
Scenario 4: INVALID - Mixed include/exclude