bcgov / digital_marketplace

The intent of this development is to build a product that will support digital procurement needs for the BC Government including services such as, but not limited to, Sprint With Us, Code With Us, The Procurement Concierge.
Apache License 2.0
13 stars 17 forks source link

An admin can publish a SWU opp. without review (API only) #163

Open joserwan opened 3 years ago

joserwan commented 3 years ago

Classic steps are :

  1. Draft (if base validation passes)
  2. Submit for review (if complete validation passes)
  3. Publish (if previous step passes)

But an admin can go from step 1. to step 3. Then, no validation is done at step 2.

Relevant code parts :

// src/shared/lib/resources/opportunity/sprint-with-us.ts
export function isValidStatusChange(from: SWUOpportunityStatus, to: SWUOpportunityStatus): boolean {
  switch (from) {
    case SWUOpportunityStatus.Draft:
      // UnderReview step can be omitted
      return [SWUOpportunityStatus.UnderReview, SWUOpportunityStatus.Published].includes(to);
// [...]

But validations take place while Reviewal step :

// src/back-end/lib/resources/opportunity/sprint-with-us.ts

case 'publish':
            // [...]
            // Opportunity will have been fully validated during review process, so no need to repeat
            const validatedPublishNote = opportunityValidation.validateNote(request.body.value);
            if (isInvalid(validatedPublishNote)) {
              return invalid({ opportunity: adt('publish' as const, validatedPublishNote.value) });
            }
            return valid({
              session: request.session,
              body: adt('publish', validatedPublishNote.value)
            });

Found this bug while converting postman tests to Mocha (https://github.com/CQEN-QDCE/digital_marketplace/tree/experimentation/tests/back-end/unit/lib/api)

dhruvio commented 3 years ago

Thanks, @joserwan, we will review this and share our updates here.

dhruvio commented 3 years ago

I have reviewed this issue, and it is indeed a bug. Thanks for bringing it to our attention, @joserwan. I have created a ticket in BCGov's JIRA backlog (DM-728). Some notes for posterity: