private async Task <bool> HasConnectionTypeAsync(OrganizationConnectionRequestModel model, Guid?connectionId,
                                                         OrganizationConnectionType type)
        {
            var existingConnections = await GetConnectionsAsync(model.OrganizationId, type);

            return(existingConnections.Any(c => c.Type == model.Type && (!connectionId.HasValue || c.Id != connectionId.Value)));
        }
Пример #2
0
        public async Task CreateConnection_OnlyOneConnectionOfEachType(OrganizationConnectionType type,
                                                                       OrganizationConnectionRequestModel model, BillingSyncConfig config, Guid existingEntityId,
                                                                       SutProvider <OrganizationConnectionsController> sutProvider)
        {
            model.Type   = type;
            model.Config = JsonDocumentFromObject(config);
            var typedModel = new OrganizationConnectionRequestModel <BillingSyncConfig>(model);
            var existing   = typedModel.ToData(existingEntityId).ToEntity();

            sutProvider.GetDependency <ICurrentContext>().OrganizationOwner(model.OrganizationId).Returns(true);

            sutProvider.GetDependency <IOrganizationConnectionRepository>().GetByOrganizationIdTypeAsync(model.OrganizationId, type).Returns(new[] { existing });

            var exception = await Assert.ThrowsAsync <BadRequestException>(() => sutProvider.Sut.CreateConnection(model));

            Assert.Contains($"The requested organization already has a connection of type {model.Type}. Only one of each connection type may exist per organization.", exception.Message);
        }
        public async Task <OrganizationConnectionResponseModel> GetConnection(Guid organizationId, OrganizationConnectionType type)
        {
            if (!await HasPermissionAsync(organizationId))
            {
                throw new BadRequestException("Only the owner of an organization can retrieve a connection.");
            }

            var connections = await GetConnectionsAsync(organizationId);

            var connection = connections.FirstOrDefault(c => c.Type == type);

            switch (type)
            {
            case OrganizationConnectionType.CloudBillingSync:
                return(new OrganizationConnectionResponseModel(connection, typeof(BillingSyncConfig)));

            default:
                throw new BadRequestException($"Unkown Organization connection Type: {type}");
            }
        }
Пример #4
0
 public async Task <ICollection <OrganizationConnection> > GetEnabledByOrganizationIdTypeAsync(Guid organizationId, OrganizationConnectionType type) =>
 (await GetByOrganizationIdTypeAsync(organizationId, type)).Where(c => c.Enabled).ToList();
Пример #5
0
        public async Task <ICollection <OrganizationConnection> > GetByOrganizationIdTypeAsync(Guid organizationId, OrganizationConnectionType type)
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                var results = await connection.QueryAsync <OrganizationConnection>(
                    $"[{Schema}].[OrganizationConnection_ReadByOrganizationIdType]",
                    new
                {
                    OrganizationId = organizationId,
                    Type           = type
                },
                    commandType : CommandType.StoredProcedure);

                return(results.ToList());
            }
        }
 private async Task <ICollection <OrganizationConnection> > GetConnectionsAsync(Guid organizationId, OrganizationConnectionType type) =>
 await _organizationConnectionRepository.GetByOrganizationIdTypeAsync(organizationId, type);
        public async Task <OrganizationConnectionResponseModel> GetConnection(Guid organizationId, OrganizationConnectionType type)
        {
            if (!await HasPermissionAsync(organizationId, type))
            {
                throw new BadRequestException($"You do not have permission to retrieve a connection of type {type}.");
            }

            var connections = await GetConnectionsAsync(organizationId, type);

            var connection = connections.FirstOrDefault(c => c.Type == type);

            switch (type)
            {
            case OrganizationConnectionType.CloudBillingSync:
                if (!_globalSettings.SelfHosted)
                {
                    throw new BadRequestException($"Cannot get a {type} connection outside of a self-hosted instance.");
                }
                return(new OrganizationConnectionResponseModel(connection, typeof(BillingSyncConfig)));

            case OrganizationConnectionType.Scim:
                return(new OrganizationConnectionResponseModel(connection, typeof(ScimConfig)));

            default:
                throw new BadRequestException($"Unkown Organization connection Type: {type}");
            }
        }
        public async Task <ICollection <OrganizationConnection> > GetEnabledByOrganizationIdTypeAsync(Guid organizationId, OrganizationConnectionType type)
        {
            using (var scope = ServiceScopeFactory.CreateScope())
            {
                var dbContext   = GetDatabaseContext(scope);
                var connections = await dbContext.OrganizationConnections
                                  .Where(oc => oc.OrganizationId == organizationId && oc.Type == type && oc.Enabled)
                                  .ToListAsync();

                return(Mapper.Map <List <OrganizationConnection> >(connections));
            }
        }