This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-8576-66e46b39331fcee8e0eeee323147a875aa4be04c
in repository https://gitbox.apache.org/repos/asf/texera.git

commit 9562edb6ef4e1a63ddcf4ba6f60fc00b50b3f4dd
Author: yangzhang75 <[email protected]>
AuthorDate: Tue Oct 27 21:48:33 2026 +0000

    feat(workflow): match search and listings against the copy on show (#8576)
    
    ### What changes were proposed in this PR?
    
    A listing is where most people meet a workflow, so it has to agree with
    what opening it shows.
    This makes search and the hub match, display and link against the copy
    on show.
    
    - **Search matches the copy the caller may see.** One search returns
    both the caller's own
    workflows and public ones, so the filter is a disjunction of guarded
    filters — the working copy
    for rows they were granted, the frozen copy for rows they reach only
    because those are public.
    Written over bare columns rather than a `CASE`, so each side stays
    eligible for its own PGroonga
    index. A pinned workflow no longer turns up on keywords that exist only
    behind the pin, and the
      author still finds their own work on what they just typed.
    - **Listings show the frozen name and description** to a viewer without
    granted access — the same
    copy the detail page serves, so a card cannot advertise a title that
    opening it does not show.
      Both are NULL while following, which leaves the live values in place.
    - **The hub is the public shelf**, so everything on it is listed as the
    public sees it, for the
      author too: they are looking at the shelf, not at their own dashboard.
    - **One definition of "the public is behind".**
    `WorkflowPublishService.pinDiffersFromWorkingCopy`
    is the share dialog's comparison as a SQL condition, and the search
    projection and the hub
    listing both use it, so a card and the dialog cannot disagree about
    whether edits are held back.
    
    ### Any related issues, documentation, discussions?
    
    Closes #7940
    Part of #7828. Design discussion: #7128. Builds on #7853 and #8575, both
    merged.
    
    ### How was this PR tested?
    
    19 new cases in `WorkflowPublishSpec` plus
    `WorkflowSearchQueryBuilderSpec` and
    `UnifiedResourceSchemaSpec` (567 in the dashboard package):
    
    - search not matching a public workflow on anything that exists only in
    unpublished edits, and
    matching it on its published copy — content, name and description, each
    separately;
    - an unpinned public workflow still matching the author's latest, and
    the author still matching
      their own workflow on a name only they can see;
    - a listing showing a public viewer the published name and description,
    a collaborator the live
      ones, and a private workflow's own listing untouched;
    - the drift flag a card carries: true while a pin holds edits back,
    false for a workflow with
    nothing frozen, and equal to what the share dialog reports for the same
    workflow — including
    after a rename and after a change of view, the two fields most easily
    left out of one of the
      three places that answer this.
    
    The shared condition was checked by mutation: dropping the default-view
    term from it turns the
    card-versus-dialog case red.
    
    `scalafmtCheckAll` clean.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (Opus 5)
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    Co-authored-by: Claude Opus 5 <[email protected]>
---
 .../resource/dashboard/SearchQueryBuilder.scala    |  14 +-
 .../resource/dashboard/UnifiedResourceSchema.scala |  19 +-
 .../VersionedResourceSearchQueryBuilder.scala      |   3 +-
 .../dashboard/WorkflowSearchQueryBuilder.scala     | 131 +++++++--
 .../web/resource/dashboard/hub/HubResource.scala   |  22 +-
 .../user/workflow/WorkflowPublishService.scala     |  61 +++-
 .../dashboard/user/workflow/WorkflowResource.scala |   5 +-
 .../dashboard/UnifiedResourceSchemaSpec.scala      |  35 ++-
 .../dashboard/WorkflowSearchQueryBuilderSpec.scala |  88 +++++-
 .../user/workflow/WorkflowPublishSpec.scala        | 308 ++++++++++++++++++++-
 10 files changed, 647 insertions(+), 39 deletions(-)

diff --git 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/SearchQueryBuilder.scala
 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/SearchQueryBuilder.scala
index c132500625..76c6e7d976 100644
--- 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/SearchQueryBuilder.scala
+++ 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/SearchQueryBuilder.scala
@@ -58,7 +58,17 @@ trait SearchQueryBuilder {
       includePublic: Boolean = false
   ): TableLike[_]
 
-  protected def constructWhereClause(uid: Integer, params: SearchQueryParams): 
Condition
+  /**
+    * @param includePublic whether public resources the user has not been 
granted access to are in
+    *                      scope. Builders whose content differs between the 
public and the private
+    *                      view (workflows, whose public copy is a pinned 
version) need this to know
+    *                      which copy a filter may match against.
+    */
+  protected def constructWhereClause(
+      uid: Integer,
+      params: SearchQueryParams,
+      includePublic: Boolean = false
+  ): Condition
 
   protected def getGroupByFields: Seq[GroupField] = Seq.empty
 
@@ -78,7 +88,7 @@ trait SearchQueryBuilder {
     val query: SelectGroupByStep[Record] = context
       .selectDistinct(mappedResourceSchema.allFields: _*)
       .from(constructFromClause(uid, params, includePublic))
-      .where(constructWhereClause(uid, params))
+      .where(constructWhereClause(uid, params, includePublic))
     val groupByFields = getGroupByFields
     if (groupByFields.nonEmpty) {
       query.groupBy(groupByFields: _*)
diff --git 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/UnifiedResourceSchema.scala
 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/UnifiedResourceSchema.scala
index 40171c8f11..d1144f635f 100644
--- 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/UnifiedResourceSchema.scala
+++ 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/UnifiedResourceSchema.scala
@@ -80,7 +80,14 @@ object UnifiedResourceSchema {
       // mark the row and route it accordingly.
       workflowDefaultView: Field[DefaultViewEnum] = DSL.cast(null, 
classOf[DefaultViewEnum]),
       modelFramework: Field[String] = DSL.cast(null, classOf[String]),
-      modelFormat: Field[String] = DSL.cast(null, classOf[String])
+      modelFormat: Field[String] = DSL.cast(null, classOf[String]),
+      workflowHasUnpublishedChanges: Field[java.lang.Boolean] =
+        DSL.cast(null, classOf[java.lang.Boolean]),
+      workflowPublishedName: Field[String] = DSL.cast(null, classOf[String]),
+      workflowPublishedDescription: Field[String] = DSL.cast(null, 
classOf[String]),
+      workflowPublishedDefaultView: Field[DefaultViewEnum] =
+        DSL.cast(null, classOf[DefaultViewEnum]),
+      viewerHasGrantedAccess: Field[java.lang.Boolean] = DSL.cast(null, 
classOf[java.lang.Boolean])
   ): UnifiedResourceSchema = {
     new UnifiedResourceSchema(
       Seq(
@@ -110,7 +117,15 @@ object UnifiedResourceSchema {
         workflowCoverImage -> workflowCoverImage.as("workflow_cover_image"),
         workflowDefaultView -> workflowDefaultView.as("workflow_default_view"),
         modelFramework -> modelFramework.as("model_framework"),
-        modelFormat -> modelFormat.as("model_format")
+        modelFormat -> modelFormat.as("model_format"),
+        workflowHasUnpublishedChanges -> workflowHasUnpublishedChanges
+          .as("workflow_has_unpublished_changes"),
+        workflowPublishedName -> 
workflowPublishedName.as("workflow_published_name"),
+        workflowPublishedDescription -> workflowPublishedDescription
+          .as("workflow_published_description"),
+        workflowPublishedDefaultView -> workflowPublishedDefaultView
+          .as("workflow_published_default_view"),
+        viewerHasGrantedAccess -> 
viewerHasGrantedAccess.as("viewer_has_granted_access")
       )
     )
   }
diff --git 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/VersionedResourceSearchQueryBuilder.scala
 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/VersionedResourceSearchQueryBuilder.scala
index 237eb1cd53..2f002fae4f 100644
--- 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/VersionedResourceSearchQueryBuilder.scala
+++ 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/VersionedResourceSearchQueryBuilder.scala
@@ -109,7 +109,8 @@ abstract class VersionedResourceSearchQueryBuilder[Rec <: 
Record, P](
 
   override protected def constructWhereClause(
       uid: Integer,
-      params: DashboardResource.SearchQueryParams
+      params: DashboardResource.SearchQueryParams,
+      includePublic: Boolean
   ): Condition = {
     val splitKeywords = params.keywords.asScala
       .flatMap(_.split("[+\\-()<>~*@\"]"))
diff --git 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/WorkflowSearchQueryBuilder.scala
 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/WorkflowSearchQueryBuilder.scala
index 2e08a98d57..ca0e80fb4e 100644
--- 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/WorkflowSearchQueryBuilder.scala
+++ 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/WorkflowSearchQueryBuilder.scala
@@ -23,9 +23,10 @@ import org.apache.texera.dao.jooq.generated.Tables._
 import org.apache.texera.dao.jooq.generated.tables.pojos.Workflow
 import 
org.apache.texera.web.resource.dashboard.DashboardResource.DashboardClickableFileEntry
 import org.apache.texera.web.resource.dashboard.FulltextSearchQueryUtils._
+import 
org.apache.texera.web.resource.dashboard.user.workflow.WorkflowPublishService
 import 
org.apache.texera.web.resource.dashboard.user.workflow.WorkflowResource.DashboardWorkflow
 import org.jooq.impl.DSL
-import org.jooq.{Condition, GroupField, Record, TableLike}
+import org.jooq.{Condition, Field, GroupField, Record, TableLike}
 
 import scala.jdk.CollectionConverters.CollectionHasAsScala
 import org.apache.texera.dao.jooq.generated.enums.{DefaultViewEnum, 
PrivilegeEnum}
@@ -53,7 +54,29 @@ object WorkflowSearchQueryBuilder extends SearchQueryBuilder 
{
       ownerId = WORKFLOW_OF_USER.UID,
       userName = USER.NAME,
       workflowCoverImage = 
DSL.max(WORKFLOW_COVER_IMAGE.IMAGE).as("workflow_cover_image"),
-      workflowDefaultView = WORKFLOW.DEFAULT_VIEW.as("workflow_default_view")
+      workflowDefaultView = WORKFLOW.DEFAULT_VIEW.as("workflow_default_view"),
+      // The isNotNull guard because isDistinctFrom would read a NULL pin as 
different content, and
+      // every unpinned public workflow would report drift. Aggregated to stay 
out of the GROUP BY,
+      // which would otherwise group the search by two TEXT columns.
+      workflowHasUnpublishedChanges = DSL
+        .boolOr(
+          WORKFLOW.PUBLISHED_CONTENT.isNotNull
+            .and(WorkflowPublishService.pinDiffersFromWorkingCopy)
+        )
+        .as("workflow_has_unpublished_changes"),
+      // What a viewer without granted access is shown instead of the author's 
live metadata. NULL
+      // while following, which the reader treats as "show the live values".
+      workflowPublishedName = 
DSL.max(WORKFLOW.PUBLISHED_NAME).as("workflow_published_name"),
+      workflowPublishedDescription =
+        
DSL.max(WORKFLOW.PUBLISHED_DESCRIPTION).as("workflow_published_description"),
+      // The view belongs with the name and the description: a card that opens 
the frozen copy in
+      // the author's live view would offer a Form View over a graph that 
carries no form.
+      workflowPublishedDefaultView =
+        
DSL.max(WORKFLOW.PUBLISHED_DEFAULT_VIEW).as("workflow_published_default_view"),
+      // The access join is already restricted to the caller, so this needs no 
user id of its own.
+      viewerHasGrantedAccess = DSL
+        .boolOr(WORKFLOW_USER_ACCESS.UID.isNotNull)
+        .as("viewer_has_granted_access")
     )
   }
 
@@ -88,9 +111,58 @@ object WorkflowSearchQueryBuilder extends 
SearchQueryBuilder {
     baseQuery.where(condition)
   }
 
+  /** Rows the user was granted access to, as opposed to rows they see only 
because it is public. */
+  private def grantedAccessCondition(uid: Integer): Condition =
+    if (uid == null) DSL.falseCondition()
+    else WORKFLOW_USER_ACCESS.UID.eq(uid)
+
+  /**
+    * The three searchable columns carrying one copy. They travel together 
because a pin freezes them
+    * together: a filter over content alone would match a pinned workflow on a 
title no public viewer
+    * has seen.
+    */
+  private case class WorkflowCopy(
+      name: Field[String],
+      description: Field[String],
+      content: Field[String]
+  )
+
+  private val workingCopy =
+    WorkflowCopy(WORKFLOW.NAME, WORKFLOW.DESCRIPTION, WORKFLOW.CONTENT)
+  private val pinnedCopy =
+    WorkflowCopy(
+      WORKFLOW.PUBLISHED_NAME,
+      WORKFLOW.PUBLISHED_DESCRIPTION,
+      WORKFLOW.PUBLISHED_CONTENT
+    )
+
+  /**
+    * Applies a filter to whichever copy the user is allowed to see: one 
search can return both their
+    * own workflows and public ones, and a pinned public one must not turn up 
on keywords that exist
+    * only behind the pin. A disjunction of guarded filters over bare columns 
rather than a CASE, so
+    * each side stays eligible for its own PGroonga index.
+    */
+  private def onVisibleCopy(
+      uid: Integer,
+      includePublic: Boolean
+  )(build: WorkflowCopy => Condition): Condition = {
+    val onWorkingCopy = build(workingCopy).and(grantedAccessCondition(uid))
+    val onPublicCopy = WORKFLOW.IS_PUBLIC
+      .eq(true)
+      .and(
+        // Following leaves the pinned columns NULL, and the public copy is 
then the working one.
+        build(pinnedCopy)
+          .or(WORKFLOW.PUBLISHED_CONTENT.isNull.and(build(workingCopy)))
+      )
+    if (uid == null) onPublicCopy
+    else if (includePublic) onWorkingCopy.or(onPublicCopy)
+    else onWorkingCopy
+  }
+
   override protected def constructWhereClause(
       uid: Integer,
-      params: DashboardResource.SearchQueryParams
+      params: DashboardResource.SearchQueryParams,
+      includePublic: Boolean
   ): Condition = {
     val splitKeywords = params.keywords.asScala
       .flatMap(_.split("[+\\-()<>~*@\"]"))
@@ -114,13 +186,23 @@ object WorkflowSearchQueryBuilder extends 
SearchQueryBuilder {
       // Apply owner filter
       .and(getContainsFilter(params.owners, USER.EMAIL))
       // Apply operators filter
-      .and(getOperatorsFilter(params.operators, WORKFLOW.CONTENT))
+      .and(
+        if (params.operators.isEmpty) DSL.noCondition()
+        else
+          onVisibleCopy(uid, includePublic)(copy =>
+            getOperatorsFilter(params.operators, copy.content)
+          )
+      )
       // Apply fulltext search filter
       .and(
-        getFullTextSearchFilter(
-          splitKeywords,
-          List(WORKFLOW.NAME, WORKFLOW.DESCRIPTION, WORKFLOW.CONTENT)
-        )
+        if (splitKeywords.isEmpty) DSL.noCondition()
+        else
+          onVisibleCopy(uid, includePublic)(copy =>
+            getFullTextSearchFilter(
+              splitKeywords,
+              List(copy.name, copy.description, copy.content)
+            )
+          )
       )
   }
 
@@ -141,20 +223,37 @@ object WorkflowSearchQueryBuilder extends 
SearchQueryBuilder {
       uid: Integer,
       record: Record
   ): DashboardResource.DashboardClickableFileEntry = {
+    val workflow = record.into(WORKFLOW).into(classOf[Workflow])
+    // The select lists specific columns, so the POJO built from the record 
does not carry this one.
+    // Without it the listing forgets the default-view preference on every 
refresh.
+    workflow.setDefaultView(record.get("workflow_default_view", 
classOf[DefaultViewEnum]))
+
+    // A viewer here only because the workflow is public sees the pinned name 
and description, the
+    // same copy the detail page serves -- otherwise a listing would advertise 
a title that opening it
+    // does not show. Both are NULL while following, which leaves the live 
values in place.
+    // Unknown counts as not granted: the reverse is the leak.
+    val granted = Option(record.get("viewer_has_granted_access", 
classOf[java.lang.Boolean]))
+      .exists(_.booleanValue())
+    if (!granted) {
+      Option(record.get("workflow_published_name", 
classOf[String])).foreach(workflow.setName)
+      Option(record.get("workflow_published_description", classOf[String]))
+        .foreach(workflow.setDescription)
+      Option(record.get("workflow_published_default_view", 
classOf[DefaultViewEnum]))
+        .foreach(workflow.setDefaultView)
+    }
+
     val dw = DashboardWorkflow(
       record.into(WORKFLOW_OF_USER).getUid == uid,
       Option(record.get(WORKFLOW_USER_ACCESS.PRIVILEGE, 
classOf[PrivilegeEnum]))
         .map(_.toString)
         .getOrElse(PrivilegeEnum.NONE.toString),
-      record.into(USER).getName, {
-        // The select lists specific columns, so the POJO built from the 
record does not carry
-        // this one. Without it the listing forgets the default-view 
preference on every refresh.
-        val w = record.into(WORKFLOW).into(classOf[Workflow])
-        w.setDefaultView(record.get("workflow_default_view", 
classOf[DefaultViewEnum]))
-        w
-      },
+      record.into(USER).getName,
+      workflow,
       record.into(USER).getUid,
-      Option(record.get("workflow_cover_image", classOf[String]))
+      Option(record.get("workflow_cover_image", classOf[String])),
+      // Null for the resource types that do not define the column at all.
+      Option(record.get("workflow_has_unpublished_changes", 
classOf[java.lang.Boolean]))
+        .exists(_.booleanValue())
     )
     DashboardClickableFileEntry(SearchQueryBuilder.WORKFLOW_RESOURCE_TYPE, 
workflow = Some(dw))
   }
diff --git 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/hub/HubResource.scala
 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/hub/HubResource.scala
index 973f41882a..b0028eeccb 100644
--- 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/hub/HubResource.scala
+++ 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/hub/HubResource.scala
@@ -30,6 +30,7 @@ import 
org.apache.texera.web.resource.dashboard.VersionedResourceTables
 import org.apache.texera.web.resource.dashboard.hub.ActionType.{Clone, Like, 
Unlike, View}
 import org.apache.texera.web.resource.dashboard.hub.EntityTables._
 import org.apache.texera.web.resource.dashboard.hub.HubResource._
+import 
org.apache.texera.web.resource.dashboard.user.workflow.WorkflowPublishService
 import 
org.apache.texera.web.resource.dashboard.user.workflow.WorkflowResource.{
   DashboardWorkflow,
   baseWorkflowSelect,
@@ -273,7 +274,26 @@ object HubResource {
       )
       .fetch()
 
-    mapWorkflowEntries(records, uid)
+    // The hub is the public shelf, so everything on it is listed as the 
public sees it: while a pin
+    // is in place, under the name and description frozen with it rather than 
the author's live ones
+    // -- for the author too, who is looking at the shelf and not at their own 
dashboard.
+    val entries = mapWorkflowEntries(records, uid)
+    val pinned = 
WorkflowPublishService.pinnedListingsOf(entries.map(_.workflow.getWid))
+    entries.map { entry =>
+      pinned.get(entry.workflow.getWid) match {
+        case None => entry
+        case Some(listing) =>
+          entry.workflow.setName(listing.name)
+          entry.workflow.setDescription(listing.description)
+          // The view too: a hub card that opened the frozen copy in the 
author's live view would
+          // offer a Form View over a graph carrying no form.
+          entry.workflow.setDefaultView(listing.defaultView)
+          // Carried like the search listing carries it: a card advertising 
the pinned copy has to
+          // open that copy, and without this flag the author's own card would 
open their editor and
+          // show them something else.
+          entry.copy(hasUnpublishedChanges = listing.hasUnpublishedChanges)
+      }
+    }
   }
 
   /** The access join is narrowed to `uid`, so each id yields one row carrying 
only the viewer's grant. */
diff --git 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowPublishService.scala
 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowPublishService.scala
index 9d6a208fcd..62d15fde23 100644
--- 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowPublishService.scala
+++ 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowPublishService.scala
@@ -26,9 +26,10 @@ import org.apache.texera.dao.jooq.generated.Tables.WORKFLOW
 import org.apache.texera.dao.jooq.generated.enums.DefaultViewEnum
 import org.apache.texera.dao.jooq.generated.tables.daos.WorkflowDao
 import org.apache.texera.dao.jooq.generated.tables.pojos.Workflow
-import org.jooq.DSLContext
+import org.jooq.{Condition, DSLContext}
 
 import javax.ws.rs.{BadRequestException, NotFoundException}
+import scala.jdk.CollectionConverters.CollectionHasAsScala
 import scala.util.Try
 
 /**
@@ -248,6 +249,64 @@ object WorkflowPublishService extends LazyLogging {
       workflow.getDefaultView
     )
 
+  /**
+    * [[differs]] as a condition, for the listings that ask about many 
workflows at once: the same
+    * fields, so a card and the share dialog can never disagree about whether 
edits are held back.
+    * Only meaningful on a row that is pinned -- while following, every frozen 
column is NULL and
+    * `isDistinctFrom` would read that as drift.
+    */
+  val pinDiffersFromWorkingCopy: Condition =
+    WORKFLOW.PUBLISHED_CONTENT
+      .isDistinctFrom(WORKFLOW.CONTENT)
+      .or(WORKFLOW.PUBLISHED_NAME.isDistinctFrom(WORKFLOW.NAME))
+      .or(WORKFLOW.PUBLISHED_DESCRIPTION.isDistinctFrom(WORKFLOW.DESCRIPTION))
+      
.or(WORKFLOW.PUBLISHED_DEFAULT_VIEW.isDistinctFrom(WORKFLOW.DEFAULT_VIEW))
+
+  /**
+    * What a listing needs about one pinned workflow: the frozen name and 
description it must show
+    * instead of the author's live ones, and whether those live ones have 
moved on.
+    */
+  case class PinnedListing(
+      name: String,
+      description: String,
+      defaultView: DefaultViewEnum,
+      hasUnpublishedChanges: Boolean
+  )
+
+  /**
+    * The pinned listings among `wids`, keyed by wid. A workflow that follows 
the author's latest is
+    * simply absent, which leaves its live values in place and its drift flag 
false.
+    *
+    * Drift is decided in SQL here rather than by [[differs]], because a 
listing asks about many
+    * workflows at once and none of their contents are worth shipping back to 
compare in memory.
+    */
+  def pinnedListingsOf(wids: Seq[Integer]): Map[Integer, PinnedListing] =
+    if (wids.isEmpty) Map()
+    else {
+      val drifted = pinDiffersFromWorkingCopy
+      context
+        .select(
+          WORKFLOW.WID,
+          WORKFLOW.PUBLISHED_NAME,
+          WORKFLOW.PUBLISHED_DESCRIPTION,
+          WORKFLOW.PUBLISHED_DEFAULT_VIEW,
+          drifted
+        )
+        .from(WORKFLOW)
+        .where(WORKFLOW.WID.in(wids: 
_*).and(WORKFLOW.PUBLISHED_CONTENT.isNotNull))
+        .fetch()
+        .asScala
+        .map(row =>
+          row.get(WORKFLOW.WID) -> PinnedListing(
+            row.get(WORKFLOW.PUBLISHED_NAME),
+            row.get(WORKFLOW.PUBLISHED_DESCRIPTION),
+            row.get(WORKFLOW.PUBLISHED_DEFAULT_VIEW),
+            row.get(drifted)
+          )
+        )
+        .toMap
+    }
+
   /** As [[publicCopyOf]], for callers holding only a wid. 404s unless the 
workflow is public. */
   def publicCopyOf(wid: Integer): PublicCopy = {
     val workflow = requireWorkflow(wid)
diff --git 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowResource.scala
 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowResource.scala
index 8625f16eb2..7b0a0f285f 100644
--- 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowResource.scala
+++ 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowResource.scala
@@ -122,7 +122,10 @@ object WorkflowResource {
       ownerName: String,
       workflow: Workflow,
       ownerId: Integer,
-      coverImage: Option[String]
+      coverImage: Option[String],
+      // Behind the author's working copy? Listings use it to open the 
published preview instead of
+      // the editor -- for the author too, since that is what the entry is 
showing.
+      hasUnpublishedChanges: Boolean = false
   )
 
   case class WorkflowWithPrivilege(
diff --git 
a/amber/src/test/scala/org/apache/texera/web/resource/dashboard/UnifiedResourceSchemaSpec.scala
 
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/UnifiedResourceSchemaSpec.scala
index 2785659579..72c4d9eade 100644
--- 
a/amber/src/test/scala/org/apache/texera/web/resource/dashboard/UnifiedResourceSchemaSpec.scala
+++ 
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/UnifiedResourceSchemaSpec.scala
@@ -79,9 +79,10 @@ class UnifiedResourceSchemaSpec extends AnyFlatSpec with 
Matchers {
 
   // Sentinels for the two slots that have no convenient distinct table
   // column of the right type; every other slot uses a real generated column so
-  // that all 23 originals render differently from one another.
+  // that all 28 originals render differently from one another.
   private val sentinelResourceType: Field[String] = 
JDSL.inline("s-resource-type")
   private val sentinelStoragePath: Field[String] = 
JDSL.inline("s-storage-path")
+  private val sentinelGranted: Field[java.lang.Boolean] = 
JDSL.inline(java.lang.Boolean.TRUE)
 
   private val sentinelSchema: UnifiedResourceSchema = UnifiedResourceSchema(
     resourceType = sentinelResourceType,
@@ -106,7 +107,12 @@ class UnifiedResourceSchemaSpec extends AnyFlatSpec with 
Matchers {
     workflowCoverImage = WORKFLOW_COVER_IMAGE.IMAGE,
     workflowDefaultView = WORKFLOW.DEFAULT_VIEW,
     modelFramework = MODEL.FRAMEWORK,
-    modelFormat = MODEL.FORMAT
+    modelFormat = MODEL.FORMAT,
+    workflowHasUnpublishedChanges = WORKFLOW.IS_PUBLIC,
+    workflowPublishedName = WORKFLOW.PUBLISHED_NAME,
+    workflowPublishedDescription = WORKFLOW.PUBLISHED_DESCRIPTION,
+    workflowPublishedDefaultView = WORKFLOW.PUBLISHED_DEFAULT_VIEW,
+    viewerHasGrantedAccess = sentinelGranted
   )
 
   // Expected projection, in order: alias -> the original it must be built 
from.
@@ -133,13 +139,18 @@ class UnifiedResourceSchemaSpec extends AnyFlatSpec with 
Matchers {
     "workflow_cover_image" -> WORKFLOW_COVER_IMAGE.IMAGE,
     "workflow_default_view" -> WORKFLOW.DEFAULT_VIEW,
     "model_framework" -> MODEL.FRAMEWORK,
-    "model_format" -> MODEL.FORMAT
+    "model_format" -> MODEL.FORMAT,
+    "workflow_has_unpublished_changes" -> WORKFLOW.IS_PUBLIC,
+    "workflow_published_name" -> WORKFLOW.PUBLISHED_NAME,
+    "workflow_published_description" -> WORKFLOW.PUBLISHED_DESCRIPTION,
+    "workflow_published_default_view" -> WORKFLOW.PUBLISHED_DEFAULT_VIEW,
+    "viewer_has_granted_access" -> sentinelGranted
   )
 
   // -- apply(): the projection 
------------------------------------------------
 
-  "apply" should "expose all 23 slots as aliases, in the order the UNION ALL 
depends on" in {
-    sentinelSchema.allFields should have size 23
+  "apply" should "expose all 28 slots as aliases, in the order the UNION ALL 
depends on" in {
+    sentinelSchema.allFields should have size 28
     sentinelSchema.allFields.map(_.getName) shouldBe 
expectedProjection.map(_._1)
   }
 
@@ -159,7 +170,7 @@ class UnifiedResourceSchemaSpec extends AnyFlatSpec with 
Matchers {
     // about datasets still union with one that does: the column count and
     // types have to line up.
     val defaults = UnifiedResourceSchema()
-    defaults.allFields should have size 23
+    defaults.allFields should have size 28
     val rendered = ctx.renderInlined(JDSL.select(defaults.allFields: _*))
     rendered should include("'' as \"resourceType\"")
     rendered should include("cast(null as timestamp) as 
\"resourceCreationTime\"")
@@ -194,12 +205,12 @@ class UnifiedResourceSchemaSpec extends AnyFlatSpec with 
Matchers {
   }
 
   it should "collapse the all-defaults projection down to one alias per 
distinct default" in {
-    // 23 slots, but only seven structurally distinct default expressions, so 
the
+    // 28 slots, but only seven structurally distinct default expressions, so 
the
     // de-dup collapses the map to seven entries. Worth pinning because it is
     // surprising, and because it is what makes the keep-first rule observable 
at
-    // all: allFields stays at 23 while the translation map does not.
+    // all: allFields stays at 28 while the translation map does not.
     val defaults = UnifiedResourceSchema()
-    defaults.allFields should have size 23
+    defaults.allFields should have size 28
     translatedAliases(defaults) shouldBe Seq(
       "resourceType", // DSL.inline("")
       "resourceCreationTime", // cast(null as timestamp)
@@ -211,7 +222,7 @@ class UnifiedResourceSchemaSpec extends AnyFlatSpec with 
Matchers {
     )
   }
 
-  it should "keep every distinct original when the caller supplies 23 distinct 
Fields" in {
+  it should "keep every distinct original when the caller supplies 28 distinct 
Fields" in {
     // Nothing to collapse here, which is the control case for the two tests
     // above: the shrinkage they observe comes from duplicate originals only.
     translatedAliases(sentinelSchema) shouldBe expectedProjection.map(_._1)
@@ -219,7 +230,7 @@ class UnifiedResourceSchemaSpec extends AnyFlatSpec with 
Matchers {
 
   it should "drop exactly the duplicated slots of the production workflow 
projection" in {
     val workflowSchema = WorkflowSearchQueryBuilder.mappedResourceSchema
-    workflowSchema.allFields should have size 23
+    workflowSchema.allFields should have size 28
     val aliases = translatedAliases(workflowSchema)
     // `uid` duplicates ownerId (WORKFLOW_OF_USER.UID); the rest are slots the
     // builder left at their default, and the defaults collide by type.
@@ -238,7 +249,7 @@ class UnifiedResourceSchemaSpec extends AnyFlatSpec with 
Matchers {
 
   "jOOQ Field equality" should "be structural, which is what makes the de-dup 
collapse anything" in {
     // If jOOQ ever switched to identity equality, translatedFieldSet would 
keep
-    // all 23 slots and translateRecord would start reading duplicated columns 
—
+    // all 28 slots and translateRecord would start reading duplicated columns 
—
     // the tests above would flip, and this one says why.
     JDSL.cast(null, classOf[Integer]) shouldBe JDSL.cast(null, 
classOf[Integer])
     JDSL.inline("") shouldBe JDSL.inline("")
diff --git 
a/amber/src/test/scala/org/apache/texera/web/resource/dashboard/WorkflowSearchQueryBuilderSpec.scala
 
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/WorkflowSearchQueryBuilderSpec.scala
index f0d8fc63d9..4b6a8a8937 100644
--- 
a/amber/src/test/scala/org/apache/texera/web/resource/dashboard/WorkflowSearchQueryBuilderSpec.scala
+++ 
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/WorkflowSearchQueryBuilderSpec.scala
@@ -62,6 +62,15 @@ class WorkflowSearchQueryBuilderSpec extends AnyFlatSpec 
with Matchers {
   // The select lists default_view under its own alias (not carried by the 
WORKFLOW POJO),
   // and toEntryImpl reads it back by that alias — the record has to carry the 
column.
   private val defaultViewField = 
WORKFLOW.DEFAULT_VIEW.as("workflow_default_view")
+  private val driftField =
+    JDSL.field(JDSL.name("workflow_has_unpublished_changes"), 
classOf[java.lang.Boolean])
+  private val publishedNameField = 
JDSL.field(JDSL.name("workflow_published_name"), classOf[String])
+  private val publishedDefaultViewField =
+    WORKFLOW.PUBLISHED_DEFAULT_VIEW.as("workflow_published_default_view")
+  private val publishedDescriptionField =
+    JDSL.field(JDSL.name("workflow_published_description"), classOf[String])
+  private val grantedField =
+    JDSL.field(JDSL.name("viewer_has_granted_access"), 
classOf[java.lang.Boolean])
 
   private val ownerUid: Integer = Integer.valueOf(42)
   private val viewerUid: Integer = Integer.valueOf(43)
@@ -79,7 +88,14 @@ class WorkflowSearchQueryBuilderSpec extends AnyFlatSpec 
with Matchers {
       uidValue: Integer = ownerUid,
       privilege: PrivilegeEnum = PrivilegeEnum.WRITE,
       cover: String = "cover-b64",
-      defaultView: DefaultViewEnum = DefaultViewEnum.CANVAS
+      defaultView: DefaultViewEnum = DefaultViewEnum.CANVAS,
+      hasUnpublishedChanges: java.lang.Boolean = null,
+      // The rows these tests describe belong to a viewer who was granted 
access, which is what
+      // leaves the author's own name and description in place.
+      grantedAccess: java.lang.Boolean = java.lang.Boolean.TRUE,
+      publishedName: String = null,
+      publishedDescription: String = null,
+      publishedDefaultView: DefaultViewEnum = null
   ): Record = {
     val record = ctx.newRecord(
       WORKFLOW.WID,
@@ -89,7 +105,12 @@ class WorkflowSearchQueryBuilderSpec extends AnyFlatSpec 
with Matchers {
       WORKFLOW_USER_ACCESS.PRIVILEGE,
       USER.NAME,
       coverField,
-      defaultViewField
+      defaultViewField,
+      driftField,
+      publishedNameField,
+      publishedDescriptionField,
+      publishedDefaultViewField,
+      grantedField
     )
     record.set(WORKFLOW.WID, wid)
     record.set(WORKFLOW.NAME, "wf-name")
@@ -99,12 +120,75 @@ class WorkflowSearchQueryBuilderSpec extends AnyFlatSpec 
with Matchers {
     record.set(USER.NAME, "owner-name")
     record.set(coverField, cover)
     record.set(defaultViewField, defaultView)
+    record.set(driftField, hasUnpublishedChanges)
+    record.set(publishedNameField, publishedName)
+    record.set(publishedDescriptionField, publishedDescription)
+    record.set(publishedDefaultViewField, publishedDefaultView)
+    record.set(grantedField, grantedAccess)
     record
   }
 
   private def workflowOf(record: Record, uid: Integer): DashboardWorkflow =
     WorkflowSearchQueryBuilder.toEntryImpl(uid, record).workflow.get
 
+  // -- what a viewer without granted access is shown 
--------------------------
+
+  "toEntryImpl" should "serve the published name and description to a viewer 
without granted access" in {
+    // Publishing pins what the public sees, and a listing is where the public 
meets a workflow, so
+    // the listing has to serve the pinned copy too rather than the author's 
live metadata.
+    val record = translatedRecord(
+      grantedAccess = java.lang.Boolean.FALSE,
+      publishedName = "as-published",
+      publishedDescription = "described-as-published"
+    )
+
+    val workflow = workflowOf(record, viewerUid).workflow
+
+    workflow.getName shouldBe "as-published"
+    workflow.getDescription shouldBe "described-as-published"
+  }
+
+  it should "serve the pinned view to a viewer without granted access" in {
+    // A card that opened the frozen copy in the author's live view would 
offer a Form View over a
+    // graph that carries no form; the view travels with the name and the 
description.
+    val record = translatedRecord(
+      grantedAccess = java.lang.Boolean.FALSE,
+      defaultView = DefaultViewEnum.FORM,
+      publishedName = "as-published",
+      publishedDefaultView = DefaultViewEnum.CANVAS
+    )
+
+    workflowOf(record, viewerUid).workflow.getDefaultView shouldBe 
DefaultViewEnum.CANVAS
+  }
+
+  it should "leave the author's live name and description for a viewer who was 
granted access" in {
+    val record = translatedRecord(
+      grantedAccess = java.lang.Boolean.TRUE,
+      publishedName = "as-published",
+      publishedDescription = "described-as-published"
+    )
+
+    val workflow = workflowOf(record, ownerUid).workflow
+
+    workflow.getName shouldBe "wf-name"
+    workflow.getDescription shouldBe "wf-description"
+  }
+
+  it should "treat an unknown access answer as public, which is the safe 
direction" in {
+    // Showing the published copy to someone who turns out to have access is 
harmless; the reverse
+    // would hand the author's live metadata to the public.
+    val record = translatedRecord(grantedAccess = null, publishedName = 
"as-published")
+
+    workflowOf(record, viewerUid).workflow.getName shouldBe "as-published"
+  }
+
+  it should "keep the author's name when a public workflow has nothing pinned" 
in {
+    // Nothing to substitute, so the row is left as it is rather than blanked.
+    val record = translatedRecord(grantedAccess = java.lang.Boolean.FALSE, 
publishedName = null)
+
+    workflowOf(record, viewerUid).workflow.getName shouldBe "wf-name"
+  }
+
   // -- privilege fallback 
-----------------------------------------------------
 
   "toEntryImpl" should "fall back to NONE when the workflow privilege is NULL" 
in {
diff --git 
a/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowPublishSpec.scala
 
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowPublishSpec.scala
index 73306d84e3..23b3a5bafe 100644
--- 
a/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowPublishSpec.scala
+++ 
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowPublishSpec.scala
@@ -29,7 +29,10 @@ import org.apache.texera.dao.jooq.generated.tables.daos.{
   WorkflowUserAccessDao
 }
 import org.apache.texera.dao.jooq.generated.tables.pojos.{User, Workflow, 
WorkflowUserAccess}
+import 
org.apache.texera.web.resource.dashboard.DashboardResource.SearchQueryParams
+import org.apache.texera.web.resource.dashboard.hub.HubResource
 import 
org.apache.texera.web.resource.dashboard.user.workflow.WorkflowResource.WorkflowIDs
+import org.apache.texera.web.resource.dashboard.{DashboardResource, 
FulltextSearchQueryUtils}
 import org.scalatest.BeforeAndAfterAll
 import org.scalatest.flatspec.AnyFlatSpec
 import org.scalatest.matchers.should.Matchers
@@ -45,7 +48,7 @@ import javax.ws.rs.{BadRequestException, ForbiddenException, 
NotFoundException}
 /**
   * Covers the publish state a workflow can be in -- following the author's 
latest content, as
   * publishing has always done, or holding a pinned copy of the version the 
author froze -- and the
-  * read paths that decide which of the two a caller is served.
+  * read paths that decide which of the two a caller is served, listings and 
search among them.
   */
 class WorkflowPublishSpec
     extends AnyFlatSpec
@@ -85,6 +88,7 @@ class WorkflowPublishSpec
 
   override protected def beforeAll(): Unit = {
     initializeDBAndReplaceDSLContext()
+    FulltextSearchQueryUtils.usePgroonga = false
     val userDao = new UserDao(getDSLContext.configuration())
     userDao.insert(owner)
     userDao.insert(stranger)
@@ -168,6 +172,40 @@ class WorkflowPublishSpec
       )
       .asInstanceOf[HttpServletRequest]
 
+  private def keywords(values: String*): util.ArrayList[String] = {
+    val list = new util.ArrayList[String]()
+    values.foreach(list.add)
+    list
+  }
+
+  private def keywordIds(values: Integer*): util.ArrayList[Integer] = {
+    val list = new util.ArrayList[Integer]()
+    values.foreach(list.add)
+    list
+  }
+
+  /** The wids a search returns, which is all any of these tests asks of one. 
*/
+  private def searchWids(user: SessionUser, params: SearchQueryParams): 
List[Integer] =
+    DashboardResource
+      .searchAllResources(user, params, includePublic = true)
+      .results
+      .flatMap(_.workflow.map(_.workflow.getWid))
+
+  /** One workflow's listing row, as the given user would see it in a 
dashboard or on the Hub. */
+  private def listingOf(user: SessionUser, wid: Integer) =
+    DashboardResource
+      .searchAllResources(
+        user,
+        SearchQueryParams(workflowIDs = keywordIds(wid)),
+        includePublic = true
+      )
+      .results
+      .flatMap(_.workflow)
+      .head
+
+  /** Nobody: the hub as an unauthenticated visitor reads it. */
+  private def anonymous: SessionUser = new SessionUser(new User())
+
   private def statusOf(wid: Integer): WorkflowPublishService.PublishStatus =
     workflowResource.getPublishStatus(wid, ownerSession)
 
@@ -945,4 +983,272 @@ class WorkflowPublishSpec
       .getSize(util.Arrays.asList(pinned))
       .get(pinned) shouldBe publishedContent.length
   }
+
+  behavior of "hub listings"
+
+  it should "list a pinned workflow on the hub under the name and description 
it froze" in {
+    // The hub is the public shelf: everything on it is listed as the public 
sees it, the author
+    // included. A pin that this listing did not honour would put the author's 
live title on that
+    // shelf, and would leave it disagreeing with the hub's own search about 
what a workflow is
+    // called.
+    val wid = createWorkflow("hub_listing_shows_public_copy")
+    publishPinned(wid)
+    relabel(wid, "renamed_after_pinning", "described_after_pinning")
+
+    for (viewer <- Seq(stranger.getUid, owner.getUid)) {
+      val listed = HubResource.fetchDashboardWorkflowsByWids(Seq(wid), 
viewer).head.workflow
+      listed.getName shouldBe "hub_listing_shows_public_copy"
+      listed.getDescription shouldBe "a workflow"
+    }
+  }
+
+  it should "list a following workflow on the hub under the author's latest 
name and description" in {
+    val wid = createWorkflow("hub_listing_follows_latest")
+    workflowResource.makePublic(wid, ownerSession)
+    relabel(wid, "renamed_while_following", "described_while_following")
+
+    val listed = HubResource.fetchDashboardWorkflowsByWids(Seq(wid), 
owner.getUid).head.workflow
+    listed.getName shouldBe "renamed_while_following"
+    listed.getDescription shouldBe "described_while_following"
+  }
+
+  it should "tell the hub listing when the copy on show is behind the author's 
working copy" in {
+    // The card advertises the pinned copy, so clicking it has to open that 
copy. Without this flag
+    // the author's own card would take them to their editor and show them 
something else -- the
+    // same signal the search listing carries, on the query the hub builds for 
itself.
+    val wid = createWorkflow("hub_listing_reports_drift")
+    publishPinned(wid)
+
+    def listedDrift(): Boolean =
+      HubResource.fetchDashboardWorkflowsByWids(Seq(wid), 
owner.getUid).head.hasUnpublishedChanges
+
+    listedDrift() shouldBe false
+    edit(wid, editedContent)
+    listedDrift() shouldBe true
+    workflowResource.pinLatest(wid, ownerSession)
+    listedDrift() shouldBe false
+  }
+
+  it should "clone the author's latest name and description while nothing is 
pinned" in {
+    val wid = createWorkflow("clone_follows_latest_metadata")
+    workflowResource.makePublic(wid, ownerSession)
+    relabel(wid, "renamed_before_clone", "described_before_clone")
+
+    val cloned =
+      workflowDao.fetchOneByWid(workflowResource.cloneWorkflow(wid, 
strangerSession, fakeRequest()))
+
+    cloned.getName shouldBe "renamed_before_clone_clone"
+    cloned.getDescription shouldBe "described_before_clone"
+  }
+
+  behavior of "search"
+
+  it should "not match a public workflow on anything that exists only in 
unpublished edits" in {
+    // Both halves of what public search indexes -- the words in the graph, 
and the operators in it --
+    // have to stop at the pinned copy, or searching would surface drafts 
nobody can open.
+    val wid = createWorkflow("search_ignores_drafts")
+    publishPinned(wid)
+    edit(
+      wid,
+      
"""{"operators":[{"operatorType":"SecretDraftOperator"}],"note":"supersecretdraftword"}"""
+    )
+
+    val byKeyword =
+      searchWids(anonymous, SearchQueryParams(keywords = 
keywords("supersecretdraftword")))
+    val byOperator =
+      searchWids(anonymous, SearchQueryParams(operators = 
keywords("SecretDraftOperator")))
+
+    byKeyword should not contain wid
+    byOperator should not contain wid
+  }
+
+  it should "match a public workflow on keywords in its published copy" in {
+    val wid = createWorkflow("search_finds_published")
+    publishPinned(wid)
+    edit(wid, editedContent)
+
+    searchWids(
+      anonymous,
+      SearchQueryParams(keywords = keywords("content_as_published"))
+    ) should contain(wid)
+  }
+
+  it should "match an unpinned public workflow on the author's latest" in {
+    // Following means the public copy is the working copy, so search must 
reach it through the same
+    // public path that a pinned workflow reaches its frozen copy through.
+    val wid = createWorkflow("search_finds_unpinned_latest")
+    workflowResource.makePublic(wid, ownerSession)
+    edit(wid, """{"operators":[],"note":"unpinnedsearchword"}""")
+
+    searchWids(
+      anonymous,
+      SearchQueryParams(keywords = keywords("unpinnedsearchword"))
+    ) should contain(wid)
+  }
+
+  it should "still match the author's own workflow on their unpublished edits" 
in {
+    val wid = createWorkflow("search_finds_own_draft")
+    publishPinned(wid)
+    edit(wid, """{"operators":[],"note":"myowndraftword"}""")
+
+    searchWids(
+      ownerSession,
+      SearchQueryParams(keywords = keywords("myowndraftword"))
+    ) should contain(wid)
+  }
+
+  it should "match a pinned workflow on the name and description the public 
can see" in {
+    // The graph was already matched against the pinned copy; the title and 
description are on public
+    // show just as much, so matching them against the author's live values 
gets it wrong in both
+    // directions at once -- findable by a title nobody has seen, unfindable 
by the one on screen.
+    val wid = createWorkflow("aapublicnamesearch")
+    relabel(wid, "aapublicnamesearch", "aapublicdescriptionsearch")
+    publishPinned(wid)
+    relabel(wid, "zzsecretnamesearch", "zzsecretdescriptionsearch")
+
+    def anonymousHits(word: String): List[Integer] =
+      searchWids(anonymous, SearchQueryParams(keywords = keywords(word)))
+
+    anonymousHits("aapublicnamesearch") should contain(wid)
+    anonymousHits("aapublicdescriptionsearch") should contain(wid)
+    anonymousHits("zzsecretnamesearch") should not contain wid
+    anonymousHits("zzsecretdescriptionsearch") should not contain wid
+  }
+
+  it should "match an unpinned public workflow on its live name and 
description" in {
+    val wid = createWorkflow("bbfollowingnamesearch")
+    workflowResource.makePublic(wid, ownerSession)
+    relabel(wid, "bbrenamedwhilefollowing", "a workflow")
+
+    searchWids(
+      anonymous,
+      SearchQueryParams(keywords = keywords("bbrenamedwhilefollowing"))
+    ) should contain(wid)
+  }
+
+  it should "still match the author's own workflow on a name only they can 
see" in {
+    val wid = createWorkflow("ccownnamesearch")
+    publishPinned(wid)
+    relabel(wid, "ccprivaterenamesearch", "a workflow")
+
+    searchWids(
+      ownerSession,
+      SearchQueryParams(keywords = keywords("ccprivaterenamesearch"))
+    ) should contain(wid)
+  }
+
+  it should "show a public viewer the published name and description in a 
listing" in {
+    // The listing is where people find and click a workflow, so a title that 
keeps following the
+    // author defeats the freeze exactly as an unfrozen graph would: a report 
about a title could be
+    // answered by quietly editing the title.
+    val wid = createWorkflow("listing_name_before")
+    publishPinned(wid)
+    relabel(wid, "listing_name_after", "described after publishing")
+
+    def listedAs(session: SessionUser): (String, String) = {
+      val entry = listingOf(session, wid).workflow
+      (entry.getName, entry.getDescription)
+    }
+
+    // The author is not a public viewer of their own workflow.
+    listedAs(ownerSession) shouldBe ("listing_name_after", "described after 
publishing")
+    // A stranger reaches it only because it is public.
+    listedAs(strangerSession) shouldBe ("listing_name_before", "a workflow")
+    // ...and the listing now agrees with what opening it shows.
+    workflowResource.retrievePublicWorkflow(wid).name shouldBe 
"listing_name_before"
+  }
+
+  it should "show a public viewer the author's live name while nothing is 
pinned" in {
+    val wid = createWorkflow("listing_unpinned_before")
+    workflowResource.makePublic(wid, ownerSession)
+    relabel(wid, "listing_unpinned_after", "a workflow")
+
+    listingOf(strangerSession, wid).workflow.getName shouldBe 
"listing_unpinned_after"
+  }
+
+  it should "show a public viewer the view the copy on show opens in" in {
+    // The Form View's definition rides inside the content, so a card offering 
a form over a frozen
+    // canvas would open a form the copy does not carry. The view travels with 
the name and the
+    // description, and for the author's own row it stays theirs.
+    val wid = createWorkflow("listing_freezes_the_view")
+    publishPinned(wid)
+    getDSLContext
+      .update(WORKFLOW)
+      .set(WORKFLOW.DEFAULT_VIEW, DefaultViewEnum.FORM)
+      .where(WORKFLOW.WID.eq(wid))
+      .execute()
+
+    listingOf(strangerSession, wid).workflow.getDefaultView shouldBe 
DefaultViewEnum.CANVAS
+    listingOf(ownerSession, wid).workflow.getDefaultView shouldBe 
DefaultViewEnum.FORM
+  }
+
+  it should "show a collaborator the author's live name in a listing" in {
+    val wid = createWorkflow("listing_for_collaborator")
+    publishPinned(wid)
+    grantAccess(wid, PrivilegeEnum.READ)
+
+    try {
+      relabel(wid, "renamed_after_sharing", "a workflow")
+      listingOf(strangerSession, wid).workflow.getName shouldBe 
"renamed_after_sharing"
+    } finally revokeAccess(wid)
+  }
+
+  it should "leave a private workflow's own listing untouched" in {
+    val wid = createWorkflow("listing_private")
+    relabel(wid, "private_renamed", "a workflow")
+
+    listingOf(ownerSession, wid).workflow.getName shouldBe "private_renamed"
+  }
+
+  it should "tell listings when the copy on show is behind the author's 
working copy" in {
+    // What sends the author to the published preview instead of their editor 
when they click their
+    // own workflow in the hub: the entry is advertising the pinned version, 
not what they are editing.
+    val wid = createWorkflow("listing_reports_drift")
+    publishPinned(wid)
+
+    def drifted(): Boolean = listingOf(ownerSession, wid).hasUnpublishedChanges
+
+    drifted() shouldBe false
+    edit(wid, editedContent)
+    drifted() shouldBe true
+    workflowResource.pinLatest(wid, ownerSession)
+    drifted() shouldBe false
+  }
+
+  it should "report the same drift to a listing as to the share dialog" in {
+    // Three places answer "is the public behind?": the share dialog in Scala, 
the search projection
+    // and the hub listing in SQL. A rename or a change of view exercises the 
fields most easily left
+    // out of one of them, and a card that disagrees with the dialog is a card 
the author distrusts.
+    val wid = createWorkflow("listing_matches_dialog")
+    publishPinned(wid)
+
+    relabel(wid, "renamed_after_pinning", "a workflow")
+    listingOf(ownerSession, wid).hasUnpublishedChanges shouldBe 
statusOf(wid).hasUnpublishedChanges
+    listingOf(ownerSession, wid).hasUnpublishedChanges shouldBe true
+
+    workflowResource.pinLatest(wid, ownerSession)
+    getDSLContext
+      .update(WORKFLOW)
+      .set(WORKFLOW.DEFAULT_VIEW, DefaultViewEnum.FORM)
+      .where(WORKFLOW.WID.eq(wid))
+      .execute()
+
+    listingOf(ownerSession, wid).hasUnpublishedChanges shouldBe 
statusOf(wid).hasUnpublishedChanges
+    listingOf(ownerSession, wid).hasUnpublishedChanges shouldBe true
+  }
+
+  it should "never report drift for a workflow with nothing frozen" in {
+    // Drift is "what the public sees is not what you have", so it can only be 
true of a workflow that
+    // has a frozen copy at all. Private and public-but-following both have 
none.
+    def driftOf(wid: Integer): Boolean = listingOf(ownerSession, 
wid).hasUnpublishedChanges
+
+    val priv = createWorkflow("listing_ignores_private")
+    edit(priv, editedContent)
+    driftOf(priv) shouldBe false
+
+    val following = createWorkflow("listing_ignores_unpinned")
+    workflowResource.makePublic(following, ownerSession)
+    edit(following, editedContent)
+    driftOf(following) shouldBe false
+  }
 }

Reply via email to