Skip to content

Commit

Permalink
Fix play button on local backend (#7688)
Browse files Browse the repository at this point in the history
If the user does not have sufficient permissions to open the project, the project no longer shows the play button. However, this does not work on the local backend because the local backend lacks permissions completely.

# Important Notes
None
  • Loading branch information
somebody1234 authored Aug 29, 2023
1 parent c558dec commit b69fa51
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
6 changes: 6 additions & 0 deletions app/ide-desktop/lib/assets/arrow_up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ export default function AssetContextMenu(props: AssetContextMenuProps) {
permission => permission.user.user_email === organization?.email
)
const managesThisAsset =
backend.type === backendModule.BackendType.local ||
self?.permission === backendModule.PermissionAction.own ||
self?.permission === backendModule.PermissionAction.admin
const isRunningProject =
asset.type === backendModule.AssetType.project &&
backendModule.DOES_PROJECT_STATE_INDICATE_VM_EXISTS[asset.projectState.type]
const canExecute =
self?.permission != null && backendModule.PERMISSION_ACTION_CAN_EXECUTE[self.permission]
backend.type === backendModule.BackendType.local ||
(self?.permission != null && backendModule.PERMISSION_ACTION_CAN_EXECUTE[self.permission])
const isOtherUserUsingProject =
backend.type !== backendModule.BackendType.local &&
backendModule.assetIsProject(asset) &&
asset.projectState.opened_by != null &&
asset.projectState.opened_by !== organization?.email
Expand Down Expand Up @@ -215,7 +218,7 @@ export default function AssetContextMenu(props: AssetContextMenuProps) {
/>
)}
<ContextMenuSeparator hidden={hidden} />
{managesThisAsset && (
{managesThisAsset && self != null && (
<MenuEntry
hidden={hidden}
action={shortcuts.KeyboardAction.share}
Expand All @@ -237,15 +240,20 @@ export default function AssetContextMenu(props: AssetContextMenuProps) {
}}
/>
)}
<MenuEntry
hidden={hidden}
disabled
action={shortcuts.KeyboardAction.label}
doAction={() => {
// No backend support yet.
}}
/>
<ContextMenuSeparator hidden={hidden} />
{backend.type !== backendModule.BackendType.local && (
<MenuEntry
hidden={hidden}
disabled
action={shortcuts.KeyboardAction.label}
doAction={() => {
// No backend support yet.
}}
/>
)}
{((managesThisAsset && self != null) ||
backend.type !== backendModule.BackendType.local) && (
<ContextMenuSeparator hidden={hidden} />
)}
<MenuEntry
hidden={hidden}
disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as React from 'react'
import * as toast from 'react-toastify'

import ArrowUpIcon from 'enso-assets/arrow_up.svg'
import PlayIcon from 'enso-assets/play.svg'
import StopIcon from 'enso-assets/stop.svg'

Expand Down Expand Up @@ -119,7 +120,9 @@ export default function ProjectIcon(props: ProjectIconProps) {
React.useState<AbortController | null>(null)
const [closeProjectAbortController, setCloseProjectAbortController] =
React.useState<AbortController | null>(null)
const isOtherUserUsingProject = item.projectState.opened_by !== organization?.email
const isOtherUserUsingProject =
backend.type !== backendModule.BackendType.local &&
item.projectState.opened_by !== organization?.email

const openProject = React.useCallback(async () => {
closeProjectAbortController?.abort()
Expand Down Expand Up @@ -355,7 +358,7 @@ export default function ProjectIcon(props: ProjectIconProps) {
)
case backendModule.ProjectState.opened:
return (
<>
<div>
<button
disabled={isOtherUserUsingProject}
{...(isOtherUserUsingProject
Expand All @@ -371,9 +374,21 @@ export default function ProjectIcon(props: ProjectIconProps) {
<div className="relative h-0">
<Spinner size={24} state={spinnerState} />
</div>
<SvgMask src={StopIcon} />
<SvgMask style={ICON_STYLE} src={StopIcon} />
</button>
</>
{!isOtherUserUsingProject && (
<button
className="w-6 h-6"
onClick={clickEvent => {
clickEvent.stopPropagation()
unsetModal()
openIde(true)
}}
>
<SvgMask style={ICON_STYLE} src={ArrowUpIcon} />
</button>
)}
</div>
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export default function ProjectNameColumn(props: ProjectNameColumnProps) {
null
const isRunning = backendModule.DOES_PROJECT_STATE_INDICATE_VM_EXISTS[asset.projectState.type]
const canExecute =
ownPermission != null &&
backendModule.PERMISSION_ACTION_CAN_EXECUTE[ownPermission.permission]
backend.type === backendModule.BackendType.local ||
(ownPermission != null &&
backendModule.PERMISSION_ACTION_CAN_EXECUTE[ownPermission.permission])
const isOtherUserUsingProject = asset.projectState.opened_by !== organization?.email

const doRename = async (newName: string) => {
Expand Down

0 comments on commit b69fa51

Please sign in to comment.