Exemplo n.º 1
0
        public async Task <ActionResult> Owner(string ownerId)
        {
            if (string.IsNullOrEmpty(ownerId))
            {
                return(RedirectToAction("Index", "Home"));
            }

            try
            {
                var ownerSettings = await _ownerSettingsStore.GetOwnerSettingsAsync(ownerId);

                var portalViewModel = new PortalViewModel(ownerSettings);

                // repos
                try
                {
                    var repos = await _repoSettingsStore.GetRepoSettingsForOwnerAsync(ownerId);

                    portalViewModel.RepoIds = repos.Select(r => r.RepositoryId).ToList();
                }
                catch (Exception e)
                {
                    Log.Error(e, "Error getting repositories for {0}", ownerId);
                }

                return(View("Index", portalViewModel));
            }
            catch (OwnerSettingsNotFoundException)
            {
                //redirect to a friendly warning page
                return(View("OwnerNotFound"));
            }
        }
Exemplo n.º 2
0
        private async Task <OwnerSettingsViewModel> GetOwnerSettingsViewModel(string ownerId)
        {
            if (string.IsNullOrEmpty(ownerId))
            {
                return(null);
            }
            try
            {
                var os = await _ownerSettingsStore.GetOwnerSettingsAsync(ownerId);

                var osvm = new OwnerSettingsViewModel(os);
                return(osvm);
            }
            catch (OwnerSettingsNotFoundException)
            {
                Log.Debug("No owner settings found for owner '{0}'", ownerId);
                return(new OwnerSettingsViewModel {
                    OwnerId = ownerId
                });
            }
            catch (Exception e)
            {
                Log.Error(e, "Error retrieving owner settings with owner id '{0}'", ownerId);
                throw;
            }
        }
Exemplo n.º 3
0
        public async Task <OwnerSettings> CheckOwnerSettingsAsync(ClaimsPrincipal user, string ownerId)
        {
            var isOrg = await CheckGitHubOwner(user.Identity, ownerId);

            try
            {
                var ownerSettings = await _ownerSettingsStore.GetOwnerSettingsAsync(ownerId);

                return(ownerSettings);
            }
            catch (OwnerSettingsNotFoundException)
            {
                var newOwnerSettings = new OwnerSettings
                {
                    OwnerId = ownerId,
                    IsOrg   = isOrg
                };


                await _ownerSettingsStore.CreateOrUpdateOwnerSettingsAsync(newOwnerSettings);

                return(newOwnerSettings);
            }
            catch (Exception e)
            {
                Log.Error($"Error checking owner settings for '{ownerId}", e);
                throw;
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Delete(DeleteAccountViewModel davm)
        {
            try
            {
                if (!ModelState.IsValid || !davm.Confirm)
                {
                    ModelState.AddModelError("", "You must confirm that you want to delete your user account and associated settings.");
                    return(View("Delete"));
                }
                var deleted = await _userStore.DeleteUserAsync(User.Identity.Name);

                if (deleted)
                {
                    // delete user's settings
                    try
                    {
                        var us = await _userStore.GetUserSettingsAsync(User.Identity.Name);

                        await _userStore.DeleteUserSettingsAsync(User.Identity.Name);
                    }
                    catch (UserSettingsNotFoundException)
                    {
                        // no action needed
                    }
                    catch (UserStoreException e)
                    {
                        Log.Error($"Error deleting user settings during user account {User.Identity.Name} deletion", e);
                    }

                    // repositories
                    try
                    {
                        var repos = await _repoSettingsStore.GetRepoSettingsForOwnerAsync(User.Identity.Name);

                        foreach (var r in repos)
                        {
                            await _repoSettingsStore.DeleteRepoSettingsAsync(r.OwnerId, r.RepositoryId);
                        }
                    }
                    catch (RepoSettingsNotFoundException)
                    {
                        // no action needed
                    }
                    catch (RepoSettingsStoreException e)
                    {
                        Log.Error($"Error deleting repo settings during user account {User.Identity.Name} deletion", e);
                    }

                    // owner settings
                    try
                    {
                        var owner = await _ownerSettingsStore.GetOwnerSettingsAsync(User.Identity.Name);

                        await _ownerSettingsStore.DeleteOwnerSettingsAsync(owner.OwnerId);
                    }
                    catch (OwnerSettingsNotFoundException)
                    {
                        // no action needed
                    }
                    catch (OwnerSettingsStoreException e)
                    {
                        Log.Error($"Error deleting owner settings during user account {User.Identity.Name} deletion", e);
                    }

                    // datasets
                    try
                    {
                        await _datasetStore.DeleteDatasetsForOwnerAsync(User.Identity.Name);
                    }
                    catch (DatasetStoreException e)
                    {
                        Log.Error($"Error deleting datasets during user account {User.Identity.Name} deletion", e);
                    }

                    // templates
                    try
                    {
                        await _schemaStore.DeleteSchemaRecordsForOwnerAsync(User.Identity.Name);
                    }
                    catch (Exception e)
                    {
                        Log.Error($"Error deleting templates during user account {User.Identity.Name} deletion", e);
                    }

                    // jobs
                    try
                    {
                        await _jobStore.DeleteJobsForOwnerAsync(User.Identity.Name);
                    }
                    catch (Exception e)
                    {
                        Log.Error($"Error deleting jobs during user account {User.Identity.Name} deletion", e);
                    }


                    await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

                    return(RedirectToAction("Index", "Home"));
                }

                // error
                ViewBag.Message =
                    "Unable to delete account at this time, if the problem persists please open a ticket with support.";
                return(View("Delete"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }