Beispiel #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req)
        {
            string tenantUrl = req.Headers[Constants.HEADER_TENANT_URL];

            if (String.IsNullOrEmpty(tenantUrl))
            {
                return(new BadRequestErrorMessageResult($"GetTenantClientSettings: Header {Constants.HEADER_TENANT_URL}  is missing or wrong"));
            }
            _logger.LogInformation($"GetTenantClientSettings: {Constants.HEADER_TENANT_URL} = {tenantUrl}");
            TenantClientSettings tenantClientSettings = new TenantClientSettings();

            // First try to get tenant settings from database
            tenantClientSettings.Tenant = await _tenantRepository.GetFirstItemOrDefault(t => tenantUrl.StartsWith(t.PrimaryUrl));

            if (null != tenantClientSettings.Tenant)
            {
                _logger.LogInformation($"GetTenantClientSetting({tenantUrl}): Tenant Settings {tenantClientSettings.Tenant.TenantName} found.");
            }
            else
            {
                // If not in database get from static configuration table. This allows that MeetUpPlanner can run withour admin tool
                tenantClientSettings.Tenant = TenantConfig.GetTenant(tenantUrl);
            }

            string key    = Constants.KEY_CLIENT_SETTINGS;
            string tenant = tenantClientSettings.Tenant.TenantKey;

            if (null != tenant)
            {
                key += "-" + tenant;
            }
            tenantClientSettings.Client = await _cosmosRepository.GetItemByKey(key);

            if (null == tenantClientSettings.Client)
            {
                tenantClientSettings.Client = new ClientSettings()
                {
                    Title            = Constants.DEFAULT_TITLE,
                    FurtherInfoLink  = Constants.DEFAULT_LINK,
                    FurtherInfoTitle = Constants.DEFAULT_LINK_TITLE,
                    Disclaimer       = Constants.DEFAULT_DISCLAIMER,
                    GuestDisclaimer  = Constants.DEFAULT_GUEST_DISCLAIMER
                };
            }
            return(new OkObjectResult(tenantClientSettings));
        }
        public async Task <IActionResult> GetTenantClientSettings([FromHeader(Name = "x-meetup-tenant-url")] string tenantUrl)
        {
            TenantClientSettings tenantClientSettings = await _meetUpFunctions.GetTenantClientSettings(tenantUrl);

            return(Ok(tenantClientSettings));
        }