File tree 5 files changed +45
-2
lines changed
site/src/pages/WorkspacePage
5 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -55,12 +55,13 @@ export interface WorkspaceProps {
55
55
workspaceErrors : WorkspaceErrors ;
56
56
buildInfo ?: TypesGen . BuildInfoResponse ;
57
57
sshPrefix ?: string ;
58
- template ? : TypesGen . Template ;
58
+ template : TypesGen . Template ;
59
59
canRetryDebugMode : boolean ;
60
60
handleBuildRetry : ( ) => void ;
61
61
handleBuildRetryDebug : ( ) => void ;
62
62
buildLogs ?: React . ReactNode ;
63
63
canAutostart : boolean ;
64
+ isOwner : boolean ;
64
65
}
65
66
66
67
/**
@@ -93,6 +94,7 @@ export const Workspace: FC<WorkspaceProps> = ({
93
94
handleBuildRetryDebug,
94
95
buildLogs,
95
96
canAutostart,
97
+ isOwner,
96
98
} ) => {
97
99
const navigate = useNavigate ( ) ;
98
100
const { saveLocal, getLocal } = useLocalStorage ( ) ;
@@ -199,6 +201,7 @@ export const Workspace: FC<WorkspaceProps> = ({
199
201
isUpdating = { isUpdating }
200
202
isRestarting = { isRestarting }
201
203
canUpdateWorkspace = { canUpdateWorkspace }
204
+ isOwner = { isOwner }
202
205
/>
203
206
204
207
< div
Original file line number Diff line number Diff line change @@ -107,3 +107,29 @@ export const AlwaysUpdateStopped: Story = {
107
107
canChangeVersions : true ,
108
108
} ,
109
109
} ;
110
+
111
+ export const CancelShownForOwner : Story = {
112
+ args : {
113
+ workspace : {
114
+ ...Mocks . MockStartingWorkspace ,
115
+ template_allow_user_cancel_workspace_jobs : false ,
116
+ } ,
117
+ isOwner : true ,
118
+ } ,
119
+ } ;
120
+ export const CancelShownForUser : Story = {
121
+ args : {
122
+ workspace : Mocks . MockStartingWorkspace ,
123
+ isOwner : false ,
124
+ } ,
125
+ } ;
126
+
127
+ export const CancelHiddenForUser : Story = {
128
+ args : {
129
+ workspace : {
130
+ ...Mocks . MockStartingWorkspace ,
131
+ template_allow_user_cancel_workspace_jobs : false ,
132
+ } ,
133
+ isOwner : false ,
134
+ } ,
135
+ } ;
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ export interface WorkspaceActionsProps {
46
46
children ?: ReactNode ;
47
47
canChangeVersions : boolean ;
48
48
canRetryDebug : boolean ;
49
+ isOwner : boolean ;
49
50
}
50
51
51
52
export const WorkspaceActions : FC < WorkspaceActionsProps > = ( {
@@ -65,6 +66,7 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
65
66
isRestarting,
66
67
canChangeVersions,
67
68
canRetryDebug,
69
+ isOwner,
68
70
} ) => {
69
71
const { duplicateWorkspace, isDuplicationReady } =
70
72
useWorkspaceDuplication ( workspace ) ;
@@ -73,6 +75,9 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
73
75
workspace ,
74
76
canRetryDebug ,
75
77
) ;
78
+ const showCancel =
79
+ canCancel &&
80
+ ( workspace . template_allow_user_cancel_workspace_jobs || isOwner ) ;
76
81
77
82
const mustUpdate =
78
83
workspaceUpdatePolicy ( workspace , canChangeVersions ) === "always" &&
@@ -146,7 +151,7 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
146
151
< Fragment key = { action } > { buttonMapping [ action ] } </ Fragment >
147
152
) ) }
148
153
149
- { canCancel && < CancelButton handleAction = { handleCancel } /> }
154
+ { showCancel && < CancelButton handleAction = { handleCancel } /> }
150
155
151
156
< MoreMenu >
152
157
< MoreMenuTrigger >
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ import { WorkspacePermissions } from "./permissions";
36
36
import { workspaceResolveAutostart } from "api/queries/workspaceQuota" ;
37
37
import { WorkspaceDeleteDialog } from "./WorkspaceDeleteDialog" ;
38
38
import dayjs from "dayjs" ;
39
+ import { useMe } from "hooks" ;
39
40
40
41
interface WorkspaceReadyPageProps {
41
42
template : TypesGen . Template ;
@@ -56,6 +57,10 @@ export const WorkspaceReadyPage = ({
56
57
throw Error ( "Workspace is undefined" ) ;
57
58
}
58
59
60
+ // Owner
61
+ const me = useMe ( ) ;
62
+ const isOwner = me . roles . find ( ( role ) => role . name === "owner" ) !== undefined ;
63
+
59
64
// Debug mode
60
65
const { data : deploymentValues } = useQuery ( {
61
66
...deploymentConfig ( ) ,
@@ -247,6 +252,7 @@ export const WorkspaceReadyPage = ({
247
252
)
248
253
}
249
254
canAutostart = { canAutostart }
255
+ isOwner = { isOwner }
250
256
/>
251
257
252
258
< WorkspaceDeleteDialog
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ export interface WorkspaceProps {
56
56
canRetryDebugMode : boolean ;
57
57
handleBuildRetry : ( ) => void ;
58
58
handleBuildRetryDebug : ( ) => void ;
59
+ isOwner : boolean ;
59
60
}
60
61
61
62
export const WorkspaceTopbar = ( props : WorkspaceProps ) => {
@@ -77,6 +78,7 @@ export const WorkspaceTopbar = (props: WorkspaceProps) => {
77
78
canRetryDebugMode,
78
79
handleBuildRetry,
79
80
handleBuildRetryDebug,
81
+ isOwner,
80
82
} = props ;
81
83
const theme = useTheme ( ) ;
82
84
@@ -263,6 +265,7 @@ export const WorkspaceTopbar = (props: WorkspaceProps) => {
263
265
canChangeVersions = { canChangeVersions }
264
266
isUpdating = { isUpdating }
265
267
isRestarting = { isRestarting }
268
+ isOwner = { isOwner }
266
269
/>
267
270
</ div >
268
271
</ Topbar >
You can’t perform that action at this time.
0 commit comments