@@ -3,6 +3,7 @@ import styled from '@emotion/styled';
3
3
import debounce from 'lodash/debounce' ;
4
4
import isEqual from 'lodash/isEqual' ;
5
5
6
+ import { hasEveryAccess } from 'sentry/components/acl/access' ;
6
7
import AvatarList from 'sentry/components/avatar/avatarList' ;
7
8
import TeamAvatar from 'sentry/components/avatar/teamAvatar' ;
8
9
import Badge from 'sentry/components/badge/badge' ;
@@ -20,6 +21,7 @@ import {space} from 'sentry/styles/space';
20
21
import type { Team } from 'sentry/types/organization' ;
21
22
import type { User } from 'sentry/types/user' ;
22
23
import { defined } from 'sentry/utils' ;
24
+ import useOrganization from 'sentry/utils/useOrganization' ;
23
25
import { useTeams } from 'sentry/utils/useTeams' ;
24
26
import { useTeamsById } from 'sentry/utils/useTeamsById' ;
25
27
import { useUser } from 'sentry/utils/useUser' ;
@@ -37,7 +39,11 @@ interface EditAccessSelectorProps {
37
39
function EditAccessSelector ( { dashboard, onChangeEditAccess} : EditAccessSelectorProps ) {
38
40
const currentUser : User = useUser ( ) ;
39
41
const dashboardCreator : User | undefined = dashboard . createdBy ;
40
- const isCurrentUserDashboardOwner = dashboardCreator ?. id === currentUser . id ;
42
+
43
+ const organization = useOrganization ( ) ;
44
+ const userCanEditDashboardPermissions =
45
+ dashboardCreator ?. id === currentUser . id ||
46
+ hasEveryAccess ( [ 'org:write' ] , { organization} ) ;
41
47
42
48
// Retrieves teams from the team store, which may contain only a subset of all teams
43
49
const { teams : teamsToRender } = useTeamsById ( ) ;
@@ -143,7 +149,7 @@ function EditAccessSelector({dashboard, onChangeEditAccess}: EditAccessSelectorP
143
149
maxVisibleAvatars = { 1 }
144
150
avatarSize = { 25 }
145
151
renderUsersFirst
146
- tooltipOptions = { { disabled : ! isCurrentUserDashboardOwner } }
152
+ tooltipOptions = { { disabled : ! userCanEditDashboardPermissions } }
147
153
/>
148
154
) : (
149
155
// Case where we display 1 Creator Avatar + a Badge with no. of teams selected
@@ -153,7 +159,7 @@ function EditAccessSelector({dashboard, onChangeEditAccess}: EditAccessSelectorP
153
159
users = { Array ( selectedOptions . length ) . fill ( dashboardCreator ) }
154
160
maxVisibleAvatars = { 1 }
155
161
avatarSize = { 25 }
156
- tooltipOptions = { { disabled : ! isCurrentUserDashboardOwner } }
162
+ tooltipOptions = { { disabled : ! userCanEditDashboardPermissions } }
157
163
/>
158
164
) ;
159
165
@@ -165,16 +171,16 @@ function EditAccessSelector({dashboard, onChangeEditAccess}: EditAccessSelectorP
165
171
{
166
172
value : '_allUsers' ,
167
173
label : t ( 'All users' ) ,
168
- disabled : ! isCurrentUserDashboardOwner ,
174
+ disabled : ! userCanEditDashboardPermissions ,
169
175
} ,
170
176
] ,
171
177
} ,
172
178
{
173
179
value : '_teams' ,
174
180
label : t ( 'Teams' ) ,
175
181
options : teamsToRender . map ( makeTeamOption ) ,
176
- showToggleAllButton : isCurrentUserDashboardOwner ,
177
- disabled : ! isCurrentUserDashboardOwner ,
182
+ showToggleAllButton : userCanEditDashboardPermissions ,
183
+ disabled : ! userCanEditDashboardPermissions ,
178
184
} ,
179
185
] ;
180
186
@@ -189,7 +195,7 @@ function EditAccessSelector({dashboard, onChangeEditAccess}: EditAccessSelectorP
189
195
setSelectedOptions ( getSelectedOptions ( ) ) ;
190
196
}
191
197
} }
192
- disabled = { ! isCurrentUserDashboardOwner }
198
+ disabled = { ! userCanEditDashboardPermissions }
193
199
>
194
200
{ t ( 'Cancel' ) }
195
201
</ Button >
@@ -209,7 +215,7 @@ function EditAccessSelector({dashboard, onChangeEditAccess}: EditAccessSelectorP
209
215
} }
210
216
priority = "primary"
211
217
disabled = {
212
- ! isCurrentUserDashboardOwner ||
218
+ ! userCanEditDashboardPermissions ||
213
219
isEqual ( getDashboardPermissions ( ) , dashboard . permissions )
214
220
}
215
221
>
@@ -254,7 +260,7 @@ function EditAccessSelector({dashboard, onChangeEditAccess}: EditAccessSelectorP
254
260
return (
255
261
< Tooltip
256
262
title = { t ( 'Only the creator of the dashboard can edit permissions' ) }
257
- disabled = { isCurrentUserDashboardOwner || isMenuOpen }
263
+ disabled = { userCanEditDashboardPermissions || isMenuOpen }
258
264
>
259
265
{ dropdownMenu }
260
266
</ Tooltip >
0 commit comments