public async Task <IViewComponentResult> InvokeAsync(string selectedOwnerId, string selectedRepoId, string area)
        {
            if (User?.Identity == null || !User.Identity.IsAuthenticated || !ClaimsHelper.OwnerExistsInUserClaims(User.Identity as ClaimsIdentity, selectedOwnerId))
            {
                // dash view model
                var publicDash = new DashboardMenuViewModel
                {
                    SelectedOwnerId = selectedOwnerId,
                    SelectedRepoId  = selectedRepoId,
                    ActiveArea      = area
                };
                //note: when public, the avatar URL cannot be retrieved from the user claims, so needs to be retrieved from data storage / cache
                return(View("Public", publicDash));
            }

            // user view model
            var uvm = new UserViewModel();

            uvm.Populate(User.Identity as ClaimsIdentity);

            // dash view model
            this.DashboardMenuViewModel = new DashboardMenuViewModel
            {
                SelectedOwnerId = selectedOwnerId,
                SelectedRepoId  = selectedRepoId,
                UserViewModel   = uvm,
                ActiveArea      = area
            };
            this.DashboardMenuViewModel.Owners.Add(uvm.UserOwner);
            this.DashboardMenuViewModel.Owners.AddRange(uvm.Organisations);
            this.DashboardMenuViewModel.SelectedOwnerAvatarUrl = this.DashboardMenuViewModel.Owners.FirstOrDefault(o => o.OwnerId.Equals(selectedOwnerId, StringComparison.InvariantCultureIgnoreCase))?.AvatarUrl;
            await PopulateRepositoryList();

            return(View(this.DashboardMenuViewModel));
        }
Exemplo n.º 2
0
        public async Task <IViewComponentResult> InvokeAsync(string ownerId, string repoId, string datasetId)
        {
            try
            {
                if (string.IsNullOrEmpty(ownerId) || string.IsNullOrEmpty(repoId) ||
                    string.IsNullOrEmpty(datasetId))
                {
                    return(View("Empty"));
                }

                var user    = Request.HttpContext.User;
                var isAdmin = user?.Identity.Name != null && user.Identity.IsAuthenticated &&
                              ClaimsHelper.OwnerExistsInUserClaims(user.Identity as ClaimsIdentity, ownerId);
                var dataset =
                    await _datasetStore.GetDatasetInfoAsync(ownerId, repoId, datasetId);

                return(View("Default", new DatasetViewModel(_uriService, dataset, isOwner: isAdmin)));
            }
            catch (Exception e)
            {
                return(View("Error", e));
            }
        }