Пример #1
0
 public async Task InviteUser_NoEmails_Throws(Organization organization, OrganizationUser invitor,
                                              OrganizationUserInvite invite, SutProvider <OrganizationService> sutProvider)
 {
     invite.Emails = null;
     sutProvider.GetDependency <IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
     await Assert.ThrowsAsync <NotFoundException>(
         () => sutProvider.Sut.InviteUserAsync(organization.Id, invitor.UserId, null, invite));
 }
Пример #2
0
        public async Task <IActionResult> Post([FromBody] MemberCreateRequestModel model)
        {
            var associations = model.Collections?.Select(c => c.ToSelectionReadOnly());
            var invite       = new OrganizationUserInvite
            {
                Emails = new List <string> {
                    model.Email
                },
                Type        = model.Type.Value,
                AccessAll   = model.AccessAll.Value,
                Collections = associations
            };
            var userPromise = await _organizationService.InviteUserAsync(_currentContext.OrganizationId.Value, null, model.ExternalId, invite);

            var user     = userPromise.FirstOrDefault();
            var response = new MemberResponseModel(user, associations);

            return(new JsonResult(response));
        }
Пример #3
0
        public async Task InviteUser_Passes(Organization organization, OrganizationUserInvite invite,
                                            OrganizationUser invitor, SutProvider <OrganizationService> sutProvider)
        {
            invitor.Permissions = JsonSerializer.Serialize(new Permissions()
            {
                ManageUsers = true
            },
                                                           new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
            });

            var organizationRepository     = sutProvider.GetDependency <IOrganizationRepository>();
            var organizationUserRepository = sutProvider.GetDependency <IOrganizationUserRepository>();
            var eventService = sutProvider.GetDependency <IEventService>();

            organizationRepository.GetByIdAsync(organization.Id).Returns(organization);
            organizationUserRepository.GetManyByUserAsync(invitor.UserId.Value).Returns(new List <OrganizationUser> {
                invitor
            });

            await sutProvider.Sut.InviteUserAsync(organization.Id, invitor.UserId, null, invite);
        }
Пример #4
0
        public async Task InviteUser_NoPermissionsObject_Passes(Organization organization, OrganizationUserInvite invite,
                                                                OrganizationUser invitor, SutProvider <OrganizationService> sutProvider)
        {
            invite.Permissions = null;
            var organizationRepository     = sutProvider.GetDependency <IOrganizationRepository>();
            var organizationUserRepository = sutProvider.GetDependency <IOrganizationUserRepository>();
            var eventService = sutProvider.GetDependency <IEventService>();

            organizationRepository.GetByIdAsync(organization.Id).Returns(organization);
            organizationUserRepository.GetManyByUserAsync(invitor.UserId.Value).Returns(new List <OrganizationUser> {
                invitor
            });

            await sutProvider.Sut.InviteUserAsync(organization.Id, invitor.UserId, null, invite);
        }
Пример #5
0
        public async Task InviteUser_CustomUserConfiguringAdmin_Throws(Organization organization, OrganizationUserInvite invite,
                                                                       OrganizationUser invitor, SutProvider <OrganizationService> sutProvider)
        {
            invitor.Permissions = JsonSerializer.Serialize(new Permissions()
            {
                ManageUsers = true
            },
                                                           new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
            });

            var organizationRepository     = sutProvider.GetDependency <IOrganizationRepository>();
            var organizationUserRepository = sutProvider.GetDependency <IOrganizationUserRepository>();

            organizationRepository.GetByIdAsync(organization.Id).Returns(organization);
            organizationUserRepository.GetManyByUserAsync(invitor.UserId.Value).Returns(new List <OrganizationUser> {
                invitor
            });

            var exception = await Assert.ThrowsAsync <BadRequestException>(
                () => sutProvider.Sut.InviteUserAsync(organization.Id, invitor.UserId, null, invite));

            Assert.Contains("can not manage admins", exception.Message.ToLowerInvariant());
        }
Пример #6
0
        public async Task InviteUser_NonAdminConfiguringAdmin_Throws(Organization organization, OrganizationUserInvite invite,
                                                                     OrganizationUser invitor, SutProvider <OrganizationService> sutProvider)
        {
            var organizationRepository     = sutProvider.GetDependency <IOrganizationRepository>();
            var organizationUserRepository = sutProvider.GetDependency <IOrganizationUserRepository>();

            organizationRepository.GetByIdAsync(organization.Id).Returns(organization);
            organizationUserRepository.GetManyByUserAsync(invitor.Id).Returns(new List <OrganizationUser> {
                invitor
            });

            var exception = await Assert.ThrowsAsync <BadRequestException>(
                () => sutProvider.Sut.InviteUserAsync(organization.Id, invitor.UserId, null, invite));

            Assert.Contains("only owners and admins", exception.Message.ToLowerInvariant());
        }