Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUN-2148: UI:Next: jobs list SCM status fixes #8814

Merged
merged 7 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,9 @@ class BaseGitPlugin {
logger.debug(ScmAuthMessages.CHECKING.getMessage())
def userStorageTree = ctx.getStorageTree()
def scmAuthPath = commonConfig?.sshPrivateKeyPath ? commonConfig?.sshPrivateKeyPath : commonConfig?.gitPasswordPath
if(!scmAuthPath){
return true
}
def expandedAuthPath = expandContextVarsInPath(ctx, scmAuthPath)
if( expandedAuthPath !== null && userStorageTree.hasPath(expandedAuthPath) ){
logger.debug(ScmAuthMessages.HAS_ACCESS.getMessage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ class BaseGitPluginSpec extends Specification {
validPathForUser | commonConfigPassword | commonConfigKey | methodResult
'keys/grantedAccess' | 'keys/grantedAccess' | null | true
'keys/grantedAccess' | null | 'keys/grantedAccess' | true
'keys/grantedAccess' | null | null | false
'keys/grantedAccess' | null | null | true
'keys/grantedAccess' | null | 'keys/notGrantedAccess' | false
'keys/grantedAccess' | 'keys/notGrantedAccess' | null | false

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<template>
<template v-if="displayExport || displayImport">
<template v-if="displayExport || displayImport || exportError || importError">
<popover
trigger="hover"
placement="left"
viewport="#section-content"
append-to="#section-content"
position-by="#section-main"
>
<span class="text-info">
<span class="text-info" v-if="displayExportState || displayImportState">
<i class="glyphicon glyphicon-exclamation-sign"></i>
{{ defaultDisplayText }}
</span>
<span class="text-danger" v-if="exportError || importError">
<i class="glyphicon glyphicon-exclamation-sign"></i>
{{ $t("scm.status.ERROR.display.text") }}
</span>
<template #popover>
<dl v-if="displayExport">
<dt>{{ $t("scm.export.title") }}</dt>
Expand All @@ -24,6 +28,18 @@
{{ importMessage }}
</dd>
</dl>
<dl v-if="exportError">
<dt>{{ $t("scm.export.title") }}</dt>
<dd>
{{ exportErrorText }}
</dd>
</dl>
<dl v-if="importError">
<dt>{{ $t("scm.import.title") }}</dt>
<dd>
{{ importErrorText }}
</dd>
</dl>
</template>
</popover>
</template>
Expand Down Expand Up @@ -54,56 +70,64 @@ export default defineComponent({
importState() {
return this.scmImport?.status?.state;
},
importError() {
return this.scmImport?.valid !== null && this.scmImport?.valid === false;
},
scmExport: function () {
return this.jobPageStore.findMeta("scmExport");
},
exportState() {
return this.scmExport?.status?.state;
},
displayExport() {
exportError() {
return this.scmExport?.valid !== null && this.scmExport?.valid === false;
},
displayExportState() {
return this.exportState && this.exportState !== "CLEAN";
},
displayImport() {
displayExport() {
return this.displayExportState;
},
displayImportState() {
return this.importState && this.importState !== "CLEAN";
},
displayImport() {
return this.displayImportState;
},
defaultDisplayText() {
if (this.displayExport) {
return this.exportDisplayText;
} else {
return this.importDisplayText;
}
},
importDisplayText() {
switch (this.importState) {
case "IMPORT_NEEDED":
return this.$t("scm.import.status.IMPORT_NEEDED.display.text");
case "REFRESH_NEEDED":
return this.$t("scm.import.status.REFRESH_NEEDED.display.text");
case "UNKNOWN":
return this.$t("scm.import.status.UNKNOWN.display.text");
case "CLEAN":
return this.$t("scm.import.status.CLEAN.display.text");
case "LOADING":
return this.$t("scm.import.status.LOADING.display.text");
exportErrorText() {
if (this.scmExport?.validationError) {
return this.scmExport?.validationError;
} else if (this.scmExport?.validationErrorCode) {
return this.$t(this.scmExport?.validationErrorCode);
} else {
return this.$t("scm.export.status.ERROR.display.text");
}
return this.importState;
},
exportDisplayText() {
switch (this.exportState) {
case "EXPORT_NEEDED":
return this.$t("scm.export.status.EXPORT_NEEDED.display.text");
case "CREATE_NEEDED":
return this.$t("scm.export.status.CREATE_NEEDED.display.text");
case "REFRESH_NEEDED":
return this.$t("scm.export.status.REFRESH_NEEDED.display.text");
case "DELETED":
return this.$t("scm.export.status.DELETED.display.text");
case "CLEAN":
return this.$t("scm.export.status.CLEAN.display.text");
case "LOADING":
return this.$t("scm.export.status.LOADING.display.text");
importErrorText() {
if (this.scmImport?.validationError) {
return this.scmImport?.validationError;
} else if (this.scmImport?.validationErrorCode) {
return this.$t(this.scmImport?.validationErrorCode);
} else {
return this.$t("scm.import.status.ERROR.display.text");
}
return this.exportState;
},
importDisplayText() {
return this.importState
? this.$t(`scm.import.status.${this.importState}.display.text`)
: "";
},
exportDisplayText() {
return this.exportState
? this.$t(`scm.export.status.${this.exportState}.display.text`)
: "";
},
exportMessage() {
return this.scmExport?.status?.message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,13 @@ const messages = {
"Import Status: Job changes need to be pulled",
"scm.export.status.REFRESH_NEEDED.display.text": "Synch Needed",
"scm.import.status.LOADING.display.text": "Loading",
"scm.export.status.ERROR.display.text": "An unknown error occurred.",
"scm.import.status.ERROR.display.text": "An unknown error occurred.",
"scm.status.ERROR.display.text": "SCM Error",
"scm.export.auth.key.noAccess":
"User has no access to the specified key or password",
"scm.import.auth.key.noAccess":
"User has no access to the specified key or password",
"scm.action.diff.clean.button.label": "View Commit Info",
"scm.import.plugin": "SCM Import Plugin",
"scm.action.diff.button.label": "Diff Changes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class JobScmMetadataComponent implements JobMetadataComponent {
def keyAccess = scmService
.userHasAccessToScmConfiguredKeyOrPassword(authContext, ScmService.IMPORT, project)
if (keyAccess) {
def jobsPluginMeta = scmService.getJobsPluginMeta(project, true)
def jobsPluginMeta = scmService.getJobsPluginMeta(project, false)
def jobStates = scmService
.importStatusForJobIds(project, authContext, ids, false, jobsPluginMeta)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ class ProjectScmMetadataComponent implements ProjectMetadataComponent {
results.renamed = scmService.getRenamedJobPathsForProject(project)
} else {
results.valid = false
results.validationErrorCode = 'scm.export.auth.key.noAccess'
}
}
}
} catch (ScmPluginException e) {
results.warning = "Failed to update SCM Export status: ${e.message}".toString()
results.valid = false
results.validationError = e.message
}
metaItems.add(ComponentMeta.with(SCM_EXPORT, results))
}
Expand All @@ -85,11 +87,13 @@ class ProjectScmMetadataComponent implements ProjectMetadataComponent {
results.actions = scmService.importPluginActions(authContext, project, status)
} else {
results.valid = false
results.validationErrorCode = 'scm.import.auth.key.noAccess'
}
}
}
} catch (ScmPluginException e) {
results.warning = "Failed to update SCM Import status: ${e.message}"
results.valid = false
results.validationError = e.message
}
metaItems.add(ComponentMeta.with(SCM_IMPORT, results))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package org.rundeck.app.data.job.metadata

import com.dtolabs.rundeck.core.authorization.AuthContextProcessor
import com.dtolabs.rundeck.core.authorization.UserAndRolesAuthContext
import com.dtolabs.rundeck.core.plugins.views.Action
import com.dtolabs.rundeck.plugins.scm.ImportSynchState
import com.dtolabs.rundeck.plugins.scm.JobImportState
import com.dtolabs.rundeck.plugins.scm.JobRenamed
import com.dtolabs.rundeck.plugins.scm.JobState
import com.dtolabs.rundeck.plugins.scm.ScmCommitInfo
import com.dtolabs.rundeck.plugins.scm.SynchState
import org.rundeck.app.data.providers.v1.job.JobDataProvider
import org.rundeck.core.auth.AuthConstants
import rundeck.services.ScmService
import rundeck.services.scm.ScmPluginConfigData
import spock.lang.Specification

class JobScmMetadataComponentSpec extends Specification {
def "scm import data"() {
given:
def auth = Mock(UserAndRolesAuthContext)
def sut = new JobScmMetadataComponent()
sut.scmService = Mock(ScmService) {
1 * projectHasConfiguredImportPlugin('project') >> true
1 * loadScmConfig('project', ScmService.IMPORT) >> Mock(ScmPluginConfigData) {
_ * getEnabled() >> true
}
1 * userHasAccessToScmConfiguredKeyOrPassword(auth, ScmService.IMPORT, 'project') >> true
1 * getJobsPluginMeta('project', false) >> [:]
1 * importStatusForJobIds('project', auth, ['id'], false, [:]) >>
[id: Mock(JobImportState) {
_ * getSynchState() >> ImportSynchState.CLEAN
_ * getActions() >> [
Mock(Action) {
_ * getId() >> 'action1'
_ * getTitle() >> 'actionTitle'
_ * getDescription() >> 'actionDesc'
_ * getIconName() >> 'actionIcon'
}
]
_ * getCommit() >> Mock(ScmCommitInfo) {
_ * asMap() >> [
commit: 'info'
]
}
_ * getJobRenamed() >> Mock(JobRenamed) {
_ * getUuid() >> 'renamedUuid'
_ * getSourceId() >> 'renameSourceId'
_ * getRenamedPath() >> 'renamedPath'
}
}]
}
sut.rundeckAuthContextProcessor = Mock(AuthContextProcessor) {
_ * authorizeApplicationResourceAny(
auth,
_,
[AuthConstants.ACTION_ADMIN, AuthConstants.ACTION_APP_ADMIN, AuthConstants.ACTION_IMPORT, AuthConstants.ACTION_SCM_IMPORT]
) >> true
}
sut.jobDataProvider = Mock(JobDataProvider)
when:
def result = sut.getMetadataForJob('id', 'project', [JobScmMetadataComponent.SCM_IMPORT].toSet(), auth)
then:
result != null
result.isPresent()
def parts = result.get()
parts.size() == 1

def scmImport = parts.find { it.name == JobScmMetadataComponent.SCM_IMPORT }
scmImport != null
scmImport.data == [
jobState: [
synchState: ImportSynchState.CLEAN.toString(),
actions : [
[
id : 'action1',
title : 'actionTitle',
description: 'actionDesc',
iconName : 'actionIcon'
]
],
jobRenamed: [
uuid : 'renamedUuid',
sourceId : 'renameSourceId',
renamedPath: 'renamedPath'
],
commit : [
commit: 'info'
]
]
]

}
def "scm export data"() {
given:
def auth = Mock(UserAndRolesAuthContext)
def sut = new JobScmMetadataComponent()
sut.scmService = Mock(ScmService) {
1 * projectHasConfiguredExportPlugin('project') >> true
1 * loadScmConfig('project', ScmService.EXPORT) >> Mock(ScmPluginConfigData) {
_ * getEnabled() >> true
}
1 * userHasAccessToScmConfiguredKeyOrPassword(auth, ScmService.EXPORT, 'project') >> true
1 * getJobsPluginMeta('project', true) >> [:]
1 * exportStatusForJobIds('project', auth, ['id'], false, [:]) >>
[id: Mock(JobState) {
_ * getSynchState() >> SynchState.CLEAN
_ * getActions() >> [
Mock(Action) {
_ * getId() >> 'action1'
_ * getTitle() >> 'actionTitle'
_ * getDescription() >> 'actionDesc'
_ * getIconName() >> 'actionIcon'
}
]
_ * getCommit() >> Mock(ScmCommitInfo) {
_ * asMap() >> [
commit: 'info'
]
}
}]
}
sut.rundeckAuthContextProcessor = Mock(AuthContextProcessor) {
_ * authorizeApplicationResourceAny(
auth,
_,
[AuthConstants.ACTION_ADMIN, AuthConstants.ACTION_APP_ADMIN, AuthConstants.ACTION_EXPORT, AuthConstants.ACTION_SCM_EXPORT]
) >> true
}
sut.jobDataProvider = Mock(JobDataProvider)
when:
def result = sut.getMetadataForJob('id', 'project', [JobScmMetadataComponent.SCM_EXPORT].toSet(), auth)
then:
result != null
result.isPresent()
def parts = result.get()
parts.size() == 1

def scmImport = parts.find { it.name == JobScmMetadataComponent.SCM_EXPORT }
scmImport != null
scmImport.data == [
jobState: [
synchState: SynchState.CLEAN.toString(),
actions : [
[
id : 'action1',
title : 'actionTitle',
description: 'actionDesc',
iconName : 'actionIcon'
]
],
commit : [
commit: 'info'
]
]
]

}
}