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

Fix view history #172

Merged
merged 7 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
46 changes: 16 additions & 30 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"immer": "^2.1.3",
"joi": "^14.3.1",
"jsonwebtoken": "^8.5.0",
"lodash.clonedeep": "^4.5.0",
"lodash.isequal": "^4.5.0",
"pino": "^5.8.0",
"pino-pretty": "^2.2.3",
Expand Down
3 changes: 3 additions & 0 deletions api/src/project_view_details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ function mkSwaggerSchema(server: FastifyInstance) {
type: "array",
items: {
type: "object",
additionalProperties: true,
kevinbader marked this conversation as resolved.
Show resolved Hide resolved
properties: {
entityId: { type: "string", example: "d0e8c69eg298c87e3899119e025eff1f" },
entityType: { type: "string", example: "project" },
businessEvent: {
type: "object",
additionalProperties: true,
properties: {
type: { type: "string" },
source: { type: "string" },
Expand All @@ -97,6 +99,7 @@ function mkSwaggerSchema(server: FastifyInstance) {
},
snapshot: {
type: "object",
additionalProperties: true,
properties: {
displayName: { type: "string", example: "Build a town-project" },
},
Expand Down
28 changes: 15 additions & 13 deletions api/src/project_view_history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { BusinessEvent } from "./service/domain/business_event";
import { ServiceUser } from "./service/domain/organization/service_user";
import * as Project from "./service/domain/workflow/project";
import * as Subproject from "./service/domain/workflow/subproject";
import logger from "./lib/logger";
kevinbader marked this conversation as resolved.
Show resolved Hide resolved

interface RequestBodyV1 {
apiVersion: "1.0";
Expand Down Expand Up @@ -83,25 +84,27 @@ function mkSwaggerSchema(server: FastifyInstance) {
items: {
type: "object",
properties: {
key: { type: "string" },
intent: { type: "string", example: "global.createProject" },
createdBy: { type: "string", example: "aSmith" },
createdAt: { type: "string", example: "2018-09-05T13:37:25.775Z" },
dataVersion: { type: "string", example: "1" },
data: {
entityId: { type: "string", example: "d0e8c69eg298c87e3899119e025eff1f" },
entityType: { type: "string", example: "project" },
businessEvent: {
type: "object",
additionalProperties: true,
example: { identity: "aSmith", intent: "subproject.viewDetails" },
properties: {
permissions: {
type: "object",
additionalProperties: true,
example: { "subproject.intent.listPermissions": ["aSmith", "jDoe"] },
},
type: { type: "string" },
source: { type: "string" },
time: { type: "string" },
publisher: { type: "string" },
},
example: {
type: "project_closed",
source: "http",
time: "2018-09-05T13:37:25.775Z",
publisher: "jdoe",
},
},
snapshot: {
type: "object",
additionalProperties: true,
properties: {
displayName: { type: "string", example: "townproject" },
},
Expand Down Expand Up @@ -201,7 +204,6 @@ export function addHttpHandler(server: FastifyInstance, urlPrefix: string, servi
for (const subproject of subprojects) {
events.push(...subproject.log);
}

kevinbader marked this conversation as resolved.
Show resolved Hide resolved
events.sort(byEventTime);

const offsetIndex = offset < 0 ? Math.max(0, events.length + offset) : offset;
Expand Down
23 changes: 17 additions & 6 deletions api/src/service/cache2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Ctx } from "../lib/ctx";
import logger from "../lib/logger";
import deepcopy from "../lib/deepcopy";
import { isEmpty } from "../lib/emptyChecks";
import logger from "../lib/logger";
import * as Result from "../result";
import { MultichainClient } from "./Client.h";
import { ConnToken } from "./conn";
Expand Down Expand Up @@ -443,20 +444,25 @@ function addEventsToCache(cache: Cache2, streamName: string, newEvents: Business
break;

default:
// Do nothing, becaue informations will be reflected in aggregates
// Do nothing, because informations will be reflected in aggregates
break;
}
}

export function updateAggregates(ctx: Ctx, cache: Cache2, newEvents: BusinessEvent[]) {
// we ignore the errors
const { projects } = sourceProjects(ctx, newEvents, cache.cachedProjects);
const { projects, errors: pErrors = [] } = sourceProjects(ctx, newEvents, cache.cachedProjects);
if (!isEmpty(pErrors)) logger.warn("sourceProject caused error: ", pErrors);
kevinbader marked this conversation as resolved.
Show resolved Hide resolved

for (const project of projects) {
cache.cachedProjects.set(project.id, project);
}

const { subprojects } = sourceSubprojects(ctx, newEvents, cache.cachedSubprojects);
const { subprojects, errors: spErrors = [] } = sourceSubprojects(
ctx,
newEvents,
cache.cachedSubprojects,
);
if (!isEmpty(spErrors)) logger.warn("sourceSubproject caused error: ", spErrors);
kevinbader marked this conversation as resolved.
Show resolved Hide resolved

for (const subproject of subprojects) {
cache.cachedSubprojects.set(subproject.id, subproject);
Expand All @@ -467,7 +473,12 @@ export function updateAggregates(ctx: Ctx, cache: Cache2, newEvents: BusinessEve
: lookUp.add(subproject.id);
}

const { workflowitems, errors } = sourceWorkflowitems(ctx, newEvents, cache.cachedWorkflowItems);
const { workflowitems, errors: wErrors = [] } = sourceWorkflowitems(
ctx,
newEvents,
cache.cachedWorkflowItems,
);
if (!isEmpty(wErrors)) logger.warn("sourceWorkflowitems caused error: ", wErrors);
kevinbader marked this conversation as resolved.
Show resolved Hide resolved

for (const workflowitem of workflowitems) {
cache.cachedWorkflowItems.set(workflowitem.id, workflowitem);
Expand Down
5 changes: 3 additions & 2 deletions api/src/service/domain/workflow/subproject_eventsourcing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { produce } from "immer";

import { Ctx } from "../../../lib/ctx";
import logger from "../../../lib/logger";
import * as Result from "../../../result";
import { BusinessEvent } from "../business_event";
import { EventSourcingError } from "../errors/event_sourcing_error";
Expand Down Expand Up @@ -31,9 +32,9 @@ export function sourceSubprojects(
if (!event.type.startsWith("subproject_")) {
continue;
}

const result = applySubprojectEvent(ctx, subprojects, event);
if (Result.isErr(result)) {
logger.warn(result);
kevinbader marked this conversation as resolved.
Show resolved Hide resolved
errors.push(result);
} else {
result.log.push(newTraceEvent(result, event));
Expand Down Expand Up @@ -78,7 +79,7 @@ function applySubprojectEvent(
return apply(ctx, event, subprojects, event.subprojectId, SubprojectProjectedBudgetDeleted);

default:
throw Error(`not implemented: ${event.type}`);
return Error(`not implemented: ${event.type}`);
}
}

Expand Down
8 changes: 4 additions & 4 deletions api/src/service/domain/workflow/subproject_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { canAssumeIdentity } from "../organization/auth_token";
import { ServiceUser } from "../organization/service_user";
import * as Subproject from "./subproject";
import { SubprojectTraceEvent } from "./subproject_trace_event";
import logger from "../../../lib/logger";

interface Repository {
getSubproject(): Promise<Result.Type<Subproject.Subproject>>;
Expand All @@ -18,13 +19,11 @@ export async function getSubproject(
subprojectId: string,
repository: Repository,
): Promise<Result.Type<Subproject.Subproject>> {
const subprojectResult = await repository.getSubproject();
const subproject = await repository.getSubproject();

if (Result.isErr(subprojectResult)) {
if (Result.isErr(subproject)) {
return new NotFound(ctx, "subproject", subprojectId);
}
const subproject = subprojectResult;

if (
user.id !== "root" &&
!Subproject.permits(subproject, user, ["subproject.viewSummary", "subproject.viewDetails"])
Expand All @@ -46,6 +45,7 @@ const requiredPermissions = new Map<EventType, Intent[]>([
["subproject_archived", ["subproject.viewSummary", "subproject.viewDetails"]],
["subproject_projected_budget_updated", ["subproject.viewDetails"]],
["subproject_projected_budget_deleted", ["subproject.viewDetails"]],
["subproject_items_reordered", ["subproject.reorderWorkflowitems"]],
kevinbader marked this conversation as resolved.
Show resolved Hide resolved
]);

function dropHiddenHistoryEvents(
Expand Down
1 change: 1 addition & 0 deletions api/src/service/domain/workflow/subproject_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const requiredPermissions = new Map<EventType, Intent[]>([
["subproject_archived", ["subproject.viewSummary", "subproject.viewDetails"]],
["subproject_projected_budget_updated", ["subproject.viewDetails"]],
["subproject_projected_budget_deleted", ["subproject.viewDetails"]],
["subproject_items_reordered", ["subproject.reorderWorkflowitems"]],
kevinbader marked this conversation as resolved.
Show resolved Hide resolved
]);

function dropHiddenHistoryEvents(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { produce } from "immer";
import isEqual = require("lodash.isequal");

import { produce } from "immer";
import Intent from "../../../authz/intents";
import { Ctx } from "../../../lib/ctx";
import logger from "../../../lib/logger";
import * as Result from "../../../result";
import { BusinessEvent } from "../business_event";
import { InvalidCommand } from "../errors/invalid_command";
Expand Down
Loading