[next] Flag Improvements (#2114)

* fix: applied fix for reaction mutation

* fix: removed comment length flag

* feat: added additionalDetails field to flags

* feat: added other flag type
This commit is contained in:
Wyatt Johnson
2018-12-12 22:49:51 +01:00
committed by Kiwi
parent 8a64e6f62d
commit e134b4de04
10 changed files with 111 additions and 54 deletions
@@ -17,6 +17,13 @@ import {
removeDontAgree,
removeReaction,
} from "talk-server/services/comments/actions";
import { validateMaximumLength } from "./util";
/**
* MAX_ADDITIONAL_DETAILS_LENGTH defines the maximum length for the
* additionalDetails field.
*/
const MAX_ADDITIONAL_DETAILS_LENGTH = 500;
export const Comment = (ctx: TenantContext) => ({
create: ({
@@ -58,10 +65,16 @@ export const Comment = (ctx: TenantContext) => ({
createDontAgree: ({
commentID,
commentRevisionID,
additionalDetails,
}: GQLCreateCommentDontAgreeInput) =>
createDontAgree(ctx.mongo, ctx.redis, ctx.tenant, ctx.user!, {
commentID,
commentRevisionID,
// TODO: (wyattjoh) move this validation to the schema when bug is fixed: https://github.com/apollographql/graphql-tools/issues/842
additionalDetails: validateMaximumLength(
MAX_ADDITIONAL_DETAILS_LENGTH,
additionalDetails
),
}),
removeDontAgree: ({ commentID }: GQLRemoveCommentDontAgreeInput) =>
removeDontAgree(ctx.mongo, ctx.redis, ctx.tenant, ctx.user!, {
@@ -71,10 +84,16 @@ export const Comment = (ctx: TenantContext) => ({
commentID,
commentRevisionID,
reason,
additionalDetails,
}: GQLCreateCommentFlagInput) =>
createFlag(ctx.mongo, ctx.redis, ctx.tenant, ctx.user!, {
commentID,
commentRevisionID,
reason,
// TODO: (wyattjoh) move this validation to the schema when bug is fixed: https://github.com/apollographql/graphql-tools/issues/842
additionalDetails: validateMaximumLength(
MAX_ADDITIONAL_DETAILS_LENGTH,
additionalDetails
),
}),
});
@@ -0,0 +1,13 @@
import { validateMaximumLength } from "./util";
it("limits to maximum when string is provided", () => {
expect(() => validateMaximumLength(5, "123456")).toThrow();
});
it("limits to maximum when string is not provided", () => {
expect(validateMaximumLength(5)).toEqual(undefined);
});
it("returns the string when string is provided and is within the length allowances", () => {
expect(validateMaximumLength(5, "1234")).toEqual("1234");
});
@@ -0,0 +1,14 @@
/**
* validateMaximumLength will limit the value of an optional string to the
* specified amount, otherwise will throw an error.
*
* @param maxLength maximum length to limit a value to
* @param value the value that should be limited
*/
export function validateMaximumLength(maxLength: number, value?: string) {
if (value && value.length > maxLength) {
throw new Error(`Exceeded maximum length of ${maxLength} characters`);
}
return value;
}
@@ -46,6 +46,12 @@ enum COMMENT_FLAG_REPORTED_REASON {
spam.
"""
COMMENT_REPORTED_SPAM
"""
COMMENT_REPORTED_OTHER is used when a User reported a Comment that doesn't
fit into the other reported reasons.
"""
COMMENT_REPORTED_OTHER
}
"""
@@ -65,12 +71,6 @@ enum COMMENT_FLAG_DETECTED_REASON {
"""
COMMENT_DETECTED_SPAM
"""
COMMENT_DETECTED_BODY_COUNT is used when the Comment was detected as exceeding
the body length by the system.
"""
COMMENT_DETECTED_BODY_COUNT
"""
COMMENT_DETECTED_TRUST is used when the Comment being left was done by a User
that has a low karma/trust score.
@@ -103,9 +103,9 @@ and COMMENT_FLAG_DETECTED_REASON types.
enum COMMENT_FLAG_REASON {
COMMENT_REPORTED_OFFENSIVE
COMMENT_REPORTED_SPAM
COMMENT_REPORTED_OTHER
COMMENT_DETECTED_TOXIC
COMMENT_DETECTED_SPAM
COMMENT_DETECTED_BODY_COUNT
COMMENT_DETECTED_TRUST
COMMENT_DETECTED_LINKS
COMMENT_DETECTED_BANNED_WORD
@@ -137,9 +137,9 @@ type DontAgreeActionCounts {
type FlagReasonActionCounts {
COMMENT_REPORTED_OFFENSIVE: Int!
COMMENT_REPORTED_SPAM: Int!
COMMENT_REPORTED_OTHER: Int!
COMMENT_DETECTED_TOXIC: Int!
COMMENT_DETECTED_SPAM: Int!
COMMENT_DETECTED_BODY_COUNT: Int!
COMMENT_DETECTED_TRUST: Int!
COMMENT_DETECTED_LINKS: Int!
COMMENT_DETECTED_BANNED_WORD: Int!
@@ -2230,6 +2230,12 @@ input CreateCommentDontAgreeInput {
"""
commentRevisionID: ID!
"""
additionalDetails stores information from the User as to why the Flag was
created or is relevant.
"""
additionalDetails: String
"""
clientMutationId is required for Relay support.
"""
@@ -2297,6 +2303,12 @@ input CreateCommentFlagInput {
"""
reason: COMMENT_FLAG_REPORTED_REASON!
"""
additionalDetails stores information from the User as to why the Flag was
created or is relevant.
"""
additionalDetails: String
"""
clientMutationId is required for Relay support.
"""
@@ -2964,8 +2976,8 @@ type Mutation {
User on a Comment if it exists.
"""
removeCommentReaction(
input: CreateCommentReactionInput!
): CreateCommentReactionPayload @auth
input: RemoveCommentReactionInput!
): RemoveCommentReactionPayload @auth
"""
createCommentDontAgree will create a DontAgree authored by the current logged in
@@ -2980,8 +2992,8 @@ type Mutation {
User on a Comment if it exists.
"""
removeCommentDontAgree(
input: CreateCommentDontAgreeInput!
): CreateCommentDontAgreePayload @auth
input: RemoveCommentDontAgreeInput!
): RemoveCommentDontAgreePayload @auth
"""
createCommentFlag will create a Flag authored by the current logged in User on