[CORL-159, CORL-160] Stream Config Tab (#2219)

* feat: Implement stream configuration tab

* feat: split profile & configure into separate bundles

* chore: better role logic

* fix+chore: add test cases, implement expectAndFail, refactor tests

* chore: add some comments

* chore: Update src/core/client/framework/lib/form/helpers.tsx

Co-Authored-By: cvle <vinh@wikiwi.io>

* feat: support new graphql mutations/schema

* fix: ci fixes

* fix: improvement to revision loading

* fix: updated some tests

* fix: adapt client to changes

* fix: remove obsolote isClosed in UpdateStory

* ci: increase no_output_timeout for build
This commit is contained in:
Kiwi
2019-03-18 22:07:52 +01:00
committed by GitHub
parent c738d9a355
commit 9eb5afbb2b
128 changed files with 2249 additions and 1081 deletions
@@ -5,16 +5,13 @@ import {
CommentBodyExceedsMaxLengthError,
CommentBodyTooShortError,
} from "talk-server/errors";
import { ModerationSettings } from "talk-server/models/settings";
import { Settings } from "talk-server/models/settings";
import {
IntermediateModerationPhase,
IntermediatePhaseResult,
} from "talk-server/services/comments/pipeline";
const testCharCount = (
settings: Partial<ModerationSettings>,
length: number
) => {
const testCharCount = (settings: Partial<Settings>, length: number) => {
if (settings.charCount && settings.charCount.enabled) {
if (!isNil(settings.charCount.min)) {
if (length < settings.charCount.min) {
@@ -1,11 +1,11 @@
import { CommentingDisabledError } from "talk-server/errors";
import { ModerationSettings } from "talk-server/models/settings";
import { Settings } from "talk-server/models/settings";
import {
IntermediateModerationPhase,
IntermediatePhaseResult,
} from "talk-server/services/comments/pipeline";
const testDisabledCommenting = (settings: Partial<ModerationSettings>) =>
const testDisabledCommenting = (settings: Partial<Settings>) =>
settings.disableCommenting && settings.disableCommenting.enabled;
export const commentingDisabled: IntermediateModerationPhase = ({
@@ -4,14 +4,14 @@ import {
} from "talk-server/graph/tenant/schema/__generated__/types";
import { ACTION_TYPE } from "talk-server/models/action/comment";
import { Comment } from "talk-server/models/comment";
import { ModerationSettings } from "talk-server/models/settings";
import { GlobalModerationSettings } from "talk-server/models/settings";
import {
IntermediateModerationPhase,
IntermediatePhaseResult,
} from "talk-server/services/comments/pipeline";
const testPremodLinksEnable = (
settings: Partial<ModerationSettings>,
settings: Partial<GlobalModerationSettings>,
comment: Pick<Comment, "metadata">
) =>
settings.premodLinksEnable && comment.metadata && comment.metadata.linkCount;
@@ -2,13 +2,13 @@ import {
GQLCOMMENT_STATUS,
GQLMODERATION_MODE,
} from "talk-server/graph/tenant/schema/__generated__/types";
import { ModerationSettings } from "talk-server/models/settings";
import { GlobalModerationSettings } from "talk-server/models/settings";
import {
IntermediateModerationPhase,
IntermediatePhaseResult,
} from "talk-server/services/comments/pipeline";
const testModerationMode = (settings: Partial<ModerationSettings>) =>
const testModerationMode = (settings: Partial<GlobalModerationSettings>) =>
settings.moderation === GQLMODERATION_MODE.PRE;
// This phase checks to see if the settings have premod enabled, if they do,
@@ -16,7 +16,9 @@ describe("storyClosed", () => {
storyClosed({
story: {} as ModerationPhaseContext["story"],
tenant: { autoCloseStream: true } as ModerationPhaseContext["tenant"],
tenant: {
closeCommenting: { auto: true },
} as ModerationPhaseContext["tenant"],
comment: {} as ModerationPhaseContext["comment"],
author: {} as ModerationPhaseContext["author"],
});
@@ -25,8 +27,10 @@ describe("storyClosed", () => {
storyClosed({
story: { createdAt: new Date() } as ModerationPhaseContext["story"],
tenant: {
autoCloseStream: true,
closedTimeout: -6000,
closeCommenting: {
auto: true,
timeout: -6000,
},
} as ModerationPhaseContext["tenant"],
comment: {} as ModerationPhaseContext["comment"],
author: {} as ModerationPhaseContext["author"],
@@ -44,7 +48,9 @@ describe("storyClosed", () => {
.plus(60000)
.toJSDate(),
} as ModerationPhaseContext["story"],
tenant: {} as ModerationPhaseContext["tenant"],
tenant: {
closeCommenting: { auto: true },
} as ModerationPhaseContext["tenant"],
comment: {} as ModerationPhaseContext["comment"],
author: {} as ModerationPhaseContext["author"],
})
@@ -53,7 +59,9 @@ describe("storyClosed", () => {
expect(
storyClosed({
story: {} as ModerationPhaseContext["story"],
tenant: {} as ModerationPhaseContext["tenant"],
tenant: {
closeCommenting: { auto: true },
} as ModerationPhaseContext["tenant"],
comment: {} as ModerationPhaseContext["comment"],
author: {} as ModerationPhaseContext["author"],
})
+30 -3
View File
@@ -22,11 +22,13 @@ import {
} from "talk-server/models/comment";
import {
calculateTotalCommentCount,
closeStory,
createStory,
CreateStoryInput,
findOrCreateStory,
FindOrCreateStoryInput,
mergeCommentStatusCount,
openStory,
removeStories,
removeStory,
retrieveManyStories,
@@ -36,6 +38,8 @@ import {
updateStoryActionCounts,
updateStoryCommentStatusCount,
UpdateStoryInput,
updateStorySettings,
UpdateStorySettingsInput,
} from "talk-server/models/story";
import { Tenant } from "talk-server/models/tenant";
import { ScraperQueue } from "talk-server/queue/tasks/scraper";
@@ -227,6 +231,24 @@ export async function update(
return updateStory(mongo, tenant.id, storyID, input);
}
export type UpdateStorySettings = UpdateStorySettingsInput;
export async function updateSettings(
mongo: Db,
tenant: Tenant,
storyID: string,
input: UpdateStorySettings
) {
return updateStorySettings(mongo, tenant.id, storyID, input);
}
export async function open(mongo: Db, tenant: Tenant, storyID: string) {
return openStory(mongo, tenant.id, storyID);
}
export async function close(mongo: Db, tenant: Tenant, storyID: string) {
return closeStory(mongo, tenant.id, storyID);
}
export async function merge(
mongo: Db,
@@ -339,7 +361,7 @@ export async function merge(
}
export function getStoryClosedAt(
tenant: Pick<Tenant, "autoCloseStream" | "closedTimeout">,
tenant: Pick<Tenant, "closeCommenting">,
story: Pick<Story, "closedAt" | "createdAt">
): Story["closedAt"] {
// Try to get the closedAt time from the story.
@@ -347,16 +369,21 @@ export function getStoryClosedAt(
return story.closedAt;
}
// Check to see if the story has been forced open again.
if (story.closedAt === false) {
return false;
}
// If the story hasn't already been closed, then check to see if the Tenant
// has the auto close stream enabled.
if (tenant.autoCloseStream && tenant.closedTimeout) {
if (tenant.closeCommenting.auto) {
// Auto-close stream has been enabled, convert the createdAt time into the
// closedAt time by adding the closedTimeout.
return (
DateTime.fromJSDate(story.createdAt)
// closedTimeout is in seconds, so multiply by 1000 to get
// milliseconds.
.plus(tenant.closedTimeout * 1000)
.plus(tenant.closeCommenting.timeout * 1000)
.toJSDate()
);
}