Skip to content

WIP #3223

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

Closed
wants to merge 11 commits into from
Closed

WIP #3223

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
73 changes: 73 additions & 0 deletions dbschema/migrations/00009-m1gm5bm.edgeql

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

37 changes: 28 additions & 9 deletions dbschema/project.esdl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,10 @@ module default {
);
};

required step: Project::Step {
default := Project::Step.EarlyConversations;
};
required stepChangedAt: datetime {
default := .createdAt;
rewrite update using (datetime_of_statement() if .step != __old__.step else .stepChangedAt);
}
property status := Project::statusFromStep(.step);
status := Project::statusFromStep(.step);
step := .latestWorkflowEvent.to ?? Project::Step.EarlyConversations;
latestWorkflowEvent := (select .workflowEvents order by .at desc limit 1);
workflowEvents := .<project[is Project::WorkflowEvent];

mouStart: cal::local_date;
mouEnd: cal::local_date;
Expand Down Expand Up @@ -199,7 +195,30 @@ module Project {
on target delete allow;
};
}


type WorkflowEvent {
required project: default::Project {
readonly := true;
};
required who: default::Actor {
readonly := true;
default := global default::currentActor;
};
required at: datetime {
readonly := true;
default := datetime_of_statement();
};
transitionKey: uuid {
readonly := true;
};
required to: Step {
readonly := true;
};
notes: default::RichText {
readonly := true;
};
}

scalar type Step extending enum<
EarlyConversations,
PendingConceptApproval,
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
"nanoid": "^4.0.2",
"neo4j-driver": "^5.20.0",
"p-retry": "^5.1.2",
"pako": "^2.1.0",
"pkg-up": "^4.0.0",
"plur": "^5.1.0",
"prismjs-terminal": "^1.2.3",
Expand Down Expand Up @@ -125,7 +124,6 @@
"@types/lodash": "^4.14.200",
"@types/luxon": "^3.3.3",
"@types/node": "^20.12.5",
"@types/pako": "^2.0.2",
"@types/prismjs": "^1.26.2",
"@types/react": "^18.2.33",
"@types/stack-trace": "^0.0.32",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Field, ObjectType } from '@nestjs/graphql';
import { ID, IdField } from '~/common';
import { TransitionType } from '../../../project/dto';
import { TransitionType } from '../../../project/workflow/dto';
import { ProgressReportStatus } from '../../dto';

export { TransitionType };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import open from 'open';
import pako from 'pako';
import { deflateSync as deflate } from 'zlib';
import { ProgressReportStatus as Status } from '../dto';
import { Transitions } from './transitions';

Expand Down Expand Up @@ -77,8 +77,7 @@ export class ProgressReportWorkflowFlowchart {
}

private compressAndB64encode(str: string) {
const data = Buffer.from(str, 'utf8');
const compressed = pako.deflate(data, { level: 9 });
const compressed = deflate(str, { level: 9 });
const result = Buffer.from(compressed)
.toString('base64')
.replace(/\+/g, '-')
Expand Down
26 changes: 1 addition & 25 deletions src/components/project/dto/project-step.enum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field, ObjectType } from '@nestjs/graphql';
import { ObjectType } from '@nestjs/graphql';
import { EnumType, makeEnum, SecuredEnum } from '~/common';

export type ProjectStep = EnumType<typeof ProjectStep>;
Expand Down Expand Up @@ -40,27 +40,3 @@ export const ProjectStep = makeEnum({
description: SecuredEnum.descriptionFor('a project step'),
})
export class SecuredProjectStep extends SecuredEnum(ProjectStep) {}

export type TransitionType = EnumType<typeof TransitionType>;
export const TransitionType = makeEnum({
name: 'TransitionType',
values: ['Neutral', 'Approve', 'Reject'],
});

@ObjectType()
export abstract class ProjectStepTransition {
@Field(() => ProjectStep)
to: ProjectStep;

@Field()
label: string;

@Field(() => TransitionType)
type: TransitionType;

@Field(() => Boolean, { defaultValue: false })
disabled?: boolean;

@Field(() => String, { nullable: true })
disabledReason?: string;
}
4 changes: 4 additions & 0 deletions src/components/project/dto/project.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DateTime } from 'luxon';
import { keys as keysOf } from 'ts-transformer-keys';
import { MergeExclusive } from 'type-fest';
import {
Calculated,
DateInterval,
DateTimeField,
DbLabel,
Expand Down Expand Up @@ -117,11 +118,13 @@ class Project extends Interfaces {
})
@DbLabel('ProjectStep')
@DbSort(sortingForEnumIndex(ProjectStep))
@Calculated()
readonly step: SecuredProjectStep;

@Field(() => ProjectStatus)
@DbLabel('ProjectStatus')
@DbSort(sortingForEnumIndex(ProjectStatus))
@Calculated()
readonly status: ProjectStatus;

readonly primaryLocation: Secured<LinkTo<'Location'> | null>;
Expand All @@ -144,6 +147,7 @@ class Project extends Interfaces {
readonly initialMouEnd: SecuredDateNullable;

@Field()
@Calculated()
readonly stepChangedAt: SecuredDateTime;

@Field()
Expand Down
5 changes: 4 additions & 1 deletion src/components/project/dto/update-project.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export abstract class UpdateProject {
@DateField({ nullable: true })
readonly estimatedSubmission?: CalendarDate | null;

@Field(() => ProjectStep, { nullable: true })
@Field(() => ProjectStep, {
nullable: true,
deprecationReason: 'Use `transitionProject` mutation instead',
})
readonly step?: ProjectStep;

@SensitivityField({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { isIdLike, PublicOf } from '~/common';
import { ID, isIdLike, PublicOf, Role } from '~/common';
import { e, RepoFor, ScopeOf } from '~/core/edgedb';
import {
CreateProjectMember,
Expand Down Expand Up @@ -33,6 +33,23 @@ export class ProjectMemberEdgeDBRepository
return await this.db.run(query);
}

async listAsNotifiers(projectId: ID, roles?: Role[]) {
const project = e.cast(e.Project, e.uuid(projectId));
const members = e.select(project.members, (member) => ({
filter: roles
? e.op(
'exists',
e.op(member.roles, 'intersect', e.cast(e.Role, e.set(...roles))),
)
: undefined,
}));
const query = e.select(members.user, () => ({
id: true,
email: true,
}));
return await this.db.run(query);
}

protected listFilters(
member: ScopeOf<typeof e.Project.Member>,
{ filter: input }: ProjectMemberListInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ID,
isIdLike,
NotFoundException,
Role,
ServerException,
Session,
UnsecuredDto,
Expand Down Expand Up @@ -177,4 +178,41 @@ export class ProjectMemberRepository extends DtoRepository<
.first();
return result!; // result from paginate() will always have 1 row.
}

async listAsNotifiers(projectId: ID, roles?: Role[]) {
return await this.db
.query()
.match([
node('', 'Project', { id: projectId }),
relation('out', '', 'member', ACTIVE),
node('node', 'ProjectMember'),
relation('out', '', 'user', ACTIVE),
node('user', 'User'),
])
.apply((q) =>
roles
? q
.match([
node('node'),
relation('out', '', 'roles', ACTIVE),
node('role', 'Property'),
])
.raw(
`WHERE size(apoc.coll.intersection(role.value, $filteredRoles)) > 0`,
{ filteredRoles: roles },
)
: q,
)
.with('user')
.optionalMatch([
node('user'),
relation('out', '', 'email', ACTIVE),
node('email', 'EmailAddress'),
])
.return<{ id: ID; email: string | null }>([
'user.id as id',
'email.value as email',
])
.run();
}
}
48 changes: 0 additions & 48 deletions src/components/project/project-step.resolver.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/components/project/project.edgedb.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const hydrate = e.shape(e.Project, (project) => ({
marketingLocation: true,
marketingRegionOverride: true,
fieldRegion: true,
stepChangedAt: e.op(project.latestWorkflowEvent.at, '??', project.createdAt),
owningOrganization: e.cast(e.uuid, null), // Not implemented going forward
presetInventory: e.bool(false), // Not implemented going forward
}));
Expand Down
Loading
Loading