public async Task ValidatePhaseMoveThrowIfNot(Sandbox sandbox, SandboxPhase currentPhase, SandboxPhase nextPhase, CancellationToken cancellation = default) { var validationErrors = new List <string>(); _logger.LogInformation(_sandboxNextPhaseEventId, "Sandbox {0}: Validation phase move from {1} to {2}", sandbox.Id, currentPhase, nextPhase); validationErrors.AddRange(VerifyThatSandboxHasDatasets(sandbox)); validationErrors.AddRange(VerifyBasicResourcesIsFinishedAsync(sandbox.Resources)); validationErrors.AddRange(await VerifyInternetClosed(sandbox, cancellation)); ValidationUtils.ThrowIfValidationErrors("Phase change not allowed", validationErrors); }
async Task DecorateDto(Study studyDb, SandboxPermissions sandboxPermissions, SandboxPhase phase) { var currentUser = await _userService.GetCurrentUserAsync(); var studyPermissionDetails = _mapper.Map <IHasStudyPermissionDetails>(studyDb); sandboxPermissions.Delete = _studyPermissionService.HasAccessToOperationForStudy(currentUser, studyPermissionDetails, Common.Constants.UserOperation.Study_Crud_Sandbox); sandboxPermissions.Update = _studyPermissionService.HasAccessToOperationForStudy(currentUser, studyPermissionDetails, Common.Constants.UserOperation.Study_Crud_Sandbox); sandboxPermissions.EditInboundRules = _studyPermissionService.HasAccessToOperationForStudy(currentUser, studyPermissionDetails, Common.Constants.UserOperation.Sandbox_EditInboundRules); sandboxPermissions.OpenInternet = phase > SandboxPhase.Open ? currentUser.Admin : _studyPermissionService.HasAccessToOperationForStudy(currentUser, studyPermissionDetails, Common.Constants.UserOperation.Sandbox_OpenInternet); //TODO: was it really only admin who could do this? sandboxPermissions.IncreasePhase = _studyPermissionService.HasAccessToOperationForStudy(currentUser, studyPermissionDetails, Common.Constants.UserOperation.Sandbox_IncreasePhase); }
public static async Task <Sandbox> Create( Study study, string sandboxName = SandboxConstants.NAME, string region = TestConstants.REGION, SandboxPhase phase = SandboxPhase.Open, bool addDatasets = false) { var sandbox = SandboxBasic(study.Id, study.Name, sandboxName, region, SandboxResources(region, study.Name, sandboxName), phase); AddDatasets(addDatasets, study, sandbox); return(await SliceFixture.InsertAsync(sandbox)); }
protected async Task <CloudResource> WithFailedVirtualMachine(bool createdByCurrentUser, bool restricted = false, List <string> additionalRolesForCurrentUser = null, List <string> rolesForOtherUser = null, SandboxPhase phase = SandboxPhase.Open, bool addDatasets = false, bool deleted = false, bool deleteSucceeded = false) { var sandbox = await WithSandbox(createdByCurrentUser, restricted, additionalRolesForCurrentUser : additionalRolesForCurrentUser, rolesForOtherUser : rolesForOtherUser, phase, addDatasets : addDatasets); var vm = await VirtualMachineSeed.CreateFailed(sandbox, deleted : deleted, deleteSucceeded : deleteSucceeded); sandbox.Resources.Add(vm); vm.Sandbox = sandbox; return(vm); }
public static async Task <Sandbox> CreateFailing( Study study, string sandboxName = SandboxConstants.NAME, string region = TestConstants.REGION, SandboxPhase phase = SandboxPhase.Open, int resourcesSucceeded = 0, string statusOfFailedResource = CloudResourceOperationState.FAILED, int tryCount = CloudResourceConstants.RESOURCE_MAX_TRY_COUNT, int maxTryCount = CloudResourceConstants.RESOURCE_MAX_TRY_COUNT, bool addDatasets = false) { var resources = SandboxResourcesFailing(region, study.Name, sandboxName, resourcesSucceeded, statusOfFailedResource, tryCount, maxTryCount); var sandbox = SandboxBasic(study.Id, study.Name, sandboxName, region, resources, phase); AddDatasets(addDatasets, study, sandbox); return(await SliceFixture.InsertAsync(sandbox)); }
protected async Task <Sandbox> WithSandbox(bool createdByCurrentUser, bool restricted = false, List <string> additionalRolesForCurrentUser = null, List <string> rolesForOtherUser = null, SandboxPhase phase = SandboxPhase.Open, bool addDatasets = false) { var study = await WithStudy(createdByCurrentUser, restricted, additionalRolesForCurrentUser, rolesForOtherUser, addDatasets : addDatasets); var sandbox = await SandboxSeed.Create(study, phase : phase, addDatasets : addDatasets); sandbox.Study = study; study.Sandboxes.Add(sandbox); return(sandbox); }
static Sandbox SandboxBasic(int studyId, string studyName, string sandboxName, string region, List <CloudResource> cloudResources, SandboxPhase phase = SandboxPhase.Open) { var sb = new Sandbox() { StudyId = studyId, Name = sandboxName, Region = region, PhaseHistory = new List <SandboxPhaseHistory>(), CreatedBy = "seed", Created = DateTime.UtcNow, UpdatedBy = "seed", Updated = DateTime.UtcNow, TechnicalContactEmail = "*****@*****.**", TechnicalContactName = "Seed", Resources = cloudResources }; int counter = 0; for (var curPhase = SandboxPhase.Open; curPhase <= phase; curPhase++) { sb.PhaseHistory.Add(new SandboxPhaseHistory() { Counter = counter, Phase = curPhase, CreatedBy = "seed" }); counter++; } return(sb); }