public OrganizationUserAttribute( OrganizationUserStatusType status = OrganizationUserStatusType.Confirmed, OrganizationUserType type = OrganizationUserType.User) { _status = status; _type = type; }
public async Task <OrganizationUser> InviteUserAsync(Guid organizationId, Guid invitingUserId, string email, OrganizationUserType type, bool accessAll, string externalId, IEnumerable <SelectionReadOnly> collections) { var organization = await _organizationRepository.GetByIdAsync(organizationId); if (organization == null) { throw new NotFoundException(); } if (organization.Seats.HasValue) { var userCount = await _organizationUserRepository.GetCountByOrganizationIdAsync(organizationId); if (userCount >= organization.Seats.Value) { throw new BadRequestException("You have reached the maximum number of users " + $"({organization.Seats.Value}) for this organization."); } } // Make sure user is not already invited var existingOrgUser = await _organizationUserRepository.GetByOrganizationAsync(organizationId, email); if (existingOrgUser != null) { throw new BadRequestException("User already invited."); } var orgUser = new OrganizationUser { OrganizationId = organizationId, UserId = null, Email = email.ToLowerInvariant(), Key = null, Type = type, Status = OrganizationUserStatusType.Invited, AccessAll = accessAll, ExternalId = externalId, CreationDate = DateTime.UtcNow, RevisionDate = DateTime.UtcNow }; if (!orgUser.AccessAll && collections.Any()) { await _organizationUserRepository.CreateAsync(orgUser, collections); } else { await _organizationUserRepository.CreateAsync(orgUser); } await SendInviteAsync(orgUser); return(orgUser); }
public async Task <OrganizationUser> InviteUserAsync(Guid organizationId, Guid invitingUserId, string email, OrganizationUserType type, bool accessAll, string externalId, IEnumerable <SelectionReadOnly> collections) { var result = await InviteUserAsync(organizationId, invitingUserId, new List <string> { email }, type, accessAll, externalId, collections); return(result.FirstOrDefault()); }
public async Task <OrganizationUser> InviteUserAsync(Guid organizationId, Guid?invitingUserId, string email, OrganizationUserType type, bool accessAll, string externalId, IEnumerable <SelectionReadOnly> collections) { var results = await InviteUserAsync(organizationId, invitingUserId, new List <string> { email }, type, accessAll, externalId, collections); var result = results.FirstOrDefault(); if (result == null) { throw new BadRequestException("This user has already been invited."); } return(result); }
[EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Invited, true, true, false)] // User not minStatus public async void GetManyByTypeApplicableToUser_Works_DataMatches_Corre( // Inline data OrganizationUserType userType, bool canManagePolicies, OrganizationUserStatusType orgUserStatus, bool policyEnabled, bool policySameType, bool isProvider, // Auto data - models TableModel.Policy policy, TableModel.User user, TableModel.Organization organization, TableModel.OrganizationUser orgUser, TableModel.Provider.Provider provider, TableModel.Provider.ProviderOrganization providerOrganization, TableModel.Provider.ProviderUser providerUser, PolicyCompareIncludingOrganization equalityComparer, // Auto data - EF repos List <EfRepo.PolicyRepository> suts, List <EfRepo.UserRepository> efUserRepository, List <EfRepo.OrganizationRepository> efOrganizationRepository, List <EfRepo.OrganizationUserRepository> efOrganizationUserRepository, List <EfRepo.ProviderRepository> efProviderRepository, List <EfRepo.ProviderOrganizationRepository> efProviderOrganizationRepository, List <EfRepo.ProviderUserRepository> efProviderUserRepository, // Auto data - SQL repos SqlRepo.PolicyRepository sqlPolicyRepo, SqlRepo.UserRepository sqlUserRepo, SqlRepo.OrganizationRepository sqlOrganizationRepo, SqlRepo.ProviderRepository sqlProviderRepo, SqlRepo.OrganizationUserRepository sqlOrganizationUserRepo, SqlRepo.ProviderOrganizationRepository sqlProviderOrganizationRepo, SqlRepo.ProviderUserRepository sqlProviderUserRepo ) { // Combine EF and SQL repos into one list per type var policyRepos = suts.ToList <IPolicyRepository>(); policyRepos.Add(sqlPolicyRepo); var userRepos = efUserRepository.ToList <IUserRepository>(); userRepos.Add(sqlUserRepo); var orgRepos = efOrganizationRepository.ToList <IOrganizationRepository>(); orgRepos.Add(sqlOrganizationRepo); var orgUserRepos = efOrganizationUserRepository.ToList <IOrganizationUserRepository>(); orgUserRepos.Add(sqlOrganizationUserRepo); var providerRepos = efProviderRepository.ToList <IProviderRepository>(); providerRepos.Add(sqlProviderRepo); var providerOrgRepos = efProviderOrganizationRepository.ToList <IProviderOrganizationRepository>(); providerOrgRepos.Add(sqlProviderOrganizationRepo); var providerUserRepos = efProviderUserRepository.ToList <IProviderUserRepository>(); providerUserRepos.Add(sqlProviderUserRepo); // Arrange data var savedPolicyType = PolicyType.SingleOrg; var queriedPolicyType = policySameType ? savedPolicyType : PolicyType.DisableSend; orgUser.Type = userType; orgUser.Status = orgUserStatus; var permissionsData = new Permissions { ManagePolicies = canManagePolicies }; orgUser.Permissions = JsonSerializer.Serialize(permissionsData, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }); policy.Enabled = policyEnabled; policy.Type = savedPolicyType; var results = new List <TableModel.Policy>(); foreach (var policyRepo in policyRepos) { var i = policyRepos.IndexOf(policyRepo); // Seed database var savedUser = await userRepos[i].CreateAsync(user); var savedOrg = await orgRepos[i].CreateAsync(organization); orgUser.UserId = savedUser.Id; orgUser.OrganizationId = savedOrg.Id; await orgUserRepos[i].CreateAsync(orgUser); if (isProvider) { var savedProvider = await providerRepos[i].CreateAsync(provider); providerOrganization.OrganizationId = savedOrg.Id; providerOrganization.ProviderId = savedProvider.Id; await providerOrgRepos[i].CreateAsync(providerOrganization); providerUser.UserId = savedUser.Id; providerUser.ProviderId = savedProvider.Id; await providerUserRepos[i].CreateAsync(providerUser); } policy.OrganizationId = savedOrg.Id; await policyRepo.CreateAsync(policy); if (suts.Contains(policyRepo)) { (policyRepo as BaseEntityFrameworkRepository).ClearChangeTracking(); } // Act var result = await policyRepo.GetManyByTypeApplicableToUserIdAsync(savedUser.Id, queriedPolicyType, OrganizationUserStatusType.Accepted); results.Add(result.FirstOrDefault()); } // Assert var distinctItems = results.Distinct(equalityComparer); Assert.True(results.All(r => r == null) || !distinctItems.Skip(1).Any()); }
public OrganizationUserCustomization(OrganizationUserStatusType status, OrganizationUserType type) { Status = status; Type = type; }
public async Task <List <OrganizationUser> > InviteUserAsync(Guid organizationId, Guid?invitingUserId, IEnumerable <string> emails, OrganizationUserType type, bool accessAll, string externalId, IEnumerable <SelectionReadOnly> collections) { var organization = await GetOrgById(organizationId); if (organization == null) { throw new NotFoundException(); } if (type == OrganizationUserType.Owner && invitingUserId.HasValue) { var invitingUserOrgs = await _organizationUserRepository.GetManyByUserAsync(invitingUserId.Value); var anyOwners = invitingUserOrgs.Any( u => u.OrganizationId == organizationId && u.Type == OrganizationUserType.Owner); if (!anyOwners) { throw new BadRequestException("Only owners can invite new owners."); } } var orgUsers = new List <OrganizationUser>(); foreach (var email in emails) { // Make sure user is not already invited var existingOrgUserCount = await _organizationUserRepository.GetCountByOrganizationAsync( organizationId, email, false); if (existingOrgUserCount > 0) { continue; } var orgUser = new OrganizationUser { OrganizationId = organizationId, UserId = null, Email = email.ToLowerInvariant(), Key = null, Type = type, Status = OrganizationUserStatusType.Invited, AccessAll = accessAll, ExternalId = externalId, CreationDate = DateTime.UtcNow, RevisionDate = DateTime.UtcNow }; if (!orgUser.AccessAll && collections.Any()) { await _organizationUserRepository.CreateAsync(orgUser, collections); } else { await _organizationUserRepository.CreateAsync(orgUser); } await SendInviteAsync(orgUser); await _eventService.LogOrganizationUserEventAsync(orgUser, EventType.OrganizationUser_Invited); orgUsers.Add(orgUser); } return(orgUsers); }