Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip(apw) - Create reviewers group #3565

Draft
wants to merge 4 commits into
base: sasho/feat/apw/reviewer-groups
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
487 changes: 487 additions & 0 deletions packages/api-apw/__tests__/graphql/reviewersGroup.crud.test.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/api-apw/src/crud/createContentReviewMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ApwContentReviewStatus,
ApwContentReviewStepStatus,
ApwReviewerCrud,
ApwReviewsGroupCrud,
ApwScheduleActionData,
ApwWorkflowStepTypes,
CreateApwContentReviewParams,
Expand Down Expand Up @@ -41,6 +42,7 @@ import { PluginsContainer } from "@webiny/plugins";

export interface CreateContentReviewMethodsParams extends CreateApwParams {
getReviewer: ApwReviewerCrud["get"];
getReviewersGroup: ApwReviewsGroupCrud["get"];
getContentGetter: AdvancedPublishingWorkflow["getContentGetter"];
getContentPublisher: AdvancedPublishingWorkflow["getContentPublisher"];
getContentUnPublisher: AdvancedPublishingWorkflow["getContentUnPublisher"];
Expand Down
44 changes: 42 additions & 2 deletions packages/api-apw/src/crud/createReviewersGroupMethods.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
export function createReviewersGroupMethods(): Record<string, any> {
return {};
import {
ApwReviewersGroup,
ApwReviewsGroupCrud,
CreateApwParams,
CreateApwReviewsGroupParams,
OnReviewerGroupAfterCreateTopicParams,
OnReviewerGroupBeforeCreateTopicParams,
UpdateApwReviewsGroupParams
} from "~/types";
import { createTopic } from "@webiny/pubsub";

export function createReviewersGroupMethods({
storageOperations
}: CreateApwParams): ApwReviewsGroupCrud {
// create
const onReviewersGroupBeforeCreate = createTopic<OnReviewerGroupBeforeCreateTopicParams>(
"apw.onReviewersGroupBeforeCreate"
);
const onReviewersGroupAfterCreate = createTopic<OnReviewerGroupAfterCreateTopicParams>(
"apw.onReviewersGroupAfterCreate"
);

return {
onReviewersGroupBeforeCreate,
onReviewersGroupAfterCreate,
async create(data: CreateApwReviewsGroupParams): Promise<ApwReviewersGroup> {
await onReviewersGroupBeforeCreate.publish(data);

const reviewersGroup = await storageOperations.createReviewersGroup({ data });

await onReviewersGroupAfterCreate.publish({ group: reviewersGroup });

return reviewersGroup;
},
async get(id: string): Promise<ApwReviewersGroup> {
return new Promise<ApwReviewersGroup>();
},
async update(id: string, data: UpdateApwReviewsGroupParams): Promise<ApwReviewersGroup> {
return null;
},
async delete(id: string): Promise<Boolean> {}
};
}
8 changes: 8 additions & 0 deletions packages/api-apw/src/storageOperations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ import { createChangeRequestStorageOperations } from "./changeRequestStorageOper
import { createCommentStorageOperations } from "~/storageOperations/commentStorageOperations";
import { createApwModels } from "./models";
import { Security } from "@webiny/api-security/types";
import { createReviewersGroupStorageOperations } from "~/storageOperations/reviewsGroupStorageOperations";

export interface CreateApwStorageOperationsParams {
cms: HeadlessCms;
security: Security;
getCmsContext: () => CmsContext;
}

export interface CreateApwReviewersGroupStorageOperationsParams {
cms: HeadlessCms;
security: Security;
getCmsContext: () => CmsContext;
}

/**
* Using any because value can be a lot of types.
* TODO @ts-refactor figure out correct types.
Expand All @@ -36,6 +43,7 @@ export const createStorageOperations = (

return {
...createReviewerStorageOperations(params),
...createReviewersGroupStorageOperations(params),
...createWorkflowStorageOperations(params),
...createContentReviewStorageOperations(params),
...createChangeRequestStorageOperations(params),
Expand Down
3 changes: 3 additions & 0 deletions packages/api-apw/src/storageOperations/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createCommentModelDefinition } from "./comment.model";
import { createChangeRequestModelDefinition } from "./changeRequest.model";
import { CmsContext } from "@webiny/api-headless-cms/types";
import { isInstallationPending } from "~/plugins/utils";
import { createReviewersGroupModelDefinition } from "~/storageOperations/models/reviewersGroup.model";

export const createApwModels = (context: CmsContext) => {
/**
Expand Down Expand Up @@ -52,6 +53,7 @@ export const createApwModels = (context: CmsContext) => {
*/
const changeRequestModelDefinition = createChangeRequestModelDefinition();
const reviewerModelDefinition = createReviewerModelDefinition();
const reviewersGroupDefinition = createReviewersGroupModelDefinition();
const workflowModelDefinition = createWorkflowModelDefinition({
reviewerModelId: reviewerModelDefinition.modelId
});
Expand All @@ -66,6 +68,7 @@ export const createApwModels = (context: CmsContext) => {
workflowModelDefinition,
contentReviewModelDefinition,
reviewerModelDefinition,
reviewersGroupDefinition,
changeRequestModelDefinition,
commentModelDefinition
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { createModelField } from "./utils";
import { WorkflowModelDefinition } from "~/types";

const idField = () =>
createModelField({
label: "Identity Id",
type: "text",
parent: "reviewersGroup",
validation: [
{
message: "`identityId` field value is required in reviewersGroup.",
name: "required"
}
]
});

const nameField = () =>
createModelField({
label: "Name",
type: "text",
parent: "reviewersGroup",
validation: [
{
message: "`name` field value is required in reviewersGroup.",
name: "required"
}
]
});

const slugField = () =>
createModelField({
label: "Slug",
type: "text",
parent: "reviewersGroup",
validation: [
{
message: "`slug` field value is required in reviewersGroup.",
name: "required"
}
]
});

const descriptionField = () =>
createModelField({
label: "Description",
type: "text",
parent: "reviewersGroup"
});

const reviewersField = () =>
createModelField({
label: "Reviewers",
type: "object",
parent: "reviewersGroup",
validation: [
{
message: "`reviewers` field value is required in reviewersGroup.",
name: "required"
}
]
});

export const REVIEWERS_GROUP_MODEL_ID = "apwReviewersGroupModelDefinition";

export const createReviewersGroupModelDefinition = (): WorkflowModelDefinition => {
return {
name: "APW - Reviewer",
modelId: REVIEWERS_GROUP_MODEL_ID,
titleFieldId: "name",
layout: [
["reviewer_identityId"],
["reviewersGroup_name"],
["reviewersGroup_description"],
["reviewersGroup_reviewers"]
],
fields: [idField(), nameField(), slugField(), descriptionField(), reviewersField()],
description: "",
isPrivate: true
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ApwReviewersGroupStorageOperations } from "./types";
import {
baseFields,
CreateApwReviewersGroupStorageOperationsParams,
getFieldValues
} from "~/storageOperations/index";
import WebinyError from "@webiny/error";

export const createReviewersGroupStorageOperations = ({
cms,
security
}: CreateApwReviewersGroupStorageOperationsParams): ApwReviewersGroupStorageOperations => {
const getReviewersGroupModel = async () => {
const model = await security.withoutAuthorization(async () => {
return cms.getModel("apwReviewersGroupModelDefinition");
});
if (!model) {
throw new WebinyError(
"Could not find `apwReviewersGroupModelDefinition` model.",
"MODEL_NOT_FOUND_ERROR"
);
}
return model;
};

return {
getReviewersGroupModel,
async createReviewersGroup(params) {
const model = await getReviewersGroupModel();
const entry = await security.withoutAuthorization(async () => {
return cms.createEntry(model, params.data);
});
return getFieldValues(entry, baseFields);
}
};
};
16 changes: 12 additions & 4 deletions packages/api-apw/src/storageOperations/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { CmsModel } from "@webiny/api-headless-cms/types";
import {
ApwReviewerStorageOperations as BaseApwReviewerStorageOperations,
ApwWorkflowStorageOperations as BaseApwWorkflowStorageOperations,
ApwContentReviewStorageOperations as BaseApwContentReviewStorageOperations,
ApwChangeRequestStorageOperations as BaseApwChangeRequestStorageOperations,
ApwCommentStorageOperations as BaseApwCommentStorageOperations
ApwCommentStorageOperations as BaseApwCommentStorageOperations,
ApwContentReviewStorageOperations as BaseApwContentReviewStorageOperations,
ApwReviewersGroupStorageOperations as BaseApwReviewersGroupStorageOperations,
ApwReviewerStorageOperations as BaseApwReviewerStorageOperations,
ApwWorkflowStorageOperations as BaseApwWorkflowStorageOperations
} from "~/types";

export interface ApwCommentStorageOperations extends BaseApwCommentStorageOperations {
Expand All @@ -21,6 +22,13 @@ export interface ApwReviewerStorageOperations extends BaseApwReviewerStorageOper
getReviewerModel(): Promise<CmsModel>;
}

export interface ApwReviewersGroupStorageOperations extends BaseApwReviewersGroupStorageOperations {
/**
* @internal
*/
getReviewersGroupModel(): Promise<CmsModel>;
}

export interface ApwWorkflowStorageOperations extends BaseApwWorkflowStorageOperations {
/**
* @internal
Expand Down
Loading