diff --git a/packages/cozy-viewer/src/Footer/BottomSheetContent.jsx b/packages/cozy-viewer/src/Footer/BottomSheetContent.jsx
index d0de05beff..8ad5703ffb 100644
--- a/packages/cozy-viewer/src/Footer/BottomSheetContent.jsx
+++ b/packages/cozy-viewer/src/Footer/BottomSheetContent.jsx
@@ -5,7 +5,7 @@ import { BottomSheetItem } from 'cozy-ui/transpiled/react/BottomSheet'
import getPanelBlocks, { getPanelBlocksSpecs } from '../Panel/getPanelBlocks'
-const BottomSheetContent = ({ file, isPublic }) => {
+const BottomSheetContent = ({ file, isPublic, isReadOnly }) => {
const panelBlocks = getPanelBlocks({
panelBlocksSpecs: getPanelBlocksSpecs(isPublic),
file
@@ -17,14 +17,15 @@ const BottomSheetContent = ({ file, isPublic }) => {
disableGutters
disableElevation={index === panelBlocks.length - 1}
>
-
+
))
}
BottomSheetContent.propTypes = {
file: PropTypes.object.isRequired,
- isPublic: PropTypes.bool
+ isPublic: PropTypes.bool,
+ isReadOnly: PropTypes.bool
}
export default BottomSheetContent
diff --git a/packages/cozy-viewer/src/Footer/FooterContent.jsx b/packages/cozy-viewer/src/Footer/FooterContent.jsx
index f71ccfff30..102e44b0d7 100644
--- a/packages/cozy-viewer/src/Footer/FooterContent.jsx
+++ b/packages/cozy-viewer/src/Footer/FooterContent.jsx
@@ -39,7 +39,13 @@ const useStyles = makeStyles(theme => ({
}
}))
-const FooterContent = ({ file, toolbarRef, children, isPublic }) => {
+const FooterContent = ({
+ file,
+ toolbarRef,
+ children,
+ isPublic,
+ isReadOnly
+}) => {
const styles = useStyles()
const toolbarProps = useMemo(() => ({ ref: toolbarRef }), [toolbarRef])
@@ -69,7 +75,11 @@ const FooterContent = ({ file, toolbarRef, children, isPublic }) => {
FooterActionButtonsWithFile={FooterActionButtonsWithFile}
/>
-
+
)
}
@@ -78,6 +88,7 @@ FooterContent.propTypes = {
file: PropTypes.object.isRequired,
toolbarRef: PropTypes.object,
isPublic: PropTypes.bool,
+ isReadOnly: PropTypes.bool,
children: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node)
diff --git a/packages/cozy-viewer/src/Panel/ActionMenuWrapper.jsx b/packages/cozy-viewer/src/Panel/ActionMenuWrapper.jsx
index 9cf8f92c67..df9b8eb019 100644
--- a/packages/cozy-viewer/src/Panel/ActionMenuWrapper.jsx
+++ b/packages/cozy-viewer/src/Panel/ActionMenuWrapper.jsx
@@ -9,38 +9,54 @@ import ActionMenuDesktop from './ActionMenuDesktop'
import ActionMenuMobile from './ActionMenuMobile'
import { isEditableAttribute } from '../helpers'
-const ActionMenuWrapper = forwardRef(({ file, optionFile, onClose }, ref) => {
- const { name, value } = optionFile
- const { isMobile } = useBreakpoints()
- const { t } = useI18n()
- const { showAlert } = useAlert()
+const ActionMenuWrapper = forwardRef(
+ ({ file, optionFile, isReadOnly, onClose }, ref) => {
+ const { name, value } = optionFile
+ const { isMobile } = useBreakpoints()
+ const { t } = useI18n()
+ const { showAlert } = useAlert()
- const isEditable = isEditableAttribute(name, file)
- const editPath = `${file.metadata.qualification.label}/${file._id}/edit/information?metadata=${optionFile.name}`
+ const isEditable = isEditableAttribute(name, file) && !isReadOnly
+ const editPath = `${file.metadata.qualification.label}/${file._id}/edit/information?metadata=${optionFile.name}`
- const handleCopy = async () => {
- try {
- await navigator.clipboard.writeText(value)
- showAlert({
- message: t(`Viewer.snackbar.copiedToClipboard.success`),
- severity: 'success',
- variant: 'filled',
- icon: false
- })
- } catch (error) {
- showAlert({
- message: t(`Viewer.snackbar.copiedToClipboard.error`),
- severity: 'error',
- variant: 'filled',
- icon: false
- })
+ const handleCopy = async () => {
+ try {
+ await navigator.clipboard.writeText(value)
+ showAlert({
+ message: t(`Viewer.snackbar.copiedToClipboard.success`),
+ severity: 'success',
+ variant: 'filled',
+ icon: false
+ })
+ } catch (error) {
+ showAlert({
+ message: t(`Viewer.snackbar.copiedToClipboard.error`),
+ severity: 'error',
+ variant: 'filled',
+ icon: false
+ })
+ }
+ onClose()
+ }
+
+ if (isMobile) {
+ return (
+
+ )
}
- onClose()
- }
- if (isMobile) {
return (
- {
/>
)
}
-
- return (
-
- )
-})
+)
ActionMenuWrapper.displayName = 'ActionMenuWrapper'
@@ -76,6 +78,7 @@ ActionMenuWrapper.propTypes = {
name: PropTypes.string,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
}),
+ isReadOnly: PropTypes.bool,
onClose: PropTypes.func
}
diff --git a/packages/cozy-viewer/src/Panel/Qualification.jsx b/packages/cozy-viewer/src/Panel/Qualification.jsx
index d843e55a6e..b9629d43c6 100644
--- a/packages/cozy-viewer/src/Panel/Qualification.jsx
+++ b/packages/cozy-viewer/src/Panel/Qualification.jsx
@@ -34,7 +34,7 @@ const ComponentFromMetadataQualificationType = {
bills: QualificationListItemInformation
}
-const Qualification = ({ file, isReadOnly }) => {
+const Qualification = ({ file, isPublic, isReadOnly }) => {
const { metadata = {} } = file
const actionBtnRef = useRef([])
const [showQualifModal, setShowQualifModal] = useState(false)
@@ -75,13 +75,13 @@ const Qualification = ({ file, isReadOnly }) => {
{hasSupportedQualification(file) ? (
setShowQualifModal(true)}
/>
) : (
setShowQualifModal(true)}
/>
)}
@@ -109,7 +109,7 @@ const Qualification = ({ file, isReadOnly }) => {
toggleActionsMenu(idx, name, val)}
@@ -124,6 +124,7 @@ const Qualification = ({ file, isReadOnly }) => {
file={file}
optionFile={optionFile}
ref={actionBtnRef.current[optionFile.id]}
+ isReadOnly={isPublic ? true : isReadOnly}
/>
)}
diff --git a/packages/cozy-viewer/src/Panel/QualificationListItemContact.jsx b/packages/cozy-viewer/src/Panel/QualificationListItemContact.jsx
index 055a35c412..cb154694ce 100644
--- a/packages/cozy-viewer/src/Panel/QualificationListItemContact.jsx
+++ b/packages/cozy-viewer/src/Panel/QualificationListItemContact.jsx
@@ -88,6 +88,7 @@ const QualificationListItemContact = ({ file, isReadOnly }) => {
file={file}
optionFile={optionFile}
ref={actionBtnRef}
+ isReadOnly={isReadOnly}
/>
)}
>
diff --git a/packages/cozy-viewer/src/ViewerContainer.jsx b/packages/cozy-viewer/src/ViewerContainer.jsx
index dcba63607c..25b48eefd7 100644
--- a/packages/cozy-viewer/src/ViewerContainer.jsx
+++ b/packages/cozy-viewer/src/ViewerContainer.jsx
@@ -4,6 +4,7 @@ import React, { createRef, useState, useEffect } from 'react'
import { useClient } from 'cozy-client'
import { isDocumentReadOnly } from 'cozy-client/dist/models/permission'
+import { useSharingContext } from 'cozy-sharing'
import Modal from 'cozy-ui/transpiled/react/Modal'
import { FileDoctype } from 'cozy-ui/transpiled/react/proptypes'
import AlertProvider from 'cozy-ui/transpiled/react/providers/Alert'
@@ -34,6 +35,8 @@ const ViewerContainer = props => {
const [isReadOnly, setIsReadOnly] = useState(true)
const client = useClient()
useExtendI18n(locales)
+ const { hasWriteAccess } = useSharingContext()
+
const currentFile = files[currentIndex]
const fileCount = files.length
const hasPrevious = currentIndex > 0
@@ -51,16 +54,18 @@ const ViewerContainer = props => {
useEffect(() => {
const getIsReadOnly = async () => {
- const res = await isDocumentReadOnly({
- document: currentFile,
- client
- })
+ const res = isPublic
+ ? await isDocumentReadOnly({
+ document: currentFile,
+ client
+ })
+ : !hasWriteAccess(currentFile._id)
setIsReadOnly(res)
}
getIsReadOnly()
- }, [client, currentFile])
+ }, [client, currentFile, hasWriteAccess, isPublic])
return (
diff --git a/packages/cozy-viewer/src/ViewerInformationsWrapper.jsx b/packages/cozy-viewer/src/ViewerInformationsWrapper.jsx
index e735b9ecf0..8e93dec40a 100644
--- a/packages/cozy-viewer/src/ViewerInformationsWrapper.jsx
+++ b/packages/cozy-viewer/src/ViewerInformationsWrapper.jsx
@@ -42,6 +42,7 @@ const ViewerInformationsWrapper = ({
file={currentFile}
toolbarRef={toolbarRef}
isPublic={isPublic}
+ isReadOnly={isReadOnly}
>
{children}
diff --git a/packages/cozy-viewer/src/components/ViewerControls.jsx b/packages/cozy-viewer/src/components/ViewerControls.jsx
index 608388d70e..58da35d9c3 100644
--- a/packages/cozy-viewer/src/components/ViewerControls.jsx
+++ b/packages/cozy-viewer/src/components/ViewerControls.jsx
@@ -141,7 +141,7 @@ class ViewerControls extends Component {
showFilePath={showFilePath}
onMouseEnter={this.showControls}
onMouseLeave={this.hideControls}
- onClose={showClose && onClose}
+ onClose={showClose ? onClose : undefined}
>
{children}