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

MARXAN-1274-published-Project-image-webshot-cookie #1014

Merged
merged 1 commit into from
Apr 26, 2022
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 @@ -54,12 +54,13 @@ import {
ProcessFetchSpecification,
} from 'nestjs-base-service';
import { PublishedProjectSerializer } from '../published-project.serializer';
import { PublishProjectDto } from '../dto/publish-project.dto';
import { CreatePublishProjectDto } from '../dto/publish-project.dto';
import { RequestPublishedProjectCloneResponseDto } from '@marxan-api/modules/projects/dto/export.project.dto';
import { ProjectsService } from '@marxan-api/modules/projects/projects.service';
import { ExportId } from '@marxan-api/modules/clone';
import { UserId } from '@marxan/domain-ids';
import { mapAclDomainToHttpError } from '@marxan-api/utils/acl.utils';
import { AppSessionTokenCookie } from '@marxan-api/decorators/app-session-token-cookie.decorator';

@IsMissingAclImplementation()
@UseGuards(JwtAuthGuard)
Expand All @@ -80,13 +81,33 @@ export class PublishProjectController {
@ApiInternalServerErrorResponse()
async publish(
@Param('id') id: string,
@Body() dto: PublishProjectDto,
@Body() dto: CreatePublishProjectDto,
@Request() req: RequestWithAuthenticatedUser,
@AppSessionTokenCookie() appSessionTokenCookie: string,
): Promise<void> {
const { config } = dto;
/**
* If a frontend app session token was provided via cookie, use this to let
* the webshot service authenticate to the app, otherwise fall back to
* looking for the relevant cookies in the body of the request.
*
* @todo Remove this once the new auth workflow via `Cookie` header is
* stable.
*/
const configForWebshot = appSessionTokenCookie
? {
...config,
cookie: appSessionTokenCookie,
}
: config;
const dtoWithUpdatedConfig = {
...dto,
config: configForWebshot || config,
};
const result = await this.publishedProjectService.publish(
id,
req.user.id,
dto,
dtoWithUpdatedConfig,
);

if (isLeft(result)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ export class PublishProjectDto {
@IsOptional()
@ApiPropertyOptional()
featuredScenarioId?: string;
}

export class CreatePublishProjectDto extends PublishProjectDto {
@ApiProperty()
@ValidateNested({ each: true })
@Type(() => WebshotConfig)
config?: WebshotConfig;
config!: WebshotConfig;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ProjectsRequest } from '@marxan-api/modules/projects/project-requests-i
import { PublishedProject } from '@marxan-api/modules/published-project/entities/published-project.api.entity';
import { ProjectAccessControl } from '@marxan-api/modules/access-control';
import { UsersService } from '@marxan-api/modules/users/users.service';
import { PublishProjectDto } from './dto/publish-project.dto';
import { CreatePublishProjectDto } from './dto/publish-project.dto';
import { WebshotService } from '@marxan/webshot';
import { AppConfig } from '@marxan-api/utils/config.utils';
import { assertDefined } from '@marxan/utils';
Expand Down Expand Up @@ -45,7 +45,7 @@ export class PublishedProjectService {
async publish(
id: string,
requestingUserId: string,
projectToPublish: PublishProjectDto,
projectToPublish: CreatePublishProjectDto,
): Promise<Either<errors | typeof alreadyPublished, true>> {
const project = await this.projectRepository.findOne(id);

Expand Down