Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Blur sensitive search results (#2640)

Dhruv Bhanushali39341c784a62
diff --git a/frontend/src/components/VAudioThumbnail/VAudioThumbnail.vue b/frontend/src/components/VAudioThumbnail/VAudioThumbnail.vue
index 4f6c843cd..7e85c1f38 100644
--- a/frontend/src/components/VAudioThumbnail/VAudioThumbnail.vue
+++ b/frontend/src/components/VAudioThumbnail/VAudioThumbnail.vue
@@ -1,8 +1,15 @@
<template>
<!-- Should be wrapped by a fixed-width parent -->
- <div class="relative h-0 w-full bg-yellow pt-full" :title="helpText">
+ <div
+ class="relative h-0 w-full overflow-hidden bg-yellow pt-full"
+ :title="helpText"
+ >
<!-- Programmatic thumbnail -->
- <svg class="absolute inset-0" :viewBox="`0 0 ${canvasSize} ${canvasSize}`">
+ <svg
+ class="absolute inset-0"
+ :class="{ hidden: shouldBlur && isOk }"
+ :viewBox="`0 0 ${canvasSize} ${canvasSize}`"
+ >
<template v-for="i in dotCount">
<circle
v-for="j in dotCount"
@@ -19,6 +26,7 @@
<img
ref="imgEl"
class="h-full w-full overflow-clip object-cover object-center"
+ :class="{ 'scale-150 blur-image': shouldBlur }"
:src="audio.thumbnail"
:alt="helpText"
@load="handleLoad"
@@ -28,12 +36,13 @@
</template>
<script lang="ts">
-import { ref, onMounted, defineComponent, PropType } from "vue"
+import { ref, onMounted, computed, defineComponent, PropType } from "vue"
import { rand, hash } from "~/utils/prng"
import { lerp, dist, bezier, Point } from "~/utils/math"
import type { AudioDetail } from "~/types/media"
import { useI18n } from "~/composables/use-i18n"
+import { useUiStore } from "~/stores/ui"
/**
* Displays the cover art for the audio in a square aspect ratio.
@@ -51,13 +60,20 @@ export default defineComponent({
},
},
setup(props) {
+ const uiStore = useUiStore()
+ const shouldBlur = computed(
+ () => uiStore.shouldBlurSensitive && props.audio.isSensitive
+ )
+
const i18n = useI18n()
- const helpText = i18n
- .t("audioThumbnail.alt", {
- title: props.audio.title,
- creator: props.audio.creator,
- })
- ?.toString()
+ const helpText = (
+ shouldBlur.value
+ ? i18n.t("sensitiveContent.title.audio")
+ : i18n.t("audioThumbnail.alt", {
+ title: props.audio.title,
+ creator: props.audio.creator,
+ })
+ )?.toString()
/* Switching */
@@ -106,6 +122,8 @@ export default defineComponent({
offset,
radius,
helpText,
+
+ shouldBlur,
}
},
})
diff --git a/frontend/src/components/VAudioTrack/layouts/VBoxLayout.vue b/frontend/src/components/VAudioTrack/layouts/VBoxLayout.vue
index d914ceb05..8be86d0f5 100644
--- a/frontend/src/components/VAudioTrack/layouts/VBoxLayout.vue
+++ b/frontend/src/components/VAudioTrack/layouts/VBoxLayout.vue
@@ -8,8 +8,9 @@
<div class="info flex flex-grow flex-col justify-between p-4">
<h2
class="font-heading line-clamp-3 text-base font-semibold leading-snug"
+ :class="{ 'blur-text': shouldBlur }"
>
- {{ audio.title }}
+ {{ shouldBlur ? $t("sensitiveContent.title.audio") : audio.title }}
</h2>
<div class="info">
<VLicense
@@ -43,6 +44,7 @@ import { computed, defineComponent, PropType } from "vue"
import type { AudioDetail } from "~/types/media"
import type { AudioSize } from "~/constants/audio"
import { useI18n } from "~/composables/use-i18n"
+import { useUiStore } from "~/stores/ui"
import VLicense from "~/components/VLicense/VLicense.vue"
@@ -78,8 +80,14 @@ export default defineComponent({
i18n.t(`filters.audioCategories.${props.audio.category}`).toString()
)
+ const uiStore = useUiStore()
+ const shouldBlur = computed(
+ () => uiStore.shouldBlurSensitive && props.audio.isSensitive
+ )
+
return {
isSmall,
+ shouldBlur,
width,
categoryLabel,
diff --git a/frontend/src/components/VAudioTrack/layouts/VRowLayout.vue b/frontend/src/components/VAudioTrack/layouts/VRowLayout.vue
index 8ca7468c8..1f68f7cc1 100644
--- a/frontend/src/components/VAudioTrack/layouts/VRowLayout.vue
+++ b/frontend/src/components/VAudioTrack/layouts/VRowLayout.vue
@@ -27,9 +27,10 @@
:class="{
'text-2xl': isMedium || isLarge,
'leading-snug': isSmall,
+ 'blur-text': shouldBlur,
}"
>
- {{ audio.title }}
+ {{ shouldBlur ? $t("sensitiveContent.title.audio") : audio.title }}
</div>
<div
@@ -42,8 +43,14 @@
}"
>
<div class="part-a">
- <i18n tag="span" path="audioTrack.creator">
- <template #creator>{{ audio.creator }}</template> </i18n
+ <i18n
+ tag="span"
+ path="audioTrack.creator"
+ :class="{ 'blur-text': shouldBlur }"
+ >
+ <template #creator>{{
+ shouldBlur ? $t("sensitiveContent.creator") : audio.creator
+ }}</template> </i18n
><span v-show="isLarge" class="mx-2" aria-hidden="true">{{
$t("interpunct")
}}</span>
@@ -101,6 +108,7 @@ import { computed, defineComponent, PropType } from "vue"
import { timeFmt } from "~/utils/time-fmt"
import type { AudioDetail } from "~/types/media"
import type { AudioSize } from "~/constants/audio"
+import { useUiStore } from "~/stores/ui"
import VAudioThumbnail from "~/components/VAudioThumbnail/VAudioThumbnail.vue"
import VLicense from "~/components/VLicense/VLicense.vue"
@@ -133,6 +141,11 @@ export default defineComponent({
const isMedium = computed(() => props.size === "m")
const isLarge = computed(() => props.size === "l")
+ const uiStore = useUiStore()
+ const shouldBlur = computed(
+ () => uiStore.shouldBlurSensitive && props.audio.isSensitive
+ )
+
return {
timeFmt,
@@ -142,6 +155,8 @@ export default defineComponent({
isSmall,
isMedium,
isLarge,
+
+ shouldBlur,
}
},
})
diff --git a/frontend/src/components/VSearchResultsGrid/VImageCell.vue b/frontend/src/components/VSearchResultsGrid/VImageCell.vue
index 815c20b4b..15a8d05e1 100644
--- a/frontend/src/components/VSearchResultsGrid/VImageCell.vue
+++ b/frontend/src/components/VSearchResultsGrid/VImageCell.vue
@@ -20,8 +20,15 @@
ref="img"
loading="lazy"
class="block w-full rounded-sm object-cover"
- :class="isSquare ? 'h-full' : 'margin-auto'"
- :alt="image.title"
+ :class="[
+ isSquare ? 'h-full' : 'margin-auto',
+ { 'scale-150 blur-image': shouldBlur },
+ ]"
+ :alt="
+ shouldBlur
+ ? $t('sensitiveContent.title.image').toString()
+ : image.title
+ "
:src="imageUrl"
:width="imgWidth"
:height="imgHeight"
@@ -32,7 +39,13 @@
<figcaption
class="invisible absolute bottom-0 left-0 bg-white p-1 text-dark-charcoal group-hover:visible group-focus:visible"
>
- <h2 class="sr-only">{{ image.title }}</h2>
+ <h2 class="sr-only">
+ {{
+ shouldBlur
+ ? $t("sensitiveContent.title.image").toString()
+ : image.title
+ }}
+ </h2>
<VLicense :license="image.license" :hide-name="true" />
</figcaption>
</figure>
@@ -47,8 +60,8 @@ import { computed, defineComponent, PropType } from "vue"
import type { AspectRatio, ImageDetail } from "~/types/media"
import { useImageCellSize } from "~/composables/use-image-cell-size"
import { useI18n } from "~/composables/use-i18n"
-
import { useAnalytics } from "~/composables/use-analytics"
+import { useUiStore } from "~/stores/ui"
import { IMAGE } from "~/constants/media"
@@ -143,9 +156,11 @@ export default defineComponent({
}
const contextSensitiveTitle = computed(() => {
- return i18n.t("browsePage.aria.imageTitle", {
- title: props.image.title,
- })
+ return shouldBlur.value
+ ? i18n.t("sensitiveContent.title.image")
+ : i18n.t("browsePage.aria.imageTitle", {
+ title: props.image.title,
+ })
})
const { sendCustomEvent } = useAnalytics()
@@ -159,6 +174,11 @@ export default defineComponent({
})
}
+ const uiStore = useUiStore()
+ const shouldBlur = computed(
+ () => uiStore.shouldBlurSensitive && props.image.isSensitive
+ )
+
return {
styles,
imgWidth,
@@ -166,6 +186,7 @@ export default defineComponent({
imageUrl,
imageLink,
contextSensitiveTitle,
+ shouldBlur,
getImageForeignUrl,
onImageLoadError,
diff --git a/frontend/src/locales/scripts/en.json5 b/frontend/src/locales/scripts/en.json5
index c94cdcf57..df22a606d 100644
--- a/frontend/src/locales/scripts/en.json5
+++ b/frontend/src/locales/scripts/en.json5
@@ -743,4 +743,11 @@
report: {
imageDetails: "See image details",
},
+ sensitiveContent: {
+ title: {
+ image: "This image may contain sensitive content.",
+ audio: "This audio track may contain sensitive content.",
+ },
+ creator: "Creator",
+ },
}
diff --git a/frontend/src/stores/ui.ts b/frontend/src/stores/ui.ts
index b15fb466c..8894aa873 100644
--- a/frontend/src/stores/ui.ts
+++ b/frontend/src/stores/ui.ts
@@ -42,6 +42,10 @@ export interface UiState {
*/
isMobileUa: boolean
dismissedBanners: BannerId[]
+ /**
+ * whether to blur sensitive content in search and single result pages
+ */
+ shouldBlurSensitive: boolean
}
export const breakpoints = Object.keys(ALL_SCREEN_SIZES)
@@ -55,6 +59,7 @@ export const useUiStore = defineStore("ui", {
breakpoint: "sm",
isMobileUa: true,
dismissedBanners: [],
+ shouldBlurSensitive: true,
}),
getters: {
diff --git a/frontend/tailwind.config.js b/frontend/tailwind.config.js
index 27ed190b3..2a6aaeea6 100644
--- a/frontend/tailwind.config.js
+++ b/frontend/tailwind.config.js
@@ -197,6 +197,10 @@ module.exports = {
serif: [...defaultTheme.fontFamily.serif],
},
extend: {
+ blur: {
+ image: "60px",
+ text: "4px",
+ },
lineHeight: {
loose: "2.0",
larger: "1.9",
diff --git a/frontend/test/unit/specs/components/AudioTrack/v-audio-track.spec.js b/frontend/test/unit/specs/components/AudioTrack/v-audio-track.spec.js
index ec71bb819..14aa9c03c 100644
--- a/frontend/test/unit/specs/components/AudioTrack/v-audio-track.spec.js
+++ b/frontend/test/unit/specs/components/AudioTrack/v-audio-track.spec.js
@@ -101,4 +101,35 @@ describe("AudioTrack", () => {
expect(getByText(/Reproduction not allowed./i)).toBeVisible()
// It's not possible to get the vm to test that Sentry has been called
})
+
+ it("has blurred title in box layout when audio is sensitive", async () => {
+ options.propsData.audio.isSensitive = true
+ options.propsData.layout = "box"
+ const { getByText } = render(VAudioTrack, options, configureVue)
+ const h2 = getByText("This audio track may contain sensitive content.")
+ expect(h2).toHaveClass("blur-text")
+ })
+
+ it("has blurred info in row layout when audio is sensitive", async () => {
+ options.propsData.audio.isSensitive = true
+ options.propsData.layout = "row"
+ const { getByText } = render(VAudioTrack, options, configureVue)
+
+ const h2 = getByText("This audio track may contain sensitive content.")
+ expect(h2).toHaveClass("blur-text")
+
+ const creator = getByText("by Creator")
+ expect(creator).toHaveClass("blur-text")
+ })
+
+ it("is does not contain title or creator anywhere when the audio is sensitive", async () => {
+ options.propsData.audio.isSensitive = true
+ options.propsData.layout = "row"
+ const screen = render(VAudioTrack, options, configureVue)
+ let { title, creator } = options.propsData.audio
+ let match = RegExp(`(${title}|${creator})`)
+ expect(screen.queryAllByText(match)).toEqual([])
+ expect(screen.queryAllByTitle(match)).toEqual([])
+ expect(screen.queryAllByAltText(match)).toEqual([])
+ })
})
diff --git a/frontend/test/unit/specs/components/VSearchResultsGrid/v-image-cell.spec.js b/frontend/test/unit/specs/components/VSearchResultsGrid/v-image-cell.spec.js
index 73fa7d414..17de76219 100644
--- a/frontend/test/unit/specs/components/VSearchResultsGrid/v-image-cell.spec.js
+++ b/frontend/test/unit/specs/components/VSearchResultsGrid/v-image-cell.spec.js
@@ -45,4 +45,20 @@ describe("VImageCell", () => {
relatedTo: null,
})
})
+
+ it("is blurred when the image is sensitive", async () => {
+ options.props.image.isSensitive = true
+ const { getByAltText } = render(VImageCell, options)
+ const img = getByAltText("This image may contain sensitive content.")
+ expect(img).toHaveClass("blur-image")
+ })
+
+ it("is does not contain title anywhere when the image is sensitive", async () => {
+ options.props.image.isSensitive = true
+ const screen = render(VImageCell, options)
+ let match = RegExp(image.title)
+ expect(screen.queryAllByText(match)).toEqual([])
+ expect(screen.queryAllByTitle(match)).toEqual([])
+ expect(screen.queryAllByAltText(match)).toEqual([])
+ })
})