Beispiel #1
0
        [ApiExplorerSettings(IgnoreApi = true)] //make sure this api is not visible in docs!!! it's kinda private and while should be available it should not be freely used really
        public async Task <IActionResult> GetUserConfigurationAsync([FromQuery] UserConfigurationQuery input, [FromQuery] string token)
        {
            try
            {
                var cfg = Cartomatic.Utils.NetCoreConfig.GetNetCoreConfig();

                if (token != cfg.GetSection("AccessTokens:Auth").Get <string>())
                {
                    return(Unauthorized());
                }

                return(Ok(await MapHive.Core.Configuration.UserConfiguration.GetAsync(GetDefaultDbContext(), input)));
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }
        /// <summary>
        /// Performs the actual core api inspection to obtain a user config for the callee
        /// </summary>
        /// <param name="actionContext"></param>
        /// <param name="q"></param>
        /// <returns></returns>
        protected async Task GetUserConfigurationAsync(ActionExecutingContext actionContext, UserConfigurationQuery q)
        {
            var cached = Cache.Get(q.CacheKey);

            if (cached.Valid)
            {
                actionContext.HttpContext.Items[nameof(UserConfiguration)] = cached.Item;
                return;
            }

            //reset
            actionContext.HttpContext.Items[nameof(UserConfiguration)] = null;

            //cached does not exist or has expired, so basically need to perform a call to the core api to obtain the user cfg
            var userCfg =
                await(actionContext.Controller as BaseController)
                .CoreApiCall <MapHive.Core.Configuration.UserConfiguration>(
                    "configuration/user",
                    queryParams: new Dictionary <string, object>
            {
                { nameof(q.UserId), q.UserId },
                { nameof(q.AppNames), q.AppNames },
                { nameof(q.Ip), q.Ip },
                { nameof(q.Referrer), q.Referrer },
                { nameof(q.TokenId), q.TokenId },
                { nameof(q.OrganizationId), q.OrganizationId },
                { "token", Cartomatic.Utils.NetCoreConfig.GetNetCoreConfig().GetSection("AccessTokens:Auth").Get <string>() }
            },

                    transferRequestHdrs: false
                    );

            //because the db encryption does actually depend on the query sent to the usercfg, need to decrypt it as it is only known here...
            userCfg?.Output?.DecryptOrgDbs(q);

            //cache the data for further usage
            if (userCfg != null)
            {
                Cache.Set(q.CacheKey, userCfg.Output);
            }

            actionContext.HttpContext.Items[nameof(UserConfiguration)] = userCfg?.Output;
        }