-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat(search): Add team: filter for issues by project ownership #106501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
5aba036 to
81d8ffc
Compare
|
bugbot review |
|
@sentry review |
|
Is there anything else I have to do in the PR process here? (I can't find any docs). Or is this just waiting for a maintainer to take a look? |
you're all good, i'll take a look. |
|
this likely would need to take into account the org open membership settings |
|
Thanks for the feedback. I noticed the existing A few questions:
|
f8d2c23 to
782cf90
Compare
src/sentry/issues/issue_search.py
Outdated
| def convert_team_value( | ||
| value: Iterable[str], | ||
| projects: Sequence[Project], | ||
| user: User, | ||
| environments: Sequence[Environment] | None, | ||
| ) -> list[RpcUser | Team | None]: | ||
| """Convert team slug(s) to Team objects for filtering issues by project ownership. | ||
|
|
||
| Only returns teams that are associated with at least one of the searched projects, | ||
| ensuring users can only filter by teams they have visibility to. | ||
| """ | ||
| if not projects: | ||
| return [] | ||
| teams: list[RpcUser | Team | None] = [] | ||
| for team_identifier in value: | ||
| team_slug = team_identifier.lstrip("#") | ||
| team = Team.objects.filter( | ||
| slug__iexact=team_slug, | ||
| organization_id=projects[0].organization_id, | ||
| projectteam__project__in=projects, | ||
| ).first() | ||
| if not team: | ||
| raise InvalidSearchQuery(f"Invalid team '{team_identifier}'") | ||
| teams.append(team) | ||
| return teams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can probably bulk query and i think that IDOR warning isn't really fixed with project[0].organization_id any more than using in=projects so lets keep it just filtering by projects.
| def convert_team_value( | |
| value: Iterable[str], | |
| projects: Sequence[Project], | |
| user: User, | |
| environments: Sequence[Environment] | None, | |
| ) -> list[RpcUser | Team | None]: | |
| """Convert team slug(s) to Team objects for filtering issues by project ownership. | |
| Only returns teams that are associated with at least one of the searched projects, | |
| ensuring users can only filter by teams they have visibility to. | |
| """ | |
| if not projects: | |
| return [] | |
| teams: list[RpcUser | Team | None] = [] | |
| for team_identifier in value: | |
| team_slug = team_identifier.lstrip("#") | |
| team = Team.objects.filter( | |
| slug__iexact=team_slug, | |
| organization_id=projects[0].organization_id, | |
| projectteam__project__in=projects, | |
| ).first() | |
| if not team: | |
| raise InvalidSearchQuery(f"Invalid team '{team_identifier}'") | |
| teams.append(team) | |
| return teams | |
| def convert_team_value( | |
| value: Iterable[str], | |
| projects: Sequence[Project], | |
| user: User, | |
| environments: Sequence[Environment] | None, | |
| ) -> list[RpcUser | Team | None]: | |
| if not projects: | |
| return [] | |
| slugs = [v[1:] if v.startswith("#") else v for v in value] | |
| if not slugs: | |
| return [] | |
| teams = Team.objects.filter( | |
| slug__in=slugs, | |
| projectteam__project__in=projects, | |
| ).distinct() | |
| teams_by_slug = {team.slug: team for team in teams} | |
| result: list[RpcUser | Team | None] = [] | |
| for slug in slugs: | |
| team = teams_by_slug.get(slug) | |
| if not team: | |
| raise InvalidSearchQuery(f"Invalid team '{slug}'") | |
| result.append(team) | |
| return result |
|
@mishamo never mind on the open membership we should already be filtering down projects to the ones available to user user similar to assigned to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Adds a new `team:` search filter that allows filtering issues by the team that owns the project. This enables searching for issues like `team:platform` to find all issues in projects owned by the platform team. Implementation: - Added `team` to `key_mappings` in issue search config - Added `convert_team_value` to convert team slugs to Team objects - Added `team_filter` QCallbackCondition in snuba backend - Added `team` to NO_CONVERSION_FIELDS to skip Snuba conversion - Uses case-insensitive slug matching consistent with existing patterns Closes getsentry#45367 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
7d7accf to
6c9f1c4
Compare
Summary
Adds a new
team:search filter that allows filtering issues by the team that owns the project. This addresses #45367.Usage:
team:data-engineering- Issues from projects owned by data-engineeringteam:#data-engineering- Same (# prefix supported for consistency with other team references)!team:data-engineering- Issues NOT from data-engineering's projectsteam:[team1,team2]- Issues from projects owned by either teamChanges
src/sentry/issues/issue_search.py:teamkey mappingconvert_team_value()converter that validates teams throughprojectteamrelationship (prevents IDOR by ensuring users can only filter by teams associated with their searched projects)src/sentry/search/snuba/backend.py:team_filter()functionteamcondition to queryset buildertests/snuba/search/test_backend.py:test_team_filter- Basic filtering with/without # prefixtest_team_filter_negation-!team:exclusiontest_team_filter_invalid_team- Error handling for non-existent teamstest_team_filter_multiple_teams-team:[t1,t2]syntaxtest_team_filter_team_not_in_searched_projects- Security test for IDOR preventionTest plan
#prefix works for consistency with other team references!team:) excludes issues from team's projectsInvalidSearchQuery🤖 Generated with Claude Code