add mail invite (#16)

This commit is contained in:
Anatolii Karlov 2021-02-12 20:22:50 +07:00 committed by GitHub
parent 63b60592de
commit 57122b381a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 85 additions and 6 deletions

View File

@ -55,6 +55,11 @@
<artifactId>swag-organizations</artifactId>
<version>1.16-8129cc0-server</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>damsel</artifactId>
<version>1.475-bde841f</version>
</dependency>
<!--spring-->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -0,0 +1,22 @@
package com.rbkmoney.orgmanager.config;
import com.rbkmoney.damsel.message_sender.MessageSenderSrv;
import com.rbkmoney.woody.thrift.impl.http.THSpawnClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import java.io.IOException;
@Configuration
public class DudoserConfig {
@Bean
public MessageSenderSrv.Iface dudoserSrv(@Value("${dudoser.url}") Resource resource,
@Value("${dudoser.networkTimeout}") int networkTimeout) throws IOException {
return new THSpawnClientBuilder()
.withNetworkTimeout(networkTimeout)
.withAddress(resource.getURI()).build(MessageSenderSrv.Iface.class);
}
}

View File

@ -4,12 +4,9 @@ import com.rbkmoney.orgmanager.converter.InvitationConverter;
import com.rbkmoney.orgmanager.entity.InvitationEntity;
import com.rbkmoney.orgmanager.repository.InvitationRepository;
import com.rbkmoney.orgmanager.repository.OrganizationRepository;
import com.rbkmoney.swag.organizations.model.InlineObject1;
import com.rbkmoney.swag.organizations.model.Invitation;
import com.rbkmoney.swag.organizations.model.InvitationListResult;
import com.rbkmoney.swag.organizations.model.InvitationRequest;
import com.rbkmoney.swag.organizations.model.InvitationStatusName;
import com.rbkmoney.swag.organizations.model.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@ -25,11 +22,13 @@ import static java.util.stream.Collectors.toList;
@Service
@RequiredArgsConstructor
@Slf4j
public class InvitationService {
private final InvitationConverter invitationConverter;
private final InvitationRepository invitationRepository;
private final OrganizationRepository organizationRepository;
private final MailInviteMessageSender mailInviteMessageSender;
// TODO [a.romanov]: idempotency
public ResponseEntity<Invitation> create(
@ -40,6 +39,9 @@ public class InvitationService {
InvitationEntity savedEntity = invitationRepository.save(entity);
Invitation savedInvitation = invitationConverter.toDomain(savedEntity);
mailInviteMessageSender.send(savedInvitation);
return ResponseEntity
.status(HttpStatus.CREATED)
.body(savedInvitation);

View File

@ -0,0 +1,38 @@
package com.rbkmoney.orgmanager.service;
import com.rbkmoney.damsel.message_sender.MailBody;
import com.rbkmoney.damsel.message_sender.Message;
import com.rbkmoney.damsel.message_sender.MessageMail;
import com.rbkmoney.damsel.message_sender.MessageSenderSrv;
import com.rbkmoney.swag.organizations.model.Invitation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@RequiredArgsConstructor
@Slf4j
public class MailInviteMessageSender {
@Value("${dashboard.url}")
private String dashboardUrl;
private final MessageSenderSrv.Iface dudoserClient;
public void send(Invitation invitation) {
try {
MessageMail messageMail = new MessageMail();
messageMail.setMailBody(new MailBody(dashboardUrl + invitation.getAcceptToken()));
messageMail.setToEmails(List.of(invitation.getInvitee().getContact().getEmail()));
messageMail.setSubject("Подтверждение вступления в организацию");
messageMail.setFromEmail("no-reply@rbkmoney.com");
dudoserClient.send(Message.message_mail(messageMail));
} catch (Exception ex) {
log.warn("dudoserClient error", ex);
}
}
}

View File

@ -61,3 +61,10 @@ scheduler:
enabled: false
lockFor: 30m
checkStatusDelay: 10000
dudoser:
url: http://dudoser:8022/dudos
networkTimeout: 10000
dashboard:
url: https://dashboard.rbk.money/organizations/accept-invitation/

View File

@ -5,6 +5,7 @@ import com.rbkmoney.orgmanager.entity.InvitationEntity;
import com.rbkmoney.orgmanager.repository.InvitationRepository;
import com.rbkmoney.orgmanager.repository.OrganizationRepository;
import com.rbkmoney.swag.organizations.model.*;
import org.apache.thrift.TException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@ -25,12 +26,14 @@ public class InvitationServiceTest {
@Mock private InvitationConverter invitationConverter;
@Mock private InvitationRepository invitationRepository;
@Mock private OrganizationRepository organizationRepository;
@Mock
private MailInviteMessageSender mailInviteMessageSender;
@InjectMocks
private InvitationService service;
@Test
public void shouldCreate() {
public void shouldCreate() throws TException {
// Given
InvitationRequest invitation = new InvitationRequest();
InvitationEntity entity = new InvitationEntity();
@ -50,6 +53,8 @@ public class InvitationServiceTest {
// Then
verify(invitationRepository, times(1))
.save(entity);
verify(mailInviteMessageSender, times(1))
.send(any());
assertThat(response.getStatusCode())
.isEqualTo(HttpStatus.CREATED);
assertThat(response.getBody())