当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript guardFactory.GuardFactory类代码示例

本文整理汇总了TypeScript中response/guards/guardFactory.GuardFactory的典型用法代码示例。如果您正苦于以下问题:TypeScript GuardFactory类的具体用法?TypeScript GuardFactory怎么用?TypeScript GuardFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GuardFactory类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: check

 /**
  * Throws Forbidden error if user is not defendant in the case
  *
  * @returns {express.RequestHandler} - request handler middleware
  */
 static check (): express.RequestHandler {
   return GuardFactory.create((res: express.Response) => {
     const claim: Claim = res.locals.claim
     const user: User = res.locals.user
     return claim.defendantId === user.id
   }, (req: express.Request, res: express.Response): void => {
     throw new ForbiddenError()
   })
 }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:14,代码来源:onlyDefendantLinkedToClaimCanDoIt.ts

示例2: checkConsentedAlready

function checkConsentedAlready (): express.RequestHandler {
  return GuardFactory.createAsync(async (req: express.Request, res: express.Response) => {
    const user: User = res.locals.user
    const roles = await claimStoreClient.retrieveUserRoles(user)

    return roles && !roles.some(role => role.includes('cmc-new-features-consent'))
  }, (req: express.Request, res: express.Response): void => {
    res.redirect(ClaimPaths.taskListPage.uri)
  })
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:10,代码来源:new-features-consent.ts

示例3: checkClaimantResponseDoesNotExist

 static checkClaimantResponseDoesNotExist (): express.RequestHandler {
   const allowed = (res: express.Response) => {
     const claim: Claim = res.locals.claim
     return claim.claimantResponse === undefined
   }
   const accessDeniedCallback = (req: express.Request, res: express.Response) => {
     logger.warn('State guard: claimant response already exists - redirecting to dashboard')
     res.redirect(DashboardPaths.dashboardPage.uri)
   }
   return GuardFactory.create(allowed, accessDeniedCallback)
 }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:11,代码来源:claimantResponseGuard.ts

示例4: requestHandler

  /**
   * Guard checks whether Statement of Means is required.
   * If so it accepts request, otherwise it makes redirect to task list
   *
   * @returns {e.RequestHandler}
   */
  static requestHandler (requireInitiatedModel: boolean = true): express.RequestHandler {
    return GuardFactory.create((res: express.Response) => {
      const draft: Draft<ResponseDraft> = res.locals.responseDraft
      const claim: Claim = res.locals.claim

      return StatementOfMeansFeature.isApplicableFor(claim, draft.document)
        && (requireInitiatedModel ? draft.document.statementOfMeans !== undefined : true)
    }, (req: express.Request, res: express.Response): void => {
      res.redirect(Paths.taskListPage.evaluateUri({ externalId: UUIDUtils.extractFrom(req.path) }))
    })
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:17,代码来源:statementOfMeansStateGuard.ts

示例5: checkResponseExists

 /**
  * Protects response journey from being accessed when response has not been submitted yet. Request in such scenario
  * will result in rendering not found page. In opposite scenario where response has already been made,
  * the request will be processed.
  */
 static checkResponseExists (): express.RequestHandler {
   const allowed = (res: express.Response) => {
     const claim: Claim = res.locals.claim
     return claim.response !== undefined
   }
   const accessDeniedCallback = (req: express.Request, res: express.Response) => {
     logger.warn('State guard: no response exists - rendering not found page')
     throw new NotFoundError(req.path)
   }
   return GuardFactory.create(allowed, accessDeniedCallback)
 }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:16,代码来源:responseGuard.ts

示例6: requestHandler

  static requestHandler (): express.RequestHandler {
    return GuardFactory.createAsync(async (req: express.Request, res: express.Response) => {
      if (!FeatureToggles.isEnabled('newFeaturesConsent')) {
        return true
      }

      const user: User = res.locals.user
      const roles = await claimStoreClient.retrieveUserRoles(user)

      return roles.length !== 0 && roles.some(role => role.includes('cmc-new-features-consent'))
    }, (req: express.Request, res: express.Response): void => {
      res.redirect(ClaimPaths.newFeaturesConsentPage.uri)
    })
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:14,代码来源:newFeaturesConsentGuard.ts

示例7: requestHandler

  static requestHandler (): express.RequestHandler {

    function isRequestAllowed (res: express.Response): boolean {
      const draft: Draft<ResponseDraft> = res.locals.responseDraft

      return draft.document.isResponseRejected()
    }

    function accessDeniedCallback (req: express.Request, res: express.Response): void {
      logger.warn('Full Rejection Guard: user tried to access page for full rejection flow')
      throw new NotFoundError(req.path)
    }

    return GuardFactory.create(isRequestAllowed, accessDeniedCallback)
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:15,代码来源:fullRejectionGuard.ts

示例8: requestHandler

  static requestHandler (): express.RequestHandler {

    function isRequestAllowed (res: express.Response): boolean {
      const draft: Draft<ResponseDraft> = res.locals.responseDraft
      const claim: Claim = res.locals.claim

      return ClaimFeatureToggles.isFeatureEnabledOnClaim(claim) && draft.document.isResponsePartiallyAdmitted()
    }

    function accessDeniedCallback (req: express.Request, res: express.Response): void {
      const claim: Claim = res.locals.claim
      logger.warn('Partial Admission Guard: user tried to access page for partial admission flow')
      res.redirect(Paths.responseTypePage.evaluateUri({ externalId: claim.externalId }))
    }

    return GuardFactory.create(isRequestAllowed, accessDeniedCallback)
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:17,代码来源:partialAdmissionGuard.ts

示例9: requestHandler

  /**
   * Makes sure that eligibility check has passed prior accessing protected pages. The eligibility is assessed by
   * checking whether draft has been marked as eligible or whether eligible cookie exists. If none of the conditions
   * is met then user is redirected to eligibility index page, otherwise request is let through as is.
   *
   * @returns {express.RequestHandler} - request handler middleware
   */
  static requestHandler (): express.RequestHandler {
    return GuardFactory.createAsync(async (req: express.Request, res: express.Response) => {
      const draft: Draft<DraftClaim> = res.locals.claimDraft
      if (draft.document.eligibility) {
        return true
      }

      const eligibility = eligibilityStore.read(req, res)
      if (eligibility.eligible) {
        await this.markDraftEligible(draft, res.locals.user)
        eligibilityStore.clear(req, res)
        return true
      }

      return false
    }, (req: express.Request, res: express.Response): void => {
      res.redirect(EligibilityPaths.startPage.uri)
    })
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:26,代码来源:claimEligibilityGuard.ts

示例10: buildRouter

  buildRouter (path: string, ...guards: express.RequestHandler[]): express.Router {
    const stateGuardRequestHandler: express.RequestHandler = GuardFactory.create((res: express.Response): boolean => {
      const model: PaymentIntention = this.createModelAccessor().get(res.locals.draft.document)

      return model
        && model.paymentOption
        && model.paymentOption.isOfType(PaymentType.INSTALMENTS)
    }, (req: express.Request, res: express.Response): void => {
      throw new NotFoundError(req.path)
    })

    return express.Router()
      .get(path + Paths.paymentPlanPage.uri,
        ...guards,
        stateGuardRequestHandler,
        ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
          this.renderView(new Form(this.createModelAccessor().get(res.locals.draft.document).paymentPlan), res)
        }))
      .post(path + Paths.paymentPlanPage.uri,
        ...guards,
        stateGuardRequestHandler,
        FormValidator.requestHandler(PaymentPlanModel, PaymentPlanModel.fromObject, undefined, ['calculatePaymentPlan']),
        ErrorHandling.apply(
          async (req: express.Request, res: express.Response): Promise<void> => {
            let form: Form<PaymentPlanModel> = req.body

            const error: FormValidationError = this.postValidation(req, res)

            if (error) {
              form = new Form<PaymentPlanModel>(form.model, [error, ...form.errors])
            }

            if (form.hasErrors() || _.get(req, 'body.action.calculatePaymentPlan')) {
              this.renderView(form, res)
            } else {
              this.createModelAccessor().patch(res.locals.draft.document, model => model.paymentPlan = form.model)

              await this.saveDraft(res.locals)

              res.redirect(this.buildPostSubmissionUri(req, res))
            }
          }))
  }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:43,代码来源:payment-plan.ts


注:本文中的response/guards/guardFactory.GuardFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。