Skip to content

Commit

Permalink
OY-4272 Changes to audit log
Browse files Browse the repository at this point in the history
  • Loading branch information
tomikat committed Nov 8, 2023
1 parent 3ce23c8 commit a90f781
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 34 deletions.
5 changes: 3 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
[org.clojure/data.json "0.2.6"]
[environ "1.1.0"]
[software.amazon.awssdk/sqs "2.5.37"]
[fi.vm.sade/auditlogger "8.3.0-20190605.103856-7"]
[fi.vm.sade/auditlogger "9.2.2-SNAPSHOT"]
[com.rpl/specter "1.1.3"]
[org.clojure/core.memoize "1.0.250"]]
:managed-dependencies [[org.clojure/clojure "1.10.1"]
Expand Down Expand Up @@ -60,7 +60,8 @@
[com.fasterxml.jackson.core/jackson-databind "2.9.8"]
[com.fasterxml.jackson.core/jackson-datatype-jsr310 "2.9.8"]
[org.clojure/data.json "0.2.6"]
[com.google.code.gson/gson "2.8.0"]
[com.google.code.gson/gson "2.10.1"]
[com.tananaev/json-patch "1.2"]

;; XML
[org.clojure/data.xml "0.0.8"]
Expand Down
28 changes: 13 additions & 15 deletions src/oph/ehoks/hoks/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,7 @@
:audit-data {:new hoks}))
(catch Exception e
(case (:error (ex-data e))
:disallowed-update (assoc
(response/bad-request! {:error (.getMessage e)})
:audit-data {:new hoks})
:disallowed-update (response/bad-request! {:error (.getMessage e)})
:duplicate (do (log/warnf
"HOKS with opiskeluoikeus-oid %s already exists"
(:opiskeluoikeus-oid hoks))
Expand All @@ -306,18 +304,18 @@
(defn- change-hoks!
"Käsittelee HOKS-muutospyynnön."
[hoks request db-handler]
(if (empty? (:hoks request))
(response/not-found {:error "HOKS not found with given HOKS ID"})
(try
(h/check-hoks-for-update! (:hoks request) hoks)
(let [hoks-db (db-handler (get-in request [:hoks :id]) hoks)]
(assoc (response/no-content) :audit-data {:new hoks}))
(catch Exception e
(h/error-log-hoks-id (get-in request [:hoks :id]))
(if (= (:error (ex-data e)) :disallowed-update)
(assoc (response/bad-request! {:error (.getMessage e)})
:audit-data {:new hoks})
(throw e))))))
(let [old-hoks (:hoks request)]
(if (empty? old-hoks)
(response/not-found {:error "HOKS not found with given HOKS ID"})
(try
(h/check-hoks-for-update! old-hoks hoks)
(let [db-hoks (db-handler (get-in request [:hoks :id]) hoks)]
(assoc (response/no-content) :audit-data {:new hoks :old old-hoks}))
(catch Exception e
(h/error-log-hoks-id (get-in request [:hoks :id]))
(if (= (:error (ex-data e)) :disallowed-update)
(response/bad-request! {:error (.getMessage e)})
(throw e)))))))

(def routes
"HOKS handlering reitit."
Expand Down
1 change: 1 addition & 0 deletions src/oph/ehoks/logging/audit.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns oph.ehoks.logging.audit
(:require [clojure.tools.logging :as log]
[clojure.data.json :as json]
[oph.ehoks.logging.access :refer [current-fin-time-str
get-session]]
[environ.core :refer [env]]
Expand Down
25 changes: 11 additions & 14 deletions src/oph/ehoks/virkailija/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@
([hoks-values]
(if-not
(oi/opiskeluoikeus-still-active? (:opiskeluoikeus-oid hoks-values))
(assoc
(response/bad-request!
{:error (format "Opiskeluoikeus %s is no longer active"
(:opiskeluoikeus-oid hoks-values))})
:audit-data {:new hoks-values}))))
(response/bad-request!
{:error (format "Opiskeluoikeus %s is no longer active"
(:opiskeluoikeus-oid hoks-values))}))))

(defn- check-virkailija-privileges
"Check whether virkailija user has write privileges in HOKS"
Expand Down Expand Up @@ -135,9 +133,7 @@
(assoc :audit-data {:new hoks})))
(catch Exception e
(case (:error (ex-data e))
:disallowed-update (assoc
(response/bad-request! {:error (.getMessage e)})
:audit-data {:new hoks})
:disallowed-update (response/bad-request! {:error (.getMessage e)})
:duplicate (do (log/warnf
"HOKS with opiskeluoikeus-oid %s already exists"
(:opiskeluoikeus-oid hoks))
Expand Down Expand Up @@ -197,14 +193,15 @@
"Change contents of HOKS with particular ID"
[hoks request db-handler]
(try
(h/check-hoks-for-update! (:hoks request) hoks)
(let [hoks-db (db-handler (:id (:hoks request))
(h/add-missing-oht-yksiloiva-tunniste hoks))]
(assoc (response/no-content) :audit-data {:new hoks}))
(let [old-hoks (:hoks request)]
(h/check-hoks-for-update! old-hoks hoks)
(let [hoks-db (db-handler (:id (:hoks request))
(h/add-missing-oht-yksiloiva-tunniste hoks))]
(assoc (response/no-content) :audit-data {:new hoks
:old old-hoks})))
(catch Exception e
(if (= (:error (ex-data e)) :disallowed-update)
(assoc (response/bad-request! {:error (.getMessage e)})
:audit-data {:new hoks})
(response/bad-request! {:error (.getMessage e)})
(throw e)))))

(defn- get-vastaajatunnus-info
Expand Down
7 changes: 5 additions & 2 deletions src/oph/ehoks/virkailija/system_handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@
:path-params [hoks-id :- s/Int]
:return (restful/response {})
(if (pos? (first (db-hoks/delete-hoks-by-hoks-id hoks-id)))
(restful/rest-ok {})
(assoc (restful/rest-ok {})
:audit-data {:old {:id hoks-id}})
(response/not-found {:error "No HOKS found with given hoks-id"})))

(c-api/PATCH "/hoks/:hoks-id/undo-shallow-delete" request
Expand All @@ -187,7 +188,9 @@
:path-params [hoks-id :- s/Int]
:return (restful/response {})
(if (pos? (first (db-hoks/undo-shallow-delete hoks-id)))
(restful/rest-ok {})
(assoc (restful/rest-ok {})
:audit-data {:old {:id hoks-id}
:new {:id hoks-id :deleted_at "*REMOVED*"}})
(response/not-found {:error "No HOKS found with given hoks-id"})))

(c-api/POST "/hoks/:hoks-id/resend-aloitusherate" request
Expand Down
3 changes: 2 additions & 1 deletion test/oph/ehoks/virkailija/handler_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
{:status 200
:body {:oid "1.2.246.562.15.760000000010"
:oppilaitos {:oid "1.2.246.562.10.1200000000010"}
:tyyppi {:koodiarvo "ammatillinenkoulutus"}}}
:tyyppi {:koodiarvo "ammatillinenkoulutus"}
:alkamispäivä "2019-01-01"}}
(.endsWith
url "/koski/api/opiskeluoikeus/1.2.246.562.15.760000000011")
{:status 200
Expand Down

0 comments on commit a90f781

Please sign in to comment.