Skip to content

Commit cbbf3bd

Browse files
committed
Merge branch 'hotfix/2021.2.2'
2 parents d8fd69f + ca0f3dd commit cbbf3bd

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

Source/Plugins/Core/com.equella.core/scalasrc/com/tle/web/api/search/SearchHelper.scala

+39-7
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ object SearchHelper {
295295
beans.asScala
296296
// Filter out restricted attachments if the user does not have permissions to view them
297297
.filter(a => !a.isRestricted || hasRestrictedAttachmentPrivileges)
298+
.map(sanitiseAttachmentBean)
298299
.map(att => {
299300
val broken = recurseBrokenAttachmentCheck(itemKey, att.getUuid)
300301
def ifNotBroken[T](f: () => Option[T]) = if (!broken) f() else None
@@ -355,21 +356,33 @@ object SearchHelper {
355356
}
356357
}
357358

359+
/**
360+
* Find out the latest version of the Item which a Custom Attachment points to.
361+
*
362+
* @param version Version of a linked Item. It is either 0 or 1 where 0 means using the latest version
363+
* and 1 means always using version 1.
364+
* @param uuid UUID of the linked Item.
365+
*/
366+
def getLatestVersionForCustomAttachment(version: Int, uuid: String): Int = {
367+
version match {
368+
// If version of is 0, find the real latest version of this Item.
369+
case 0 => LegacyGuice.itemService.getLatestVersion(uuid)
370+
case realVersion => realVersion
371+
}
372+
}
373+
358374
/**
359375
* Determines if a given customAttachment is invalid. Required as these attachments can be recursive.
360376
* @param customAttachment The attachment to check.
361377
* @return If true, this attachment is broken.
362378
*/
363379
def getBrokenAttachmentStatusForResourceAttachment(
364380
customAttachment: CustomAttachment): Boolean = {
365-
val uuid = customAttachment.getData("uuid").asInstanceOf[String]
366-
// If version of the linked Item is 0, find the latest version of this Item.
367-
val version = customAttachment.getData("version").asInstanceOf[Int] match {
368-
case 0 => LegacyGuice.itemService.getLatestVersion(uuid)
369-
case realVersion => realVersion
370-
}
381+
val uuid = customAttachment.getData("uuid").asInstanceOf[String]
382+
val version = customAttachment.getData("version").asInstanceOf[Int]
383+
384+
val key = new ItemId(uuid, getLatestVersionForCustomAttachment(version, uuid))
371385

372-
val key = new ItemId(uuid, version)
373386
if (customAttachment.getType != "resource") {
374387
return false;
375388
}
@@ -488,4 +501,23 @@ object SearchHelper {
488501
*/
489502
def getAttachmentDescription(itemKey: ItemKey, attachmentUuid: String): Option[String] =
490503
Option(LegacyGuice.itemService.getAttachmentForUuid(itemKey, attachmentUuid).getDescription)
504+
505+
/**
506+
* When an AttachmentBean is converted to SearchResultAttachment, it may require some extra sanitising
507+
* to complete the conversion. The sanitising work includes tasks listed below.
508+
*
509+
* 1. Help ResourceAttachmentBean check the version of its linked resource.
510+
*
511+
* @param att An AttachmentBean to be sanitised.
512+
*/
513+
def sanitiseAttachmentBean(att: AttachmentBean): AttachmentBean = {
514+
att match {
515+
case bean: ResourceAttachmentBean =>
516+
val latestVersion =
517+
getLatestVersionForCustomAttachment(bean.getItemVersion, bean.getItemUuid)
518+
bean.setItemVersion(latestVersion)
519+
case _ =>
520+
}
521+
att
522+
}
491523
}

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ name := "Equella"
115115

116116
(ThisBuild / equellaMajor) := 2021
117117
(ThisBuild / equellaMinor) := 2
118-
(ThisBuild / equellaPatch) := 1
118+
(ThisBuild / equellaPatch) := 2
119119
(ThisBuild / equellaStream) := "Stable"
120120
(ThisBuild / equellaBuild) := buildConfig.value.getString("build.buildname")
121121
(ThisBuild / buildTimestamp) := Instant.now().getEpochSecond

0 commit comments

Comments
 (0)