Skip to content

Commit

Permalink
Merge branch 'hotfix/2021.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
PenghaiZhang committed Jan 27, 2022
2 parents d8fd69f + ca0f3dd commit cbbf3bd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ object SearchHelper {
beans.asScala
// Filter out restricted attachments if the user does not have permissions to view them
.filter(a => !a.isRestricted || hasRestrictedAttachmentPrivileges)
.map(sanitiseAttachmentBean)
.map(att => {
val broken = recurseBrokenAttachmentCheck(itemKey, att.getUuid)
def ifNotBroken[T](f: () => Option[T]) = if (!broken) f() else None
Expand Down Expand Up @@ -355,21 +356,33 @@ object SearchHelper {
}
}

/**
* Find out the latest version of the Item which a Custom Attachment points to.
*
* @param version Version of a linked Item. It is either 0 or 1 where 0 means using the latest version
* and 1 means always using version 1.
* @param uuid UUID of the linked Item.
*/
def getLatestVersionForCustomAttachment(version: Int, uuid: String): Int = {
version match {
// If version of is 0, find the real latest version of this Item.
case 0 => LegacyGuice.itemService.getLatestVersion(uuid)
case realVersion => realVersion
}
}

/**
* Determines if a given customAttachment is invalid. Required as these attachments can be recursive.
* @param customAttachment The attachment to check.
* @return If true, this attachment is broken.
*/
def getBrokenAttachmentStatusForResourceAttachment(
customAttachment: CustomAttachment): Boolean = {
val uuid = customAttachment.getData("uuid").asInstanceOf[String]
// If version of the linked Item is 0, find the latest version of this Item.
val version = customAttachment.getData("version").asInstanceOf[Int] match {
case 0 => LegacyGuice.itemService.getLatestVersion(uuid)
case realVersion => realVersion
}
val uuid = customAttachment.getData("uuid").asInstanceOf[String]
val version = customAttachment.getData("version").asInstanceOf[Int]

val key = new ItemId(uuid, getLatestVersionForCustomAttachment(version, uuid))

val key = new ItemId(uuid, version)
if (customAttachment.getType != "resource") {
return false;
}
Expand Down Expand Up @@ -488,4 +501,23 @@ object SearchHelper {
*/
def getAttachmentDescription(itemKey: ItemKey, attachmentUuid: String): Option[String] =
Option(LegacyGuice.itemService.getAttachmentForUuid(itemKey, attachmentUuid).getDescription)

/**
* When an AttachmentBean is converted to SearchResultAttachment, it may require some extra sanitising
* to complete the conversion. The sanitising work includes tasks listed below.
*
* 1. Help ResourceAttachmentBean check the version of its linked resource.
*
* @param att An AttachmentBean to be sanitised.
*/
def sanitiseAttachmentBean(att: AttachmentBean): AttachmentBean = {
att match {
case bean: ResourceAttachmentBean =>
val latestVersion =
getLatestVersionForCustomAttachment(bean.getItemVersion, bean.getItemUuid)
bean.setItemVersion(latestVersion)
case _ =>
}
att
}
}
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ name := "Equella"

(ThisBuild / equellaMajor) := 2021
(ThisBuild / equellaMinor) := 2
(ThisBuild / equellaPatch) := 1
(ThisBuild / equellaPatch) := 2
(ThisBuild / equellaStream) := "Stable"
(ThisBuild / equellaBuild) := buildConfig.value.getString("build.buildname")
(ThisBuild / buildTimestamp) := Instant.now().getEpochSecond
Expand Down

0 comments on commit cbbf3bd

Please sign in to comment.