Skip to content

Commit

Permalink
fix(roles): team admin is allowed to add a project to other teams (#8…
Browse files Browse the repository at this point in the history
…2453)

Since #49229, Team Admins are
allowed to share the project they have admin access, with other teams.
The original PR implemented this feature from the projectTeams side.
However, it should also be possible to do the same action (team+project
association) from teamProjects view, as they both use the same backend
endpoint.

Also, removing the yellow permission alert as it no longer applies:
> These settings can only be edited by users with the organization-level
owner, manager, or team-level admin roles.

Note, this is only a Frontend fix, there is no security impact.

## Example
`go` project belongs to both `#go-admin` and `#go-contributor` teams.
`go2` project belongs to `#go2` team.
`go3` project belongs to `#go3` team.

A user has Team Admin role in `#go-admin` and `#go2`, but Contributor
role in `#go-contributor` and `#go3`. In this setup, a user should be
able to share the `go2` project from the `#go-contributor` team view
(but not `#go3`).

## Before this PR

![image](https://github.com/user-attachments/assets/9c6193c2-63dd-4505-b3b8-bd949d30a46c)

## After

![image](https://github.com/user-attachments/assets/c2a0fe4a-0bd4-4806-941a-9e5a19e530b7)


![image](https://github.com/user-attachments/assets/9ef501cb-55a5-4cc0-885a-d8fcf69869a1)
  • Loading branch information
oioki authored Jan 7, 2025
1 parent ef6cf98 commit ca98854
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions static/app/views/settings/organizationTeams/teamProjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import useApi from 'sentry/utils/useApi';
import useOrganization from 'sentry/utils/useOrganization';
import ProjectListItem from 'sentry/views/settings/components/settingsProjectItem';
import TextBlock from 'sentry/views/settings/components/text/textBlock';
import PermissionAlert from 'sentry/views/settings/project/permissionAlert';

interface TeamProjectsProps extends RouteComponentProps<{teamId: string}, {}> {
team: Team;
Expand Down Expand Up @@ -116,42 +115,31 @@ function TeamProjects({team, location, params}: TeamProjectsProps) {
'If you have Team Admin permissions for other projects, you can associate them with this team.'
)}
</TextBlock>
<PermissionAlert access={['team:write']} team={team} />
<Panel>
<PanelHeader hasButtons>
<div>{t('Projects')}</div>
<div style={{textTransform: 'none', fontWeight: 'normal'}}>
{!hasWriteAccess ? (
<DropdownButton
disabled
title={t('You do not have enough permission to associate a project.')}
size="xs"
>
{t('Add Project')}
</DropdownButton>
) : (
<DropdownAutoComplete
items={otherProjects}
minWidth={300}
onChange={evt => setQuery(evt.target.value)}
onSelect={selection => {
const project = unlinkedProjects.find(p => p.id === selection.value);
if (project) {
handleLinkProject(project, 'add');
}
}}
onClose={() => setQuery('')}
busy={loadingUnlinkedProjects}
emptyMessage={t('You are not an admin for any other projects')}
alignMenu="right"
>
{({isOpen}) => (
<DropdownButton isOpen={isOpen} size="xs">
{t('Add Project')}
</DropdownButton>
)}
</DropdownAutoComplete>
)}
<DropdownAutoComplete
items={otherProjects}
minWidth={300}
onChange={evt => setQuery(evt.target.value)}
onSelect={selection => {
const project = unlinkedProjects.find(p => p.id === selection.value);
if (project) {
handleLinkProject(project, 'add');
}
}}
onClose={() => setQuery('')}
busy={loadingUnlinkedProjects}
emptyMessage={t('You are not an admin for any other projects')}
alignMenu="right"
>
{({isOpen}) => (
<DropdownButton isOpen={isOpen} size="xs">
{t('Add Project')}
</DropdownButton>
)}
</DropdownAutoComplete>
</div>
</PanelHeader>

Expand Down

0 comments on commit ca98854

Please sign in to comment.