public async Task <IActionResult> Edit(EditOpenIdScopeViewModel model, string returnUrl = null) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageScopes)) { return(Forbid()); } var scope = await _scopeManager.FindByPhysicalIdAsync(model.Id); if (scope == null) { return(NotFound()); } if (ModelState.IsValid) { var other = await _scopeManager.FindByNameAsync(model.Name); if (other != null && !string.Equals( await _scopeManager.GetIdAsync(other), await _scopeManager.GetIdAsync(scope))) { ModelState.AddModelError(nameof(model.Name), S["The name is already taken by another scope."]); } } if (!ModelState.IsValid) { ViewData["ReturnUrl"] = returnUrl; return(View(model)); } var descriptor = new OpenIdScopeDescriptor(); await _scopeManager.PopulateAsync(descriptor, scope); descriptor.Description = model.Description; descriptor.DisplayName = model.DisplayName; descriptor.Name = model.Name; descriptor.Resources.Clear(); if (!string.IsNullOrEmpty(model.Resources)) { descriptor.Resources.UnionWith(model.Resources.Split(' ', StringSplitOptions.RemoveEmptyEntries)); } descriptor.Resources.UnionWith(model.Tenants .Where(tenant => tenant.Selected) .Where(tenant => !string.Equals(tenant.Name, _shellSettings.Name)) .Select(tenant => OpenIdConstants.Prefixes.Tenant + tenant.Name)); await _scopeManager.UpdateAsync(scope, descriptor); if (string.IsNullOrEmpty(returnUrl)) { return(RedirectToAction("Index")); } return(LocalRedirect(returnUrl)); }
public async Task <IActionResult> Edit(string id, string returnUrl = null) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageScopes)) { return(Forbid()); } var scope = await _scopeManager.FindByPhysicalIdAsync(id); if (scope == null) { return(NotFound()); } var model = new EditOpenIdScopeViewModel { Description = await _scopeManager.GetDescriptionAsync(scope), DisplayName = await _scopeManager.GetDisplayNameAsync(scope), Id = await _scopeManager.GetPhysicalIdAsync(scope), Name = await _scopeManager.GetNameAsync(scope) }; var resources = await _scopeManager.GetResourcesAsync(scope); model.Resources = string.Join(" ", from resource in resources where !string.IsNullOrEmpty(resource) && !resource.StartsWith(OpenIdConstants.Prefixes.Tenant, StringComparison.Ordinal) select resource); foreach (var tenant in _shellHost.GetAllSettings().Where(s => s.State == TenantState.Running)) { model.Tenants.Add(new EditOpenIdScopeViewModel.TenantEntry { Current = string.Equals(tenant.Name, _shellSettings.Name), Name = tenant.Name, Selected = resources.Contains(OpenIdConstants.Prefixes.Tenant + tenant.Name) }); } ViewData["ReturnUrl"] = returnUrl; return(View(model)); }