@@ -20,15 +20,16 @@ package cmd
2020import (
2121 "errors"
2222 "fmt"
23+ "os"
24+ "strconv"
25+ "strings"
26+ "time"
27+
2328 "github.com/JankariTech/OpenProjectTmetricIntegration/config"
2429 "github.com/JankariTech/OpenProjectTmetricIntegration/openproject"
2530 "github.com/JankariTech/OpenProjectTmetricIntegration/tmetric"
2631 "github.com/manifoldco/promptui"
2732 "github.com/spf13/cobra"
28- "os"
29- "strconv"
30- "strings"
31- "time"
3233)
3334
3435func validateOpenProjectWorkPackage (input string ) error {
@@ -51,7 +52,7 @@ func handleEntriesWithoutIssue(timeEntries []tmetric.TimeEntry, tmetricUser tmet
5152 defer spinner .Stop ()
5253
5354 for _ , entry := range entriesWithoutLinkToOpenProject {
54- prompt := promptui.Prompt {
55+ getWPPrompt := promptui.Prompt {
5556 Label : fmt .Sprintf (
5657 "%v => %v %v-%v. Provide a WP number to be assigned to this time-entry (Enter to skip)" ,
5758 entry .Project .Name , entry .Note , entry .StartTime , entry .EndTime ,
@@ -62,7 +63,7 @@ func handleEntriesWithoutIssue(timeEntries []tmetric.TimeEntry, tmetricUser tmet
6263 workpackageFoundOnOpenProject := false
6364 for ! workpackageFoundOnOpenProject {
6465
65- workPackageId , err := prompt .Run ()
66+ workPackageId , err := getWPPrompt .Run ()
6667
6768 if err != nil {
6869 return fmt .Errorf ("prompt failed: %v" , err )
@@ -82,7 +83,37 @@ func handleEntriesWithoutIssue(timeEntries []tmetric.TimeEntry, tmetricUser tmet
8283 continue
8384 }
8485
85- prompt = promptui.Prompt {
86+ if ! implausibleProjectConfirmation (
87+ workPackage ,
88+ workPackage .Embedded .Project .Active ,
89+ "This project is NOT active! " ,
90+ "Do you want to use a WP from an INACTIVE project?" ,
91+ ) {
92+ workpackageFoundOnOpenProject = false
93+ continue
94+ }
95+
96+ if ! implausibleProjectConfirmation (
97+ workPackage ,
98+ workPackage .Embedded .Project .Favorited ,
99+ "This project is none of your favorite projects!" ,
100+ "Do you really want to use a WP from a not-favorite project?" ,
101+ ) {
102+ workpackageFoundOnOpenProject = false
103+ continue
104+ }
105+
106+ if ! implausibleProjectConfirmation (
107+ workPackage ,
108+ workPackage .Embedded .Assignee .Name == tmetricUser .Name || workPackage .Embedded .Assignee .Name == config .OpenProjectTeam ,
109+ fmt .Sprintf ("This WP is not assigned to you but to '%s'!" , workPackage .Embedded .Assignee .Name ),
110+ "Do you really want to use a WP that is not assigned to you?" ,
111+ ) {
112+ workpackageFoundOnOpenProject = false
113+ continue
114+ }
115+
116+ prompt := promptui.Prompt {
86117 Label : fmt .Sprintf (
87118 "WP: %v. Subject: %v. Update t-metric entry?" , workPackage .Id , workPackage .Subject ,
88119 ),
@@ -112,6 +143,23 @@ func handleEntriesWithoutIssue(timeEntries []tmetric.TimeEntry, tmetricUser tmet
112143 return nil
113144}
114145
146+ func implausibleProjectConfirmation (
147+ workPackage openproject.WorkPackage , condition bool , issue string , question string ,
148+ ) bool {
149+ if condition {
150+ return true
151+ }
152+ prompt := promptui.Prompt {
153+ Label : fmt .Sprintf (
154+ "⚠️ Found WP '%s' in the project '%s'. %s %s" ,
155+ workPackage .Subject , workPackage .Embedded .Project .Name , issue , question ,
156+ ),
157+ IsConfirm : true ,
158+ }
159+ result , err := prompt .Run ()
160+ return err == nil && result == "y"
161+ }
162+
115163func handleEntriesWithoutWorkType (timeEntries []tmetric.TimeEntry , tmetricUser tmetric.User , config * config.Config ) error {
116164 entriesWithoutWorkType := tmetric .GetEntriesWithoutWorkType (timeEntries )
117165 if len (entriesWithoutWorkType ) > 0 {
0 commit comments