Skip to content

Commit

Permalink
Merge pull request #4426 from coralproject/fix/user-action-presence-r…
Browse files Browse the repository at this point in the history
…r-qa-archived

Fix reported states for archived, Q&A, and R&R stories when data cache is enabled
  • Loading branch information
kabeaty authored Dec 4, 2023
2 parents 64b978a + cfaa294 commit d87e620
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/src/core/client/admin/permissions/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const permissionMap: PermissionMap<AbilityType, PermissionContext> = {
[GQLUSER_ROLE.MODERATOR]: () => true,
},
ARCHIVE_STORY: {
[GQLUSER_ROLE.ADMIN]: () => false,
[GQLUSER_ROLE.ADMIN]: () => true,
},
};

Expand Down
8 changes: 6 additions & 2 deletions server/src/core/server/graph/loaders/Comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const tagFilter = (tag?: GQLTAG): CommentConnectionInput["filter"] => {
return {};
};

const isRatingsAndReviews = (
export const isRatingsAndReviews = (
tenant: Pick<Tenant, "featureFlags">,
story: Story
) => {
Expand All @@ -68,7 +68,7 @@ const isRatingsAndReviews = (
);
};

const isQA = (tenant: Pick<Tenant, "featureFlags">, story: Story) => {
export const isQA = (tenant: Pick<Tenant, "featureFlags">, story: Story) => {
return (
hasFeatureFlag(tenant, GQLFEATURE_FLAG.ENABLE_QA) &&
story.settings.mode === GQLSTORY_MODE.QA
Expand Down Expand Up @@ -173,6 +173,8 @@ const mapVisibleComment = (user?: Pick<User, "role">) => {
interface ActionPresenceArgs {
commentID: string;
isArchived: boolean;
isQA: boolean;
isRR: boolean;
}

/**
Expand Down Expand Up @@ -268,13 +270,15 @@ export default (ctx: GraphContext) => ({

const commentIDs = args.map((rd) => rd.commentID);
const hasArchivedData = args.some((rd) => rd.isArchived);
const hasRROrQA = args.some((rd) => rd.isQA || rd.isRR);

const result = await retrieveManyUserActionPresence(
ctx.mongo,
ctx.cache.commentActions,
ctx.tenant.id,
ctx.user.id,
commentIDs,
!(hasRROrQA || hasArchivedData),
hasArchivedData
);

Expand Down
3 changes: 3 additions & 0 deletions server/src/core/server/graph/resolvers/Comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from "coral-server/graph/schema/__generated__/types";

import GraphContext from "../context";
import { isQA, isRatingsAndReviews } from "../loaders/Comments";
import { setCacheHint } from "../setCacheHint";

export const maybeLoadOnlyID = async (
Expand Down Expand Up @@ -223,6 +224,8 @@ export const Comment: GQLCommentTypeResolver<comment.Comment> = {
return ctx.loaders.Comments.retrieveMyActionPresence.load({
commentID: c.id,
isArchived: !!story.isArchived,
isRR: isRatingsAndReviews(ctx.tenant, story),
isQA: isQA(ctx.tenant, story),
});
},

Expand Down
4 changes: 3 additions & 1 deletion server/src/core/server/models/action/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,13 @@ export async function retrieveManyUserActionPresence(
tenantID: string,
userID: string | null,
commentIDs: string[],
useCache = true,
isArchived = false
): Promise<GQLActionPresence[]> {
let actions: Readonly<CommentAction>[] = [];

const cacheAvailable = await commentActionsCache.available(tenantID);
const cacheAvailable =
useCache && (await commentActionsCache.available(tenantID));
if (cacheAvailable) {
const actionsFromCache = await commentActionsCache.findMany(
tenantID,
Expand Down

0 comments on commit d87e620

Please sign in to comment.