public async Task <ActionResult> GetMessageBoxInstance(int instanceOwnerPartyId, Guid instanceGuid, [FromQuery] string language) { string[] acceptedLanguages = { "en", "nb", "nn" }; string languageId = "nb"; if (language != null && acceptedLanguages.Contains(language.ToLower())) { languageId = language; } string instanceId = $"{instanceOwnerPartyId}/{instanceGuid}"; Instance instance = await _instanceRepository.GetOne(instanceId, instanceOwnerPartyId); if (instance == null) { return(NotFound($"Could not find instance {instanceId}")); } MessageBoxInstance messageBoxInstance = InstanceHelper.ConvertToMessageBoxInstance(instance); // Setting these two properties could be handled by custom PEP. messageBoxInstance.AllowDelete = true; messageBoxInstance.AuthorizedForWrite = true; Dictionary <string, Dictionary <string, string> > appTitle = await _applicationRepository.GetAppTitles(new List <string> { instance.AppId }); InstanceHelper.AddTitleToInstances(new List <MessageBoxInstance> { messageBoxInstance }, appTitle, languageId); return(Ok(messageBoxInstance)); }
public async Task <ActionResult> GetMessageBoxInstanceList(int instanceOwnerPartyId, [FromQuery] string state, [FromQuery] string language) { string[] allowedStates = { "active", "archived", "deleted" }; string[] acceptedLanguages = { "en", "nb", "nn" }; string languageId = "nb"; if (string.IsNullOrEmpty(state)) { return(BadRequest($"State is empty. Please provide on of: {string.Join(", ", allowedStates)}")); } state = state.ToLower(); if (!allowedStates.Contains(state)) { return(BadRequest($"Invalid instance state. Please provide on of: {string.Join(", ", allowedStates)}")); } if (language != null && acceptedLanguages.Contains(language.ToLower())) { languageId = language; } List <Instance> allInstances = await _instanceRepository.GetInstancesInStateOfInstanceOwner(instanceOwnerPartyId, state); if (allInstances.Count <= 0) { return(Ok(new List <MessageBoxInstance>())); } // removing properties only used for active messageBoxInstances if (!state.Equals("active")) { allInstances.ForEach(i => i.DueBefore = null); } List <MessageBoxInstance> autorizedInstances = await _authorizationHelper.AuthorizeMesseageBoxInstances(HttpContext.User, allInstances); List <string> appIds = autorizedInstances.Select(i => InstanceHelper.GetAppId(i)).Distinct().ToList(); Dictionary <string, Dictionary <string, string> > appTitles = await _applicationRepository.GetAppTitles(appIds); List <MessageBoxInstance> messageBoxInstances = InstanceHelper.AddTitleToInstances(autorizedInstances, appTitles, languageId); return(Ok(messageBoxInstances)); }