use of com.thoughtworks.go.config.Approval in project gocd by gocd.
the class ApprovalRepresenter method fromJSON.
public static Approval fromJSON(JsonReader jsonReader) {
Approval approval = new Approval();
jsonReader.readStringIfPresent("type", approval::setType);
jsonReader.readBooleanIfPresent(Approval.ALLOW_ONLY_ON_SUCCESS, approval::setAllowOnlyOnSuccess);
AuthConfig authConfig = StageAuthorizationRepresenter.fromJSON(jsonReader.readJsonObject("authorization"));
approval.setAuthConfig(authConfig);
return approval;
}
use of com.thoughtworks.go.config.Approval in project gocd by gocd.
the class StageApprovalAuthorizationTest method shouldAuthorizeUserCruiseIfUserIsAuthorisedToOperateAutoStage.
@Test
public void shouldAuthorizeUserCruiseIfUserIsAuthorisedToOperateAutoStage() throws Exception {
CONFIG_HELPER.addSecurityWithAdminConfig();
CONFIG_HELPER.setOperatePermissionForStage(PIPELINE_NAME, STAGE_NAME, "cruise");
StageConfig stage = StageConfigMother.custom("ft", new Approval(new AuthConfig(new AdminUser(new CaseInsensitiveString("cruise")))));
PipelineConfig pipeline = CONFIG_HELPER.addStageToPipeline(PIPELINE_NAME, stage);
assertThat(securityService.hasOperatePermissionForStage(CaseInsensitiveString.str(pipeline.name()), CaseInsensitiveString.str(stage.name()), "cruise"), is(true));
assertThat(securityService.hasOperatePermissionForStage(PIPELINE_NAME, STAGE_NAME, "anyone"), is(false));
}
use of com.thoughtworks.go.config.Approval in project gocd by gocd.
the class SchedulingCheckerService method shouldAllowSchedulingStage.
ScheduleStageResult shouldAllowSchedulingStage(Pipeline pipeline, String stageName) {
if (pipeline == null) {
return ScheduleStageResult.PipelineNotFound;
}
if (pipeline.hasStageBeenRun(stageName)) {
return ScheduleStageResult.CanSchedule;
}
String pipelineName = pipeline.getName();
if (!goConfigService.hasPreviousStage(pipelineName, stageName)) {
return ScheduleStageResult.CanSchedule;
}
CaseInsensitiveString previousStageName = goConfigService.previousStage(pipelineName, stageName).name();
if (!pipeline.hasStageBeenRun(CaseInsensitiveString.str(previousStageName))) {
return ScheduleStageResult.PreviousStageNotRan;
}
StageConfig currentStageConfig = goConfigService.nextStage(pipelineName, previousStageName.toString());
Approval approval = currentStageConfig.getApproval();
if (approval.isAllowOnlyOnSuccess()) {
Stage previousStage = pipeline.getStages().byName(previousStageName.toString());
StageResult previousStageResult = previousStage.getResult();
if (previousStageResult != StageResult.Passed) {
return ScheduleStageResult.PreviousStageNotPassed.setPreviousStageValues(previousStageName.toString(), previousStageResult.name());
}
}
return ScheduleStageResult.CanSchedule;
}
use of com.thoughtworks.go.config.Approval in project gocd by gocd.
the class ApprovalRepresenter method fromJSON.
public static Approval fromJSON(JsonReader jsonReader) {
Approval approval = new Approval();
jsonReader.readStringIfPresent("type", approval::setType);
jsonReader.readBooleanIfPresent(Approval.ALLOW_ONLY_ON_SUCCESS, approval::setAllowOnlyOnSuccess);
AuthConfig authConfig = StageAuthorizationRepresenter.fromJSON(jsonReader.readJsonObject("authorization"));
approval.setAuthConfig(authConfig);
return approval;
}
use of com.thoughtworks.go.config.Approval in project gocd by gocd.
the class ApprovalRepresenter method fromJSON.
public static Approval fromJSON(JsonReader jsonReader) {
Approval approval = new Approval();
jsonReader.readStringIfPresent("type", approval::setType);
jsonReader.readBooleanIfPresent(Approval.ALLOW_ONLY_ON_SUCCESS, approval::setAllowOnlyOnSuccess);
AuthConfig authConfig = StageAuthorizationRepresenter.fromJSON(jsonReader.readJsonObject("authorization"));
approval.setAuthConfig(authConfig);
return approval;
}
Aggregations