Skip to content

Commit

Permalink
fix(filesharing): file appear as shared by their owner if it has a nu…
Browse files Browse the repository at this point in the history
…merical user ID

Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
  • Loading branch information
julien-nc committed Sep 30, 2024
1 parent 526a504 commit 0af3637
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions apps/files_sharing/src/actions/sharingStatusAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ import { generateAvatarSvg } from '../utils/AccountIcon.ts'
import './sharingStatusAction.scss'

const isExternal = (node: Node) => {
return node.attributes?.['is-federated'] ?? false
return node.attributes.remote_id !== undefined
}

export const action = new FileAction({
id: 'sharing-status',
displayName(nodes: Node[]) {
const node = nodes[0]
const shareTypes = Object.values(node?.attributes?.['share-types'] || {}).flat() as number[]
const ownerId = node?.attributes?.['owner-id']

if (shareTypes.length > 0
|| (ownerId !== getCurrentUser()?.uid || isExternal(node))) {
|| (node.owner !== getCurrentUser()?.uid || isExternal(node))) {
return t('files_sharing', 'Shared')
}

Expand All @@ -55,15 +54,14 @@ export const action = new FileAction({

title(nodes: Node[]) {
const node = nodes[0]
const ownerId = node?.attributes?.['owner-id']
const ownerDisplayName = node?.attributes?.['owner-display-name']

// Mixed share types
if (Array.isArray(node.attributes?.['share-types']) && node.attributes?.['share-types'].length > 1) {
return t('files_sharing', 'Shared multiple times with different people')
}

if (ownerId && (ownerId !== getCurrentUser()?.uid || isExternal(node))) {
if (node.owner && (node.owner !== getCurrentUser()?.uid || isExternal(node))) {
const ownerDisplayName = node?.attributes?.['owner-display-name']
return t('files_sharing', 'Shared by {ownerDisplayName}', { ownerDisplayName })
}

Expand Down Expand Up @@ -96,10 +94,9 @@ export const action = new FileAction({
return CircleSvg
}

const ownerId = node?.attributes?.['owner-id']
if (ownerId && (ownerId !== getCurrentUser()?.uid || isExternal(node))) {
if (node.owner && (node.owner !== getCurrentUser()?.uid || isExternal(node))) {
const sanitizeId = (id: string) => id.replace(/[^a-zA-Z0-9._%+@-]+/g, '').replace(/\//g, '')
return generateAvatarSvg(sanitizeId(ownerId), isExternal(node))
return generateAvatarSvg(sanitizeId(node.owner), isExternal(node))
}

return AccountPlusSvg
Expand All @@ -111,8 +108,8 @@ export const action = new FileAction({
}

const node = nodes[0]
const ownerId = node?.attributes?.['owner-id']
const isMixed = Array.isArray(node.attributes?.['share-types'])
const shareTypes = node.attributes?.['share-types']
const isMixed = Array.isArray(shareTypes) && shareTypes.length > 0

// If the node is shared multiple times with
// different share types to the current user
Expand All @@ -121,7 +118,7 @@ export const action = new FileAction({
}

// If the node is shared by someone else
if (ownerId && (ownerId !== getCurrentUser()?.uid || isExternal(node))) {
if (node.owner && (node.owner !== getCurrentUser()?.uid || isExternal(node))) {
return true
}

Expand Down

0 comments on commit 0af3637

Please sign in to comment.