Exemple #1
0
        public async Task CreateMessagesOfInvalidUsersForContact(ColidEntryContactInvalidUsersDto cec)
        {
            // It is only possible to send messages to users who are already logged in to COLID, because
            // they are assigned to the user. Therefore external users must be created separately beforehand.
            var userId = await CreateInitialUserForMessages(cec);

            var messageTemplate      = _messageTemplateService.GetOne(MessageType.InvalidUserWarning);
            var messageConfigForUser = await _userService.GetMessageConfigAsync(userId);

            var messageList = new Collection <MessageDto>();

            foreach (var entry in cec.ColidEntries)
            {
                var subject = messageTemplate.Subject.Replace("%COLID_PID_URI%", entry.PidUri.OriginalString).Replace("%COLID_LABEL%", entry.Label);
                var body    = messageTemplate.Body
                              .Replace("%COLID_PID_URI%", entry.PidUri.OriginalString)
                              .Replace("%COLID_LABEL%", entry.Label)
                              .Replace("%INVALID_USERS%", string.Join(", ", entry.InvalidUsers));

                var message = CreateMessageDto(messageConfigForUser, subject, body);
                messageList.Add(message);
            }

            var _ = await _userService.AddMessagesAsync(userId, messageList);
        }
Exemple #2
0
        public async Task <IEnumerable <ColidEntryContactInvalidUsersDto> > CollectAndPrepareContactMessagesForEntries()
        {
            var contactAndEntryList = new List <ColidEntryContactInvalidUsersDto>();
            var adUserEmailSet      = await _reportingService.GetContactsFromAllColidEntries();

            var adUserValidEmailSet = RemoveInvalidEmailsByPattern(adUserEmailSet);
            var contactValidityList = await _appDataService.CheckUsersValidityAsync(adUserValidEmailSet);

            // ad invalid emails by pattern to invalid contacts -> allow any string in reporting service
            var invalidContacts      = contactValidityList.Where(x => !x.AccountEnabled);
            var invalidContactsMails = invalidContacts.Select(c => c.Mail).ToHashSet();

            foreach (var adUserDto in invalidContacts)
            {
                var entityList = await _reportingService.GetContactReferencedEntries(adUserDto.Mail);

                foreach (var colidEntryContactsDto in entityList)
                {
                    if (IsTechnicalUserInEntry(colidEntryContactsDto, adUserDto.Mail))
                    {
                        continue; // then skip message creation
                    }

                    var contactPerson     = DetermineContactPerson(adUserDto.Mail, colidEntryContactsDto, invalidContactsMails);
                    var contactAndEntries = contactAndEntryList.FirstOrDefault(c => c.ContactMail == contactPerson);

                    if (contactAndEntries != null)
                    {
                        if (contactAndEntries.TryGetColidEntry(colidEntryContactsDto.PidUri, out ColidEntryInvalidUsersDto colidEntry))
                        {
                            // append invalid user to existing users' colid entry
                            colidEntry.InvalidUsers.Add(adUserDto.Mail);
                        }
                        else
                        {
                            // create new colid entry for user
                            var ce = new ColidEntryInvalidUsersDto(colidEntryContactsDto.PidUri,
                                                                   colidEntryContactsDto.Label, new HashSet <string> {
                                adUserDto.Mail
                            });
                            contactAndEntries.ColidEntries.Add(ce);
                        }
                    }
                    else
                    {
                        // create new contact message
                        var invalidUserDto = new ColidEntryInvalidUsersDto(colidEntryContactsDto.PidUri,
                                                                           colidEntryContactsDto.Label, new HashSet <string> {
                            adUserDto.Mail
                        });
                        var contactDto = new ColidEntryContactInvalidUsersDto();
                        contactDto.ContactMail = contactPerson;
                        contactDto.ColidEntries.Add(invalidUserDto);
                        contactAndEntryList.Add(contactDto);
                    }
                }
            }

            return(contactAndEntryList);
        }
        public async Task CreateMessagesOfInvalidUsersForContact(ColidEntryContactInvalidUsersDto content)
        {
            using var httpClient = _clientFactory.CreateClient();
            var path = $"{_appDataServiceColidEntriesInvalidUserApi}";

            try
            {
                var accessToken = await _tokenService.GetAccessTokenForWebApiAsync();

                var response = await httpClient.SendRequestWithOptionsAsync(HttpMethod.Put, path, content, accessToken, _cancellationToken, _correlationContext.CorrelationContext);

                response.EnsureSuccessStatusCode();
            }
            catch (AuthenticationException ex)
            {
                _logger.LogError("An error occurred during authentication: ", ex);
            }
        }
Exemple #4
0
        private async Task <Guid> CreateInitialUserForMessages(ColidEntryContactInvalidUsersDto cec)
        {
            try
            {
                return(await _userService.GetIdByEmailAddressAsync(cec.ContactMail));
            }
            catch (EntityNotFoundException)
            {
                // in case, that the user doesn't exist within appdata service, create
                var adUser = await _activeDirectoryService.GetUserAsync(cec.ContactMail);

                var userDto = new UserDto
                {
                    Id           = new Guid(adUser.Id),
                    EmailAddress = adUser.Mail
                };
                var user = await _userService.CreateAsync(userDto);

                return(user.Id);
            }
        }
Exemple #5
0
        public async Task <IActionResult> CreateMessagesOfInvalidUsersForContact([FromBody] ColidEntryContactInvalidUsersDto cec)
        {
            await _messageService.CreateMessagesOfInvalidUsersForContact(cec);

            return(Created("/api/ColidEntries/invalidUser", "created"));
        }