Skip to content

Commit

Permalink
fix(sanity): discard draft permission check (#8711)
Browse files Browse the repository at this point in the history
  • Loading branch information
juice49 authored Feb 20, 2025
1 parent 2693a76 commit e226ca4
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {MenuGroup} from '../../../../../ui-components/menuGroup/MenuGroup'
import {MenuItem} from '../../../../../ui-components/menuItem/MenuItem'
import {useTranslation} from '../../../../i18n/hooks/useTranslation'
import {useDocumentPairPermissions} from '../../../../store/_legacy/grants/documentPairPermissions'
import {getPublishedId, isDraftId, isPublishedId} from '../../../../util/draftUtils'
import {getPublishedId, isPublishedId} from '../../../../util/draftUtils'
import {useReleasesUpsell} from '../../../contexts/upsell/useReleasesUpsell'
import {type ReleaseDocument} from '../../../store/types'
import {useReleaseOperations} from '../../../store/useReleaseOperations'
Expand Down Expand Up @@ -60,12 +60,14 @@ export const VersionContextMenu = memo(function VersionContextMenu(props: {
const {createRelease} = useReleaseOperations()
const [hasCreatePermission, setHasCreatePermission] = useState<boolean | null>(null)

const releaseId = isVersion ? fromRelease : documentId
const [permissions, isPermissionsLoading] = useDocumentPairPermissions({
id: getPublishedId(documentId),
type,
version: releaseId,
permission: isDraftId(documentId) ? 'discardDraft' : 'discardVersion',
version: isVersion ? fromRelease : undefined,
// Note: the result of this discard permission check is disregarded for the published document
// version. Discarding is never available for the published document version. Therefore, the
// parameters provided here are not configured to handle published document versions.
permission: fromRelease === 'draft' ? 'discardDraft' : 'discardVersion',
})
const hasDiscardPermission = !isPermissionsLoading && permissions?.granted

Expand All @@ -88,7 +90,7 @@ export const VersionContextMenu = memo(function VersionContextMenu(props: {
{isVersion && (
<IntentLink
intent="release"
params={{id: releaseId}}
params={{id: fromRelease}}
rel="noopener noreferrer"
style={{textDecoration: 'none'}}
disabled={disabled}
Expand Down

0 comments on commit e226ca4

Please sign in to comment.