public static bool IsCan(this IAuthorityProvider authorityProvider, string authorityName, long?entityId) => authorityProvider.IsCan(new[] { authorityName }, entityId);
public ActionResult Index() { var projects = _apiService.GetProjectsByUser().Select(_ => _.ToModel()).ToArray(); var model = new ProjectsViewModel { IsCanCreateProject = _authorityProvider.IsCan(Authorities.UI.Project.ProjectsList.Create, null) }; if (projects.Length == 0) { return(View(model)); } var currentUser = _apiService.GetCurrentUser(); var roles = _apiService.GetRoles(currentUser.Id); var projectViewModels = projects .Select(p => new ProjectViewModel { IsCanEdit = _authorityProvider.IsCan(new Authorities.UI.Project.Settings().All(), p.Id), IsCanViewHealthStat = _authorityProvider.IsCan(Authorities.UI.Project.ProjectsList.Stat.Health, p.Id), IsCanViewMetricsStat = _authorityProvider.IsCan(Authorities.UI.Project.ProjectsList.Stat.Metrics, p.Id), IsCanViewVulnerabilitiesStat = _authorityProvider.IsCan(Authorities.UI.Project.ProjectsList.Stat.Vulnerabilities, p.Id), Project = p, Roles = roles .Where(r => (r.ProjectId == p.Id) || (r.ProjectId == null)) .Select(_ => _.ToModel()) .ToArray(), ScanCore = _apiService.GetScanCore(p.Id).ToModel(), HealthTable = _apiService.GetProjectHealthStat(p.Id).ToModel(), MetricsTable = _apiService.GetProjectMetricStat(p.Id).ToModel(), VulnerabilityTable = _apiService.GetProjectVulnerabilitiesStat(p.Id).ToModel() }); model.Projects = projectViewModels.ToList(); return(View(model)); }