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

Subspacetemplates fixes 2 #4665

Merged
merged 3 commits into from
Nov 4, 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.
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 @@ -62,11 +62,7 @@ export class CollaborationAuthorizationService {
},
}
);
if (
!collaboration.callouts ||
!collaboration.innovationFlow ||
!collaboration.timeline
) {
if (!collaboration.callouts || !collaboration.innovationFlow) {
throw new RelationshipNotFoundException(
`Unable to load child entities for collaboration authorization: ${collaboration.id}`,
LogContext.SPACES
Expand Down Expand Up @@ -121,8 +117,7 @@ export class CollaborationAuthorizationService {
if (
!collaboration.callouts ||
!collaboration.innovationFlow ||
!collaboration.innovationFlow.profile ||
!collaboration.timeline
!collaboration.innovationFlow.profile
) {
throw new RelationshipNotFoundException(
`Unable to load child entities for collaboration authorization children: ${collaboration.id}`,
Expand All @@ -148,7 +143,8 @@ export class CollaborationAuthorizationService {
collaboration.authorization
);

if (roleSet && spaceSettings) {
// Collaboration templates don't have timeline so this won't be executed for them
if (roleSet && spaceSettings && collaboration.timeline) {
const extendedAuthorizationContributors =
await this.appendCredentialRulesForContributors(
clonedAuthorization,
Expand Down
12 changes: 7 additions & 5 deletions src/domain/collaboration/collaboration/collaboration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,15 @@ export class CollaborationService {
AuthorizationPolicyType.COLLABORATION
);
collaboration.callouts = [];
collaboration.timeline = this.timelineService.createTimeline();
collaboration.groupsStr = this.calloutGroupsService.serializeGroups(
collaborationData.calloutGroups
);
collaboration.isTemplate = collaborationData.isTemplate || false;

if (!collaboration.isTemplate) {
collaboration.timeline = this.timelineService.createTimeline();
}

collaboration.tagsetTemplateSet =
this.tagsetTemplateSetService.createTagsetTemplateSet();

Expand Down Expand Up @@ -153,7 +156,7 @@ export class CollaborationService {
storageAggregator
);

this.moveCalloutsToCorrectGroupAndState(
this.moveCalloutsToDefaultGroupAndState(
groupTagsetTemplateInput.allowedValues,
statesTagsetTemplate.allowedValues,
collaboration.callouts
Expand Down Expand Up @@ -224,6 +227,7 @@ export class CollaborationService {
calloutNameIds.push(calloutDefault.nameID);
}
if (
calloutDefault.isTemplate === false &&
calloutDefault.type === CalloutType.POST &&
calloutDefault.contributionPolicy?.state === CalloutState.OPEN
) {
Expand All @@ -235,8 +239,6 @@ export class CollaborationService {
storageAggregator,
userID
);
// default callouts are already published
callout.visibility = CalloutVisibility.PUBLISHED;
callouts.push(callout);
}
return callouts;
Expand Down Expand Up @@ -788,7 +790,7 @@ export class CollaborationService {
* Move callouts that are not in valid groups or flowStates to the default group & first flowState
* @param callouts
*/
public moveCalloutsToCorrectGroupAndState(
public moveCalloutsToDefaultGroupAndState(
validGroupNames: string[],
validFlowStateNames: string[],
callouts: {
Expand Down
13 changes: 10 additions & 3 deletions src/domain/space/space.defaults/space.defaults.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Inject, Injectable, LoggerService } from '@nestjs/common';
import { LogContext } from '@common/enums/logging.context';
import { ISpaceSettings } from '../space.settings/space.settings.interface';
import { subspaceCommunityRoles } from './definitions/subspace.community.roles';
Expand Down Expand Up @@ -26,6 +26,7 @@ import { TemplateDefaultType } from '@common/enums/template.default.type';
import { ValidationException } from '@common/exceptions';
import { CollaborationService } from '@domain/collaboration/collaboration/collaboration.service';
import { ITemplatesManager } from '@domain/template/templates-manager';
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';

@Injectable()
export class SpaceDefaultsService {
Expand All @@ -34,7 +35,8 @@ export class SpaceDefaultsService {
private inputCreatorService: InputCreatorService,
private platformService: PlatformService,
private collaborationService: CollaborationService,
private templatesManagerService: TemplatesManagerService
private templatesManagerService: TemplatesManagerService,
@Inject(WINSTON_MODULE_NEST_PROVIDER) private readonly logger: LoggerService
) {}

public async createCollaborationInput(
Expand All @@ -61,6 +63,11 @@ export class SpaceDefaultsService {
}
} catch (e) {
// Space does not have a subspace default template, just use the platform default
this.logger.warn(
`Space does not have a subspace default template, using platform default parentSpaceTemplatesManager.id: ${parentSpaceTemplatesManager?.id}`,
undefined,
LogContext.TEMPLATES
);
}
}
// Get the platform default template if no parent template
Expand Down Expand Up @@ -171,7 +178,7 @@ export class SpaceDefaultsService {
state => state.displayName
);

this.collaborationService.moveCalloutsToCorrectGroupAndState(
this.collaborationService.moveCalloutsToDefaultGroupAndState(
validGroupNames ?? [],
validFlowStateNames ?? [],
collaborationData.calloutsData ?? []
Expand Down
87 changes: 55 additions & 32 deletions src/domain/template/template-applier/template.applier.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { AuthorizationPolicyService } from '@domain/common/authorization-policy/
import { IAuthorizationPolicy } from '@domain/common/authorization-policy';
import { NamingService } from '@services/infrastructure/naming/naming.service';
import { TagsetReservedName } from '@common/enums/tagset.reserved.name';
import { ICallout } from '@domain/collaboration/callout';

@Injectable()
export class TemplateApplierService {
Expand Down Expand Up @@ -76,46 +77,68 @@ export class TemplateApplierService {
userID
);
targetCollaboration.callouts?.push(...newCallouts);

const validGroupNames =
targetCollaboration.tagsetTemplateSet?.tagsetTemplates.find(
tagset => tagset.name === TagsetReservedName.CALLOUT_GROUP
)?.allowedValues;
const validFlowStates = this.innovationFlowService
.getStates(targetCollaboration.innovationFlow)
?.map(state => state.displayName);

this.collaborationService.moveCalloutsToCorrectGroupAndState(
validGroupNames ?? [],
validFlowStates ?? [],
targetCollaboration.callouts
);

const authorizations: IAuthorizationPolicy[] = [];

const { roleSet: communityPolicy, spaceSettings } =
await this.namingService.getRoleSetAndSettingsForCollaboration(
targetCollaboration.id
);
this.ensureCalloutsInValidGroupsAndStates(targetCollaboration);

// Need to save before applying authorization policy to get the callout ids
const result = await this.collaborationService.save(targetCollaboration);

for (const callout of newCallouts) {
const calloutAuthorizations =
await this.calloutAuthorizationService.applyAuthorizationPolicy(
callout.id,
targetCollaboration.authorization,
communityPolicy,
spaceSettings
);
authorizations.push(...calloutAuthorizations);
}
await this.authorizationPolicyService.saveAll(authorizations);
await this.applyAuthorizationPolicyToNewCallouts(
targetCollaboration,
newCallouts
);

return result;
} else {
this.ensureCalloutsInValidGroupsAndStates(targetCollaboration);
return await this.collaborationService.save(targetCollaboration);
}
}
private ensureCalloutsInValidGroupsAndStates(
targetCollaboration: ICollaboration
) {
// We don't have callouts or we don't have innovationFlow, can't do anything
if (!targetCollaboration.innovationFlow || !targetCollaboration.callouts) {
throw new RelationshipNotFoundException(
`Unable to load Callouts or InnovationFlow ${targetCollaboration.id} `,
LogContext.TEMPLATES
);
}

const validGroupNames =
targetCollaboration.tagsetTemplateSet?.tagsetTemplates.find(
tagset => tagset.name === TagsetReservedName.CALLOUT_GROUP
)?.allowedValues;
const validFlowStates = this.innovationFlowService
.getStates(targetCollaboration.innovationFlow)
?.map(state => state.displayName);

this.collaborationService.moveCalloutsToDefaultGroupAndState(
validGroupNames ?? [],
validFlowStates ?? [],
targetCollaboration.callouts
);
}
private async applyAuthorizationPolicyToNewCallouts(
targetCollaboration: ICollaboration,
newCallouts: ICallout[]
): Promise<unknown> {
const authorizations: IAuthorizationPolicy[] = [];

const { roleSet: communityPolicy, spaceSettings } =
await this.namingService.getRoleSetAndSettingsForCollaboration(
targetCollaboration.id
);

for (const callout of newCallouts) {
const calloutAuthorizations =
await this.calloutAuthorizationService.applyAuthorizationPolicy(
callout.id,
targetCollaboration.authorization,
communityPolicy,
spaceSettings
);
authorizations.push(...calloutAuthorizations);
}
return await this.authorizationPolicyService.saveAll(authorizations);
}
}