diff --git a/html/embed.go b/html/embed.go index 228e1bcc..f7ac9389 100644 --- a/html/embed.go +++ b/html/embed.go @@ -76,7 +76,7 @@ func (ts templateSystemEmbed) loadTemplateSubdir(subdir string) error { } func (ts templateSystemEmbed) addSubdirTemplates(t *template.Template, subdir string) error { - var err error = fs.WalkDir(ts.sourceFS, subdir, func(path string, d fs.DirEntry, err error) error { + var err = fs.WalkDir(ts.sourceFS, subdir, func(path string, d fs.DirEntry, err error) error { if err != nil || d.IsDir() { return err } diff --git a/middleware/logger.go b/middleware/logger.go index dafdcc06..57f55820 100644 --- a/middleware/logger.go +++ b/middleware/logger.go @@ -164,7 +164,7 @@ func (l *defaultLogEntry) Panic(v interface{}, stack []byte) { } func init() { - color := !(runtime.GOOS == "windows") + color := runtime.GOOS != "windows" DefaultLogger = RequestLogger(&DefaultLogFormatter{Logger: log.New(os.Stdout, "", log.LstdFlags), NoColor: !color}) } diff --git a/platform/label_studio.go b/platform/label_studio.go index 826f8331..735e7482 100644 --- a/platform/label_studio.go +++ b/platform/label_studio.go @@ -3,7 +3,6 @@ package platform import ( "context" "encoding/json" - "errors" "fmt" "log" "os" diff --git a/platform/publicreport.go b/platform/publicreport.go index a44c3aca..ba24957e 100644 --- a/platform/publicreport.go +++ b/platform/publicreport.go @@ -173,6 +173,22 @@ func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_ if err != nil { return nil, fmt.Errorf("find compliance %d: %w", report.ID, err) } + // Don't allow modifying of the submission date if it's set + if compliance_setter.Submitted.IsValue() { + if compliance.Submitted.IsValue() { + compliance_setter.Submitted.Unset() + } else { + comm := &model.Communication{ + SourceReportID: &report.ID, + } + comm, err := querypublic.CommunicationInsert(ctx, txn, comm) + if err != nil { + return nil, fmt.Errorf("insert communication: %w", err) + } + log.Debug().Int32("id", comm.ID).Msg("inserted new communication") + } + } + // Avoid attempting to perform an empty update if report_setter.LatlngAccuracyValue.IsValue() || report_setter.ReporterEmail.IsValue() || @@ -389,14 +405,18 @@ func publicReportCreate(ctx context.Context, setter_report models.PublicreportRe UserID: omitnull.FromPtr[int32](nil), }).One(ctx, txn) - comm := &model.Communication{ - SourceReportID: &result.ID, + // Only create communication entries for compliance when they're submitted + report_type := setter_report.ReportType.MustGet() + if report_type != enums.PublicreportReporttypeCompliance { + comm := &model.Communication{ + SourceReportID: &result.ID, + } + comm, err = querypublic.CommunicationInsert(ctx, txn, comm) + if err != nil { + return nil, fmt.Errorf("insert communication: %w", err) + } + log.Debug().Int32("id", comm.ID).Msg("inserted new communication") } - comm, err = querypublic.CommunicationInsert(ctx, txn, comm) - if err != nil { - return nil, fmt.Errorf("insert communication: %w", err) - } - log.Debug().Int32("id", comm.ID).Msg("inserted new communication") txn.Commit(ctx) diff --git a/platform/text/text.go b/platform/text/text.go index bebb378b..69f53eb8 100644 --- a/platform/text/text.go +++ b/platform/text/text.go @@ -38,7 +38,7 @@ func HandleTextMessage(ctx context.Context, source string, destination string, c if err != nil { return fmt.Errorf("Failed to get phone status") } - is_visible_to_llm := !(status == enums.CommsPhonestatustypeUnconfirmed) + is_visible_to_llm := status != enums.CommsPhonestatustypeUnconfirmed l, err := models.CommsTextLogs.Insert(&models.CommsTextLogSetter{ //ID: diff --git a/resource/publicreport_compliance.go b/resource/publicreport_compliance.go index 44ddb234..4c287e40 100644 --- a/resource/publicreport_compliance.go +++ b/resource/publicreport_compliance.go @@ -28,7 +28,7 @@ type complianceR struct { router *router } -type publicreportComplianceForm struct { +type publicReportComplianceForm struct { AccessInstructions omit.Val[string] `schema:"access_instructions" json:"access_instructions"` Address omit.Val[types.Address] `schema:"address" json:"address"` AvailabilityNotes omit.Val[string] `schema:"availability_notes" json:"availability_notes"` @@ -42,6 +42,7 @@ type publicreportComplianceForm struct { PermissionType omit.Val[enums.Permissionaccesstype] `schema:"permission_type" json:"permission_type"` Reporter omit.Val[types.Contact] `schema:"reporter" json:"reporter"` ReportPhoneCanSMS omitnull.Val[bool] `schema:"report_phone_can_text" json:"report_phone_can_text"` + Submitted omitnull.Val[time.Time] `schema:"submitted" json:"submitted"` WantsScheduled omitnull.Val[bool] `schema:"wants_scheduled" json:"wants_scheduled"` } @@ -51,7 +52,7 @@ func (res *complianceR) ByID(ctx context.Context, r *http.Request, u platform.Us func (res *complianceR) ByIDPublic(ctx context.Context, r *http.Request, query QueryParams) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) { return res.byID(ctx, r, true) } -func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicreportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) { +func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicReportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) { if n.District.IsUnset() && n.MailerID.IsUnset() { return nil, nhttp.NewBadRequest("You must provide a district_id or mailer_id") } @@ -141,7 +142,7 @@ func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicrep } return res.complianceHydrate(result, true) } -func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicreportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) { +func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicReportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) { vars := mux.Vars(r) public_id := vars["id"] if public_id == "" { @@ -198,12 +199,10 @@ func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicr if prf.WantsScheduled.IsValue() { compliance_setter.WantsScheduled = prf.WantsScheduled } - log.Debug(). - Bool("access_instructions", prf.AccessInstructions.IsValue()). - Bool("access_instructions", prf.AccessInstructions.IsValue()). - Bool("access_instructions", prf.AccessInstructions.IsValue()). - Bool("access_instructions", prf.AccessInstructions.IsValue()). - Msg("updating compliance") + if prf.Submitted.IsValue() { + log.Debug().Str("submitted", prf.Submitted.MustGet().String()).Msg("got submitted") + compliance_setter.Submitted = omitnull.From(time.Now()) + } report, err := platform.PublicReportUpdateCompliance(ctx, public_id, &report_setter, &compliance_setter, address, location) if err != nil { return nil, nhttp.NewError("platform update report compliance: %w", err) @@ -216,22 +215,6 @@ func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicr return res.complianceHydrate(report, true) } -type publicreportComplianceFormSubmit struct { - ClientID uuid.UUID `schema:"client_id" json:"client_id"` -} - -func (res *complianceR) Submit(ctx context.Context, r *http.Request, prf publicreportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) { - vars := mux.Vars(r) - public_id := vars["id"] - if public_id == "" { - return nil, nhttp.NewBadRequest("You must provide an ID") - } - report, err := platform.PublicReportComplianceSubmit(ctx, public_id, true) - if err != nil { - return nil, nhttp.NewError("submit report: %w", err) - } - return report, nil -} func (res *complianceR) byID(ctx context.Context, r *http.Request, is_public bool) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) { vars := mux.Vars(r) public_id := vars["id"] diff --git a/resource/query_params.go b/resource/query_params.go index 6c070ebf..156403be 100644 --- a/resource/query_params.go +++ b/resource/query_params.go @@ -20,7 +20,7 @@ func (qp QueryParams) SortOrDefault(default_name string, ascending bool) (string if s == "" { return default_name, ascending } - a := !(s[0] == '-') + a := s[0] != '-' if s[0] == '+' || s[0] == '-' { s = s[1:] diff --git a/ts/rmo/view/Compliance.vue b/ts/rmo/view/Compliance.vue index 4d01fd7d..17236b08 100644 --- a/ts/rmo/view/Compliance.vue +++ b/ts/rmo/view/Compliance.vue @@ -183,6 +183,9 @@ function doPermission() { function doSubmit() { console.log("submit", report.value); storeLocal.delExistingComplianceReportURI(); + updateReport({ + submitted: new Date().toISOString(), + }); } async function updateReport(updates: ComplianceUpdate) { if (!(report.value && report.value.uri)) { diff --git a/ts/type/api.ts b/ts/type/api.ts index daaaee7d..882120ba 100644 --- a/ts/type/api.ts +++ b/ts/type/api.ts @@ -196,6 +196,7 @@ export interface ComplianceUpdate { location?: Location; permission_type?: string; reporter?: Contact; + submitted?: string; //uri: string; wants_scheduled?: boolean; } @@ -294,6 +295,7 @@ export interface PublicReportComplianceDTO extends PublicReportDTO { gate_code: string; has_dog: boolean; permission_type: PermissionType; + submitted: string; wants_scheduled: boolean; } export interface PublicReportComplianceOptions extends PublicReportOptions { @@ -304,6 +306,7 @@ export interface PublicReportComplianceOptions extends PublicReportOptions { gate_code: string; has_dog: boolean; permission_type: PermissionType; + submitted: string; wants_scheduled: boolean; } export interface PublicReportComplianceUpdate extends PublicReportUpdate { @@ -313,6 +316,7 @@ export interface PublicReportComplianceUpdate extends PublicReportUpdate { gate_code?: string; has_dog?: boolean; permission_type?: PermissionType; + submitted?: string; wants_scheduled?: boolean; } export class PublicReportCompliance extends PublicReport { @@ -323,6 +327,7 @@ export class PublicReportCompliance extends PublicReport { gate_code: string; has_dog: boolean; permission_type: PermissionType; + submitted?: Date; wants_scheduled: boolean; constructor(options?: PublicReportComplianceOptions) { super(options); @@ -335,6 +340,9 @@ export class PublicReportCompliance extends PublicReport { this.permission_type = toPermissionType( options?.permission_type ?? PermissionType.UNSELECTED, ); + this.submitted = options?.submitted + ? new Date(options!.submitted) + : undefined; this.wants_scheduled = options?.wants_scheduled ?? false; } static fromJSON(json: PublicReportComplianceDTO): PublicReportCompliance {