Skip to content
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

Forbid to save file if it's not on latest revision #3124

Merged
merged 7 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions catalog/app/components/FileEditor/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,24 @@ export const isSupportedFileType: (path: string) => boolean = R.pipe(
export function useWriteData({
bucket,
key,
version,
}: S3HandleBase): (value: string) => Promise<Model.S3File> {
const s3 = AWS.S3.use()
return React.useCallback(
async (value) => {
const { VersionId: version } = await s3
const { VersionId: latestVersion } = await s3
.headObject({ Bucket: bucket, Key: key })
.promise()
if (latestVersion !== version) throw new Error('Revision is outdated')

const { VersionId } = await s3
.putObject({ Bucket: bucket, Key: key, Body: value })
.promise()
const { ContentLength: size } = await s3
.headObject({ Bucket: bucket, Key: key, VersionId: version })
.headObject({ Bucket: bucket, Key: key, VersionId })
.promise()
return { bucket, key, size, version }
return { bucket, key, size, version: VersionId }
},
[bucket, key, s3],
[bucket, key, s3, version],
)
}
25 changes: 15 additions & 10 deletions catalog/app/containers/Bucket/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,20 @@ export default function File({
}),
})

const downloadable =
!noDownload &&
versionExistsData.case({
_: () => false,
Ok: requests.ObjectExistence.case({
_: () => false,
Exists: ({ deleted, archived }) => !deleted && !archived,
const { downloadable, hash } = versionExistsData.case({
_: () => ({
downloadable: false,
}),
Ok: requests.ObjectExistence.case({
_: () => ({
downloadable: false,
}),
})
Exists: ({ deleted, archived, version: versionHash }) => ({
downloadable: !noDownload && !deleted && !archived,
hash: versionHash,
}),
}),
})

const viewModes = useViewModes(path, mode)

Expand All @@ -402,8 +407,8 @@ export default function File({
)

const handle = React.useMemo(
() => ({ bucket, key: path, version }),
[bucket, path, version],
() => ({ bucket, key: path, version: hash }),
[bucket, path, hash],
)

const editorState = FileEditor.useState(handle)
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* [Changed] Fixed config and docs mistyping: `ui.athena.defaultWorkflow` should be `ui.athena.defaultWorkgroup` ([#3067](https://github.com/quiltdata/quilt/pull/3067))
* [Changed] Use dedicated columns field instead of first row, fix duplicated first row in table results ([#3101](https://github.com/quiltdata/quilt/pull/3101))
* [Changed] Allow pushing empty packages, suggest creating a stub `README.md` file when trying to push an empty package ([#3114](https://github.com/quiltdata/quilt/pull/3114))
* [Changed] Allow to save only latest revisions of files ([#3124](https://github.com/quiltdata/quilt/pull/3124))

## Docs
* [Added] Fix four-deep headers so auto-link generation works ([#3100](https://github.com/quiltdata/quilt/pull/3100))
Expand Down