Skip to content

Correct FieldRegion's zone change to only migrate zone directors for that region #3502

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

Open
wants to merge 1 commit into
base: field-region-filters
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class RegionsZoneChangesAppliesDirectorChangeToProjectMembersHandler {
oldDirector.id,
newDirector.id,
'FieldOperationsDirector',
event.updated.id,
);

this.logger.notice(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,26 @@ export class ProjectMemberGelRepository
oldDirector: ID<'User'>,
newDirector: ID<'User'>,
role: Role,
region?: ID<'FieldRegion'>,
) {
return await this.db.run(this.replaceMembershipsOnOpenProjectsQuery, {
oldDirector,
newDirector,
role,
region,
});
}
private readonly replaceMembershipsOnOpenProjectsQuery = e.params(
{
oldDirector: e.uuid,
newDirector: e.uuid,
role: e.Role,
region: e.optional(e.uuid),
},
($) => {
const oldDirector = e.cast(e.User, $.oldDirector);
const newDirector = e.cast(e.User, $.newDirector);
const region = e.cast(e.FieldRegion, $.region);

const members = e.select(e.Project.members, (member) => ({
filter: e.all(
Expand All @@ -101,6 +105,14 @@ export class ProjectMemberGelRepository
e.op(member.active, '=', true),
e.op($.role, 'in', member.roles),
e.op(member.project.status, 'in', e.set('Active', 'InDevelopment')),
e.op(
'if',
e.op('exists', region),
'then',
e.op(member.project.fieldRegion, '=', region),
'else',
true,
),
),
),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ export class ProjectMemberRepository extends DtoRepository(ProjectMember) {
oldDirector: ID<'User'>,
newDirector: ID<'User'>,
role: Role,
// This could be replaced with Filters once those are abstracted for Gel.
region?: ID<'FieldRegion'>,
) {
const nowVal = DateTime.now();
const now = variable('$now');
Expand Down Expand Up @@ -232,7 +234,10 @@ export class ProjectMemberRepository extends DtoRepository(ProjectMember) {
user: { id: oldDirector },
active: true,
roles: [role],
project: { status: ['Active', 'InDevelopment'] },
project: {
status: ['Active', 'InDevelopment'],
...(region ? { fieldRegion: { id: region } } : {}),
},
}),
)
.apply(
Expand Down