Compare commits

..

8 Commits

Author SHA1 Message Date
Alejandro Alonso
6564736d3e 🐛 Fix challenge redirect with parameters 2024-09-11 12:03:32 +02:00
Alejandro
ea7768117c Merge pull request #5082 from penpot/superalex-fix-challenge-redirect-with-parameters
🐛 Fix challenge redirect with parameters
2024-09-11 11:33:45 +02:00
Alejandro Alonso
5bfb39cdf6 🐛 Fix challenge redirect with parameters 2024-09-11 11:23:19 +02:00
Andrey Antukh
3f34aa92fa Add support for optional human challenge 2024-09-06 13:39:53 +02:00
Alejandro
b2010e5fd8 Merge pull request #5052 from penpot/niwinz-bugfix-srepl-helpers
🐛 Fix issues with srepl helper for profile deletion in bulk
2024-09-04 12:01:55 +02:00
Andrey Antukh
d5f5c440dd 🐛 Fix issues with srepl helper for profile deletion in bulk 2024-09-04 11:09:05 +02:00
Alejandro
9f52709a42 Merge pull request #5047 from penpot/niwinz-hotfix-webhooks
🐛 Fix incorrect params handling on webhook processing task
2024-09-04 08:57:53 +02:00
Andrey Antukh
85444f5a47 🐛 Fix incorrect params handling on webhook processing task 2024-09-03 17:19:35 +02:00
10 changed files with 94 additions and 27 deletions

View File

@@ -1,5 +1,11 @@
# CHANGELOG
## 2.1.5
### :bug: Bugs fixed
- Fix broken webhooks [Taiga #8370](https://tree.taiga.io/project/penpot/issue/8370)
## 2.1.4
### :bug: Bugs fixed

View File

@@ -263,6 +263,8 @@
(assoc ::wrk/dedupe dedupe?)
(assoc ::wrk/label label)
(assoc ::wrk/params (-> params
(dissoc :source)
(dissoc :context)
(dissoc :ip-addr)
(dissoc :type)))))))
params))

View File

@@ -66,21 +66,18 @@
(defmethod ig/init-key ::process-event-handler
[_ cfg]
(fn [{:keys [props] :as task}]
(let [event (:event props)]
(l/dbg :hint "process webhook event" :name (:name event))
(when-let [items (lookup-webhooks cfg event)]
(l/trc :hint "webhooks found for event" :total (count items))
(db/tx-run! cfg (fn [cfg]
(doseq [item items]
(wrk/submit! (-> cfg
(assoc ::wrk/task :run-webhook)
(assoc ::wrk/queue :webhooks)
(assoc ::wrk/max-retries 3)
(assoc ::wrk/params {:event event
:config item}))))))))))
(l/dbg :hint "process webhook event" :name (:name props))
(when-let [items (lookup-webhooks cfg props)]
(l/trc :hint "webhooks found for event" :total (count items))
(db/tx-run! cfg (fn [cfg]
(doseq [item items]
(wrk/submit! (-> cfg
(assoc ::wrk/task :run-webhook)
(assoc ::wrk/queue :webhooks)
(assoc ::wrk/max-retries 3)
(assoc ::wrk/params {:event props
:config item})))))))))
;; --- RUN
(declare interpret-exception)

View File

@@ -727,13 +727,15 @@
deleted 0
total 0]
(if-let [email (first emails)]
(if-let [profile (db/get* system :profile
{:email (str/lower email)}
{::db/remove-deleted false})]
(if-let [profile (some-> (db/get* system :profile
{:email (str/lower email)}
{::db/remove-deleted false})
(profile/decode-row))]
(do
(audit/insert! system
{::audit/name "delete-profile"
::audit/type "action"
::audit/profile-id (:id profile)
::audit/tracked-at deleted-at
::audit/props (audit/profile->props profile)
::audit/context {:triggered-by "srepl"

View File

@@ -21,10 +21,9 @@
(with-mocks [submit-mock {:target 'app.worker/submit! :return nil}]
(let [prof (th/create-profile* 1 {:is-active true})
res (th/run-task! :process-webhook-event
{:event
{:type "command"
:name "create-project"
:props {:team-id (:default-team-id prof)}}})]
{:type "command"
:name "create-project"
:props {:team-id (:default-team-id prof)}})]
(t/is (= 0 (:call-count @submit-mock)))
(t/is (nil? res)))))
@@ -34,10 +33,9 @@
(let [prof (th/create-profile* 1 {:is-active true})
whk (th/create-webhook* {:team-id (:default-team-id prof)})
res (th/run-task! :process-webhook-event
{:event
{:type "command"
:name "create-project"
:props {:team-id (:default-team-id prof)}}})]
{:type "command"
:name "create-project"
:props {:team-id (:default-team-id prof)}})]
(t/is (= 1 (:call-count @submit-mock)))
(t/is (nil? res)))))

View File

@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Penpot - Challenge</title>
<link rel="icon" href="images/favicon.png" />
<script>
var params = new URL(document.location.toString()).searchParams;
var redirectPath = params.get("redirect");
setTimeout(() => {
location.href = "/#" + redirectPath;
}, 100);
</script>
</head>
<body>
</body>
</html>

View File

@@ -333,6 +333,13 @@ async function generateTemplates() {
await fs.writeFile("./resources/public/index.html", content);
content = await renderTemplate(
"resources/templates/challenge.mustache",
{},
partials,
);
await fs.writeFile("./resources/public/challenge.html", content);
content = await renderTemplate("resources/templates/preview-body.mustache", {
manifest: manifest,
translations: JSON.stringify(translations),

View File

@@ -137,13 +137,26 @@
(when (not= previous-email email)
(set-current-team! nil)))))))
(defn- on-fetch-profile-exception
[cause]
(let [data (ex-data cause)]
(if (and (= :authorization (:type data))
(= :challenge-required (:code data)))
(let [path (rt/get-current-path)
href (->> path
(str "/challenge.html?redirect=")
(js/encodeURIComponent))]
(rx/of (rt/nav-raw href)))
(rx/throw cause))))
(defn fetch-profile
[]
(ptk/reify ::fetch-profile
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/cmd! :get-profile)
(rx/map profile-fetched)))))
(rx/map profile-fetched)
(rx/catch on-fetch-profile-exception)))))
;; --- EVENT: login

View File

@@ -17,7 +17,7 @@
[cuerdas.core :as str]))
(defn handle-response
[{:keys [status body] :as response}]
[{:keys [status body headers] :as response}]
(cond
(= 204 status)
;; We need to send "something" so the streams listening downstream can act
@@ -40,6 +40,13 @@
{:type :validation
:code :request-body-too-large}))
(and (= status 403)
(or (= "cloudflare" (get headers "server"))
(= "challenge" (get headers "cf-mitigated"))))
(rx/throw (ex-info "http error"
{:type :authorization
:code :challenge-required}))
(and (>= status 400) (map? body))
(rx/throw (ex-info "http error" body))
@@ -48,6 +55,7 @@
(ex-info "http error"
{:type :unexpected-error
:status status
:headers headers
:data body}))))
(def default-options

View File

@@ -13,8 +13,10 @@
[app.main.data.events :as ev]
[app.util.browser-history :as bhistory]
[app.util.dom :as dom]
[app.util.globals :as globals]
[app.util.timers :as ts]
[beicon.v2.core :as rx]
[cuerdas.core :as str]
[goog.events :as e]
[potok.v2.core :as ptk]
[reitit.core :as r]))
@@ -143,6 +145,20 @@
(= (.-hostname location) (:host referrer)))
(nav-back))))
(defn nav-raw
[href]
(ptk/reify ::nav-raw
ptk/EffectEvent
(effect [_ _ _]
(set! (.-href globals/location) href))))
(defn get-current-path
[]
(let [hash (.-hash globals/location)]
(if (str/starts-with? hash "#")
(subs hash 1)
hash)))
;; --- History API
(defn initialize-history