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

Fixes #21119: When a technique is not in the active techique tree, it can't be deleted in editor #4292

Conversation

ElaadF
Copy link
Member

@ElaadF ElaadF commented May 24, 2022

@ElaadF ElaadF added qa: Can't merge WIP Use that label for a Work In Progress PR that must not be merged yet labels May 24, 2022
@ElaadF ElaadF force-pushed the bug_21119/when_a_technique_is_not_in_the_active_techique_tree_it_can_t_be_deleted_in_editor branch 4 times, most recently from c2809cc to 9d12411 Compare May 25, 2022 09:30
@ElaadF ElaadF removed qa: Can't merge WIP Use that label for a Work In Progress PR that must not be merged yet labels May 25, 2022
@ElaadF ElaadF requested a review from VinceMacBuche May 25, 2022 09:32
@ElaadF ElaadF force-pushed the bug_21119/when_a_technique_is_not_in_the_active_techique_tree_it_can_t_be_deleted_in_editor branch from 9d12411 to 2bb7648 Compare May 25, 2022 09:34
@ElaadF ElaadF requested review from fanf and ncharles May 25, 2022 09:34
@@ -138,40 +134,56 @@ class TechniqueWriter (
cr1.copy(directives = cr1.directives ++ cr2.directives)
}

for {
directives <- readDirectives.getFullDirectiveLibrary().map(_.allActiveTechniques.values.filter(_.techniqueName.value == techniqueId.name.value).flatMap(_.directives).filter(_.techniqueVersion == techniqueId.version))
technique <- techniqueRepository.get(techniqueId).notOptional(s"No Technique with ID '${techniqueId.toString()}' found in reference library.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should extract the for loop in a function (maybe an inner function, it does not need to be global for now)

Same for the none part, it should be in an inner function

fanf
fanf previously requested changes Jun 7, 2022
for {
_ <- ZIO.foreach(unknownTechniquesDir) { f =>
val cat = f.pathAsString.substring(s"${basePath}/techniques/".length).split("/").filter(s => s != techniqueName && s != techniqueVersion).toList
archiver.deleteTechnique(techniqueName, techniqueVersion, cat, modId, committer, s"Deleting invalid technique ${techniqueName}/${techniqueVersion}").runNow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's forbidden to put runNow into a ZIO effect. You need to deal with the effects, especially with the error case: if the archiver doesn't succeed, what needs to be done ? (something like delete file by hand ? Or perhaps give a procedure in logs for an admin: delete that, commit in git, reload techniques)

@ElaadF ElaadF added qa: Can't merge WIP Use that label for a Work In Progress PR that must not be merged yet and removed qa: Can't merge WIP Use that label for a Work In Progress PR that must not be merged yet labels Jun 8, 2022
@VinceMacBuche
Copy link
Member

You should split both branch of your code in inner function, it's complicated to understand what both branch is doing.

Have you not seen my previous comment ? https://github.com/Normation/rudder/pull/4292/files#r891297849

@ElaadF
Copy link
Member Author

ElaadF commented Jun 13, 2022

I'm surprised I did refactor in functions, I had pushed the changes but didn't appear.. I will check locally

}
}

def removeInvalidTechnique(basePath: String, techniqueName: String): IOResult[Unit] = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VinceMacBuche the inner function

@VinceMacBuche VinceMacBuche dismissed fanf’s stale review June 14, 2022 08:51

Dismissing review, changes were made

@Normation-Quality-Assistant
Copy link
Contributor

This PR is not mergeable to upper versions.
Since it is "Ready for merge" you must merge it by yourself using the following command:
rudder-dev merge https://github.com/Normation/rudder/pull/4292
-- Your faithful QA
Kant merge: "In law a man is guilty when he violates the rights of others. In ethics he is guilty if he only thinks of doing so."
(https://ci.normation.com/jenkins/job/merge-accepted-pr/55592/console)

@ElaadF
Copy link
Member Author

ElaadF commented Jun 14, 2022

OK, squash merging this PR

@ElaadF ElaadF force-pushed the bug_21119/when_a_technique_is_not_in_the_active_techique_tree_it_can_t_be_deleted_in_editor branch from 55b310b to c773656 Compare June 14, 2022 08:53
@ElaadF ElaadF merged commit c773656 into Normation:branches/rudder/6.2 Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants