void onOperationProposed()

in sources/src/main/java/com/google/solutions/jitaccess/web/proposal/MailProposalHandler.java [111:157]


  void onOperationProposed(
    @NotNull JitGroupContext.JoinOperation operation,
    @NotNull Proposal proposal,
    @NotNull ProposalHandler.ProposalToken token,
    @NotNull URI actionUri
  ) throws IOException {

    var recipients = proposal.recipients()
      .stream()
      .map(this.emailMapping::emailFromPrincipalId)
      .collect(Collectors.toSet());

    //
    // Load and initialize the email template.
    //
    var template = MailTemplate.fromResource(PROPOSAL_TEMPLATE);
    template.addContext("input", operation.input(), true);
    template.addContext("user", operation.user());
    template.addContext("joining_user", operation.joiningUser());
    template.addContext("group", operation.group());
    template.addContext("proposal")
      .set("action_uri", actionUri.toString())
      .set("token", TokenObfuscator.encode(token.value()))
      .set("expiry", OffsetDateTime
        .ofInstant(proposal.expiry(), this.options.timeZone)
        .truncatedTo(ChronoUnit.SECONDS)
        .format(DateTimeFormatter.RFC_1123_DATE_TIME));

    try {
      //
      // Send mail to users that can handle the proposal and cc
      // the user that wants to join.
      //
      sendMail(
        recipients,
        List.of(this.emailMapping.emailFromPrincipalId(proposal.user())),
        String.format(
          "%s requests to join %s",
          operation.joiningUser().email,
          operation.group().name()),
        template.evaluate(),
        false);
    }
    catch (EvaluationException e) {
      throw new IllegalArgumentException("The mail template is invalid", e);
    }
  }