Skip to content

Remove legacy APIs & transitional code for project workflow #3267

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

Merged
merged 2 commits into from
May 9, 2025
Merged
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
4 changes: 0 additions & 4 deletions src/components/project/dto/create-project.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
} from '~/common';
import { type Location } from '../../location/dto';
import { ReportPeriod } from '../../periodic-report/dto';
import { ProjectStep } from './project-step.enum';
import { ProjectType } from './project-type.enum';
import { IProject, type Project } from './project.dto';

Expand Down Expand Up @@ -69,9 +68,6 @@ export abstract class CreateProject {
@DateField({ nullable: true })
readonly estimatedSubmission?: CalendarDate;

@Field(() => ProjectStep, { nullable: true })
readonly step?: ProjectStep;

@SensitivityField({
description: 'Defaults to High, only available on internship projects',
nullable: true,
Expand Down
6 changes: 0 additions & 6 deletions src/components/project/dto/update-project.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import { ChangesetIdField } from '../../changeset';
import { type Location } from '../../location/dto';
import { ReportPeriod } from '../../periodic-report/dto';
import { ProjectStep } from './project-step.enum';
import { IProject, type Project } from './project.dto';

@InputType()
Expand Down Expand Up @@ -64,11 +63,6 @@ export abstract class UpdateProject {
@DateField({ nullable: true })
readonly estimatedSubmission?: CalendarDate | null;

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

@SensitivityField({
description: 'Update only available to internship projects',
optional: true,
Expand Down
2 changes: 1 addition & 1 deletion src/components/project/project.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class ProjectRepository extends CommonRepository {
}

async create(input: CreateProject) {
const step = input.step ?? ProjectStep.EarlyConversations;
const step = ProjectStep.EarlyConversations;
const now = DateTime.local();
const {
primaryLocationId,
Expand Down
33 changes: 4 additions & 29 deletions src/components/project/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ import {
type UnsecuredDto,
} from '~/common';
import { isAdmin } from '~/common/session';
import {
ConfigService,
HandleIdLookup,
IEventBus,
ILogger,
Logger,
} from '~/core';
import { HandleIdLookup, IEventBus, ILogger, Logger } from '~/core';
import { Transactional } from '~/core/database';
import { type AnyChangesOf } from '~/core/database/changes';
import { Privileges } from '../authorization';
Expand All @@ -46,7 +40,6 @@ import {
type LocationListInput,
type SecuredLocationList,
} from '../location/dto';
import { PartnerService } from '../partner';
import { PartnershipService } from '../partnership';
import {
type PartnershipListInput,
Expand Down Expand Up @@ -84,7 +77,6 @@ import {
type SecuredProjectMemberList,
} from './project-member/dto';
import { ProjectRepository } from './project.repository';
import { ProjectWorkflowService } from './workflow/project-workflow.service';

@Injectable()
export class ProjectService {
Expand All @@ -97,12 +89,8 @@ export class ProjectService {
private readonly partnerships: PartnershipService & {},
@Inject(forwardRef(() => EngagementService))
private readonly engagementService: EngagementService & {},
@Inject(forwardRef(() => PartnerService))
private readonly partnerService: PartnerService & {},
private readonly config: ConfigService,
private readonly privileges: Privileges,
private readonly eventBus: IEventBus,
private readonly workflow: ProjectWorkflowService,
private readonly repo: ProjectRepository,
private readonly projectChangeRequests: ProjectChangeRequestService,
@Logger('project:service') private readonly logger: ILogger,
Expand Down Expand Up @@ -293,29 +281,16 @@ export class ProjectService {
);
}

const { step: changedStep, ...changes } = this.repo.getActualChanges(
currentProject,
input,
);
const changes = this.repo.getActualChanges(currentProject, input);
this.privileges
.for(session, resolveProjectType(currentProject), currentProject)
.verifyChanges(changes, { pathPrefix: 'project' });
if (!changedStep && Object.keys(changes).length === 0) {
if (Object.keys(changes).length === 0) {
return await this.readOneUnsecured(input.id, session, changeset);
}

ProjectDateRangeException.throwIfInvalid(currentProject, changes);

let updated = currentProject;
if (changedStep) {
await this.workflow.executeTransitionLegacy(
this.secure(currentProject, session),
changedStep,
session,
);
updated = await this.readOneUnsecured(input.id, session, changeset);
}

if (changes.primaryLocationId) {
try {
const location = await this.locationService.readOne(
Expand Down Expand Up @@ -347,7 +322,7 @@ export class ProjectService {
'Field region not found',
);

updated = await this.repo.update(updated, changes, changeset);
const updated = await this.repo.update(currentProject, changes, changeset);

const prevMissing = RequiredWhen.calc(IProject, currentProject);
const nowMissing = RequiredWhen.calc(IProject, updated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ObjectType } from '@nestjs/graphql';
import { WorkflowTransition } from '../../../workflow/dto';
import { ProjectStep } from '../../dto';

@ObjectType('ProjectStepTransition', {
@ObjectType({
description: WorkflowTransition.descriptionFor('project'),
})
export abstract class ProjectWorkflowTransition extends WorkflowTransition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class StepHistoryToWorkflowEventsMigration extends BaseMigration {
{
project: fakeProject,
moduleRef: this.moduleRef,
// @ts-expect-error removed from src, but keeping this file for reference for now.
migrationPrevSteps: prev,
},
project,
Expand Down
25 changes: 1 addition & 24 deletions src/components/project/workflow/project-workflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
findTransition,
WorkflowService,
} from '../../workflow/workflow.service';
import { IProject, type Project, type ProjectStep } from '../dto';
import { IProject, type Project } from '../dto';
import { ProjectService } from '../project.service';
import {
type ExecuteProjectTransitionInput,
Expand Down Expand Up @@ -110,27 +110,4 @@ export class ProjectWorkflowService extends WorkflowService(

return this.projects.secure(event.project, session);
}

/** @deprecated */
async executeTransitionLegacy(
currentProject: Project,
step: ProjectStep,
session: Session,
) {
const transitions = await this.getAvailableTransitions(
currentProject,
session,
);
// Pick the first matching to step.
// Lack of detail is one of the reasons why this is legacy logic.
const transition = transitions.find((t) => t.to === step);

await this.executeTransition(
{
project: currentProject.id,
...(transition ? { transition: transition.key } : { bypassTo: step }),
},
session,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ export interface ResolveParams {
project: MaybeSecured<Project>;
previousStep?: Step;
moduleRef: ModuleRef;
migrationPrevSteps?: ProjectStep[];
}

export const BackTo = (
...steps: ProjectStep[]
): DynamicState<Step, ResolveParams> => ({
description: 'Back',
relatedStates: steps,
async resolve({ project, moduleRef, migrationPrevSteps }) {
if (migrationPrevSteps) {
return migrationPrevSteps.find((s) => steps.includes(s)) ?? steps[0];
}
async resolve({ project, moduleRef }) {
const repo = moduleRef.get(ProjectWorkflowRepository);
const found = await repo.mostRecentStep(project.id, steps);
return found ?? steps[0] ?? ProjectStep.EarlyConversations;
Expand Down