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

Add primary partner name to project workflow notification #3210

Merged
merged 1 commit into from
May 21, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 47 additions & 1 deletion src/components/project/project.rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import {
} from '~/common';
import { ConfigService, ILogger, Logger } from '~/core';
import { DatabaseService } from '~/core/database';
import { ACTIVE, INACTIVE } from '~/core/database/query';
import { ACTIVE, INACTIVE, merge } from '~/core/database/query';
import { AuthenticationService } from '../authentication';
import { withoutScope } from '../authorization/dto';
import { EngagementService } from '../engagement';
import { EngagementStatus } from '../engagement/dto';
import { OrganizationService } from '../organization';
import { Organization } from '../organization/dto';
import { UserService } from '../user';
import { User } from '../user/dto';
import {
Expand Down Expand Up @@ -61,6 +63,7 @@ export interface EmailNotification {
changedBy: Pick<User, 'id' | 'displayFirstName' | 'displayLastName'>;
project: Pick<Project, 'id' | 'modifiedAt' | 'name' | 'step' | 'type'>;
previousStep?: ProjectStep;
primaryPartnerName?: string | undefined;
}

const rolesThatCanBypassWorkflow: Role[] = [Role.Administrator];
Expand All @@ -75,6 +78,7 @@ export class ProjectRules {
private readonly projectService: ProjectService & {},
@Inject(forwardRef(() => EngagementService))
private readonly engagements: EngagementService & {},
private readonly organizations: OrganizationService,
@Inject(forwardRef(() => AuthenticationService))
private readonly auth: AuthenticationService & {},
private readonly configService: ConfigService,
Expand Down Expand Up @@ -1099,6 +1103,35 @@ export class ProjectRules {
return result.steps;
}

async getPrimaryOrganizationByProjectId(id: ID) {
const result = await this.db
.query()
.match([
node('project', 'Project', { id }),
relation('out', '', 'partnership', ACTIVE),
node('partnership', 'Partnership'),
relation('out', '', 'primary', ACTIVE),
node('primary', 'Property', { value: true }),
])
.with('partnership')
.match([
node('partnership'),
relation('out', '', 'partner', ACTIVE),
node('', 'Partner'),
relation('out', '', 'organization', ACTIVE),
node('org', 'Organization'),
relation('out', '', 'name', ACTIVE),
node('name', 'Property'),
])
.return<{ dto: UnsecuredDto<Organization> }>(
merge('org', {
name: 'name.value',
}).as('dto'),
)
.first();
return result?.dto ?? null;
}

private async getEmailNotificationObject(
changedById: ID,
projectId: ID,
Expand Down Expand Up @@ -1135,11 +1168,24 @@ export class ProjectRules {
recipientSession,
);

const organization = await this.getPrimaryOrganizationByProjectId(
projectId,
);
let orgName;
if (organization) {
const org = await this.organizations.readOne(
organization.id,
recipientSession,
);
orgName = org.name.value;
}

return {
changedBy,
project,
recipient,
previousStep,
primaryPartnerName: orgName,
};
}
}
5 changes: 5 additions & 0 deletions src/core/email/templates/project-step-changed.template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function ProjectStepChanged({
changedBy,
previousStep: oldStepVal,
recipient,
primaryPartnerName,
}: StepChangeNotification) {
const projectUrl = useFrontendUrl(`/projects/${project.id}`);
const projectName = project.name.value;
Expand Down Expand Up @@ -65,6 +66,10 @@ export function ProjectStepChanged({
/>
<br />
Project Type: {project.type}
<br />
{primaryPartnerName ? (
<>Primary Partner: {primaryPartnerName}</>
) : null}
</Text>
<HideInText>
<Button href={projectUrl} paddingTop={16}>
Expand Down