public async Task Invite_SpecificSharingEnabled_UserInvitedTwiceButWithSameCode() { var env = new TestEnvironment(); const string email = "*****@*****.**"; SFProjectSecret projectSecret = env.ProjectSecrets.Get(Project03); Assert.That(projectSecret.ShareKeys.Any(sk => sk.Email == email), Is.False, "setup"); env.SecurityService.GenerateKey().Returns("1111", "3333"); await env.Service.InviteAsync(User01, Project03, email); await env.EmailService.Received(1).SendEmailAsync(email, Arg.Any <string>(), Arg.Is <string>(body => body.Contains($"http://localhost/projects/{Project03}?sharing=true&shareKey=1111"))); // Code was recorded in database projectSecret = env.ProjectSecrets.Get(Project03); Assert.That(projectSecret.ShareKeys.Any(sk => sk.Email == email), Is.True); await env.Service.InviteAsync(User01, Project03, email); // Invitation email was sent again, but with first code await env.EmailService.Received(2).SendEmailAsync(Arg.Is(email), Arg.Any <string>(), Arg.Is <string>(body => body.Contains($"http://localhost/projects/{Project03}?sharing=true&shareKey=1111"))); projectSecret = env.ProjectSecrets.Get(Project03); Assert.That(projectSecret.ShareKeys.Single(sk => sk.Email == email).Key, Is.EqualTo("1111"), "Code should not have been changed"); }
public async Task InitAsync(UserSecret currentUserSecret, SFProjectSecret projectSecret, List <User> ptUsers, string paratextProjectId) { _currentUserSecret = currentUserSecret; _currentParatextUsername = _paratextService.GetParatextUsername(currentUserSecret); _projectSecret = projectSecret; _idToSyncUser.Clear(); _usernameToSyncUser.Clear(); foreach (SyncUser syncUser in projectSecret.SyncUsers) { _idToSyncUser[syncUser.Id] = syncUser; _usernameToSyncUser[syncUser.ParatextUsername] = syncUser; } _ptProjectUsersWhoCanWriteNotes = new HashSet <string>(); IReadOnlyDictionary <string, string> roles = await _paratextService.GetProjectRolesAsync(currentUserSecret, paratextProjectId); var ptRolesCanWriteNote = new HashSet <string> { SFProjectRole.Administrator, SFProjectRole.Translator, SFProjectRole.Consultant, SFProjectRole.WriteNote }; foreach (User user in ptUsers) { // Populate the list with all Paratext users belonging to the project and who can write notes if (roles.TryGetValue(user.ParatextId, out string role) && ptRolesCanWriteNote.Contains(role)) { _ptProjectUsersWhoCanWriteNotes.Add(user.Id); } } }
public async Task InviteAsync_SpecificSharingEnabled_UserInvited() { var env = new TestEnvironment(); const string email = "*****@*****.**"; await env.Service.InviteAsync(User01, Project03, email); await env.EmailService.Received(1).SendEmailAsync(email, Arg.Any <string>(), Arg.Is <string>(body => body.Contains($"http://localhost/projects/{Project03}?sharing=true&shareKey=1234abc") && body.Contains("link will only work for this email address"))); // Code was recorded in database and email address was encoded in ShareKeys SFProjectSecret projectSecret = env.ProjectSecrets.Get(Project03); Assert.That(projectSecret.ShareKeys.Single(sk => sk.Email == email).Key, Is.EqualTo("1234abc")); }