Skip to content

Commit

Permalink
Merge pull request #556 from solita/feature/AE-2283-public-ui-changes
Browse files Browse the repository at this point in the history
Feature/ae 2283 public UI changes
  • Loading branch information
solita-juhohaa authored Sep 18, 2024
2 parents 8cdb90e + 064bfaf commit fbde184
Show file tree
Hide file tree
Showing 16 changed files with 574 additions and 5 deletions.
6 changes: 6 additions & 0 deletions etp-core/etp-backend/src/main/clj/solita/common/aws/s3.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
{:Bucket bucket
:Key key}))

(defn delete-object [{:keys [client bucket]} key]
(aws.utils/invoke client
:DeleteObject
{:Bucket bucket
:Key key}))

(defn create-multipart-upload [{:keys [client bucket]} key]
(aws.utils/invoke client
:CreateMultipartUpload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
[solita.etp.schema.viesti :as viesti-schema]
[solita.etp.security :as security]
[solita.etp.service.energiatodistus :as energiatodistus-service]
[solita.etp.service.energiatodistus-destruction :as energiatodistus-destruction-service]
[solita.etp.service.energiatodistus-csv :as energiatodistus-csv-service]
[solita.etp.service.energiatodistus-pdf :as energiatodistus-pdf-service]
[solita.etp.service.energiatodistus-search :as energiatodistus-search-service]
[solita.etp.service.energiatodistus-xlsx :as energiatodistus-xlsx-service]
[solita.etp.service.kayttaja :as kayttaja-service]
[solita.etp.service.json :as json]
[solita.etp.service.rooli :as rooli-service]
[solita.etp.service.viesti :as viesti-service])
Expand Down Expand Up @@ -257,3 +259,15 @@
["/legacy"
["/2013" (xml-api/post 2013)]
["/2018" (xml-api/post 2018)]]]])

(def internal-routes
[["/energiatodistukset"
["/anonymize-and-delete-expired"
{:post {:summary "Anonymisoi vanhentuneet energiatodistukset ja poistaa niihin linkittyvät dokumentit."
:middleware [[security/wrap-db-application-name
(kayttaja-service/system-kayttaja :expiration)]
[security/wrap-whoami-for-internal-expiration-api]]
:responses {200 {:body nil}}
:handler (fn [{:keys [db aws-s3-client]}]
(r/response (energiatodistus-destruction-service/destroy-expired-energiatodistukset!
db aws-s3-client)))}}]]])
1 change: 1 addition & 0 deletions etp-core/etp-backend/src/main/clj/solita/etp/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
["/internal"
(concat (tag "Laskutus API" laskutus-api/routes)
(tag "Laatija Internal API" laatija-api/internal-routes)
(tag "Energiatodistus Internal API" energiatodistus-api/internal-routes)
(tag "Aineisto Internal API" aineisto-api/internal-routes))]]
(when config/allow-palveluvayla-api
["/palveluvayla" ["/openapi.json" {:get {:no-doc true :openapi {:info {:title "Energiatodistuspalvelu API" :description "Hae energiatodistuksia pdf tai json muodoissa"}
Expand Down
5 changes: 5 additions & 0 deletions etp-core/etp-backend/src/main/clj/solita/etp/security.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
(handler (assoc req :whoami {:id (:aineisto kayttaja-service/system-kayttaja)
:rooli -1}))))

(defn wrap-whoami-for-internal-expiration-api [handler]
(fn [req]
(handler (assoc req :whoami {:id (:expiration kayttaja-service/system-kayttaja)
:rooli -1}))))

(defn wrap-access [handler]
(fn [{:keys [request-method whoami] :as req}]
(let [access (-> req :reitit.core/match :data (get request-method) :access)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
(ns solita.etp.service.energiatodistus-destruction
"Contains functions for anonymizing the energiatodistus and removing
data linked to it."
(:require [clojure.java.jdbc :as jdbc]
[clojure.tools.logging :as log]
[solita.etp.db :as db]
[solita.etp.service.complete-energiatodistus :as complete-energiatodistus-service]
[solita.etp.service.energiatodistus :as energiatodistus-service]
[solita.etp.service.file :as file])
(:import (clojure.lang ExceptionInfo)
(org.postgresql.util PSQLException)))

(db/require-queries 'energiatodistus-destruction)

(defn- get-currently-expired-todistus-ids [db]
(->> (energiatodistus-destruction-db/select-expired-energiatodistus-ids db)
(map :id)))

(defn- anonymize-energiatodistus! [db id]
(energiatodistus-destruction-db/anonymize-energiatodistus! db {:id id}))

(defn- destroy-energiatodistus-audit-data! [db id]
(energiatodistus-destruction-db/destroy-energiatodistus-audit-information! db {:id id}))

(defn- delete-energiatodistus-pdf! [aws-s3-client id language]
(let [file-key (energiatodistus-service/file-key id language)]
(file/delete-file aws-s3-client file-key)
(log/info (str "Deleted " file-key " from S3"))))

(defn- delete-energiatodistus-pdfs! [db aws-s3-client id]
(let [language-codes (-> (complete-energiatodistus-service/find-complete-energiatodistus db id)
:perustiedot
:kieli
energiatodistus-service/language-id->codes)]
(doseq [language-code language-codes]
(delete-energiatodistus-pdf! aws-s3-client id language-code))))

(defn- destroy-expired-energiatodistus! [db aws-s3-client id]
(jdbc/with-db-transaction [db db]
(anonymize-energiatodistus! db id)
(destroy-energiatodistus-audit-data! db id))
(delete-energiatodistus-pdfs! db aws-s3-client id)
(log/info (str "Destroyed energiatodistus (id: " id ")")))

(defn destroy-expired-energiatodistukset! [db aws-s3-client]
(log/info (str "Destruction of expired energiatodistukset initiated."))
(let [expired-todistukset (get-currently-expired-todistus-ids db)]
(map #(destroy-expired-energiatodistus! db aws-s3-client %) expired-todistukset)
nil))

3 changes: 3 additions & 0 deletions etp-core/etp-backend/src/main/clj/solita/etp/service/file.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
(defn upsert-file-from-input-stream [aws-s3-client key is]
(upsert-file-from-bytes aws-s3-client key (.readAllBytes is)))

(defn delete-file [aws-s3-client key]
(s3/delete-object aws-s3-client key))

(defn find-file [aws-s3-client key]
(some-> (s3/get-object aws-s3-client key)
io/input-stream))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@
{:communication -3
:laskutus -2
:presigned -4
:aineisto -5})
:aineisto -5
:expiration -6})
Loading

0 comments on commit fbde184

Please sign in to comment.