Skip to content

Commit

Permalink
fix(Viewer): Now use the folder as a reference when sharing
Browse files Browse the repository at this point in the history
If a doc is not shared but inside a shared folder, the sharing must
relies on the folder and not the file
  • Loading branch information
JF-Cozy committed Jan 20, 2025
1 parent fd145fa commit dee9d4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 7 additions & 4 deletions packages/cozy-viewer/src/Panel/Sharing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ const Sharing = ({ file, t }) => {
getDocumentPermissions,
getSharingLink,
allLoaded,
hasSharedParent,
getRecipients
} = useSharingContext()

const recipients = getRecipients(file._id)
const permissions = getDocumentPermissions(file._id)
const link = getSharingLink(file._id)
const shareFileRefId = hasSharedParent(file.path) ? file.dir_id : file._id
const recipients = getRecipients(shareFileRefId)
const permissions = getDocumentPermissions(shareFileRefId)
const link = getSharingLink(shareFileRefId)
const _isOwner = isOwner(shareFileRefId)

return (
<>
Expand All @@ -56,7 +59,7 @@ const Sharing = ({ file, t }) => {
<MemberRecipientLite
key={recipient.index}
recipient={recipient}
isOwner={isOwner(file._id)}
isOwner={_isOwner}
/>
))
) : (
Expand Down
10 changes: 7 additions & 3 deletions packages/cozy-viewer/src/ViewerContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ViewerContainer = props => {
const [isReadOnly, setIsReadOnly] = useState(true)
const client = useClient()
useExtendI18n(locales)
const { hasWriteAccess } = useSharingContext()
const { hasWriteAccess, hasSharedParent } = useSharingContext()

const currentFile = files[currentIndex]
const fileCount = files.length
Expand All @@ -59,13 +59,17 @@ const ViewerContainer = props => {
document: currentFile,
client
})
: !hasWriteAccess(currentFile._id)
: !hasWriteAccess(
hasSharedParent(currentFile.path)
? currentFile.dir_id
: currentFile._id
)

setIsReadOnly(res)
}

getIsReadOnly()
}, [client, currentFile, hasWriteAccess, isPublic])
}, [client, currentFile, hasWriteAccess, hasSharedParent, isPublic])

return (
<AlertProvider>
Expand Down

0 comments on commit dee9d4b

Please sign in to comment.