Search in sources :

Example 1 with 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;
}
Also used : AuthConfig(com.thoughtworks.go.config.AuthConfig) Approval(com.thoughtworks.go.config.Approval)

Example 2 with 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));
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) AdminUser(com.thoughtworks.go.config.AdminUser) AuthConfig(com.thoughtworks.go.config.AuthConfig) Approval(com.thoughtworks.go.config.Approval) StageConfig(com.thoughtworks.go.config.StageConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.jupiter.api.Test)

Example 3 with Approval

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;
}
Also used : StageResult(com.thoughtworks.go.domain.StageResult) Stage(com.thoughtworks.go.domain.Stage) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Approval(com.thoughtworks.go.config.Approval) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageConfig(com.thoughtworks.go.config.StageConfig)

Example 4 with 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;
}
Also used : AuthConfig(com.thoughtworks.go.config.AuthConfig) Approval(com.thoughtworks.go.config.Approval)

Example 5 with 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;
}
Also used : AuthConfig(com.thoughtworks.go.config.AuthConfig) Approval(com.thoughtworks.go.config.Approval)

Aggregations

Approval (com.thoughtworks.go.config.Approval)5 AuthConfig (com.thoughtworks.go.config.AuthConfig)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 StageConfig (com.thoughtworks.go.config.StageConfig)2 AdminUser (com.thoughtworks.go.config.AdminUser)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 Stage (com.thoughtworks.go.domain.Stage)1 StageResult (com.thoughtworks.go.domain.StageResult)1 Test (org.junit.jupiter.api.Test)1