Skip to content

Commit

Permalink
Update notif. when req. to join priv. Forum channel
Browse files Browse the repository at this point in the history
[Re #1625]

The template of the email and its data has changed now, so we provide
the link for the GPML admins to click and be able to provide the needed
info to the front-end to perform an automated request (once the admin
confirms it there) so the target user is added to the requested private
Forum channel.
  • Loading branch information
joseAyudarte91 committed Oct 5, 2023
1 parent 0319f74 commit 2043a3c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
8 changes: 8 additions & 0 deletions backend/src/gpml/handler/chat.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@

(def ^:private send-private-channel-invitation-request-params-schema
[:map
[:channel_id
{:optional false
:swagger {:description "The channel id"
:type "string"
:allowEmptyValue false}}
[:string {:min 1}]]
[:channel_name
{:optional false
:swagger {:description "The channel name"
Expand Down Expand Up @@ -157,9 +163,11 @@
:root-context? true})
(r/forbidden {:message "Unauthorized"})
(let [channel-name (get-in parameters [:body :channel_name])
channel-id (get-in parameters [:body :channel_id])
result (srv.chat/send-private-channel-invitation-request
config
user
channel-id
channel-name)]
(if (:success? result)
(r/ok {})
Expand Down
3 changes: 2 additions & 1 deletion backend/src/gpml/service/chat.clj
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,11 @@
channel-id))

(defn send-private-channel-invitation-request
[{:keys [db mailjet-config]} user channel-name]
[{:keys [db mailjet-config]} user channel-id channel-name]
(let [super-admins (db.rbac-util/get-super-admins-details (:spec db) {})]
(util.email/notify-admins-new-chat-private-channel-invitation-request
mailjet-config
super-admins
user
channel-id
channel-name)))
8 changes: 6 additions & 2 deletions backend/src/gpml/util.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns gpml.util
(:require [clojure.string :as str]
[clojure.walk :as w]
[gpml.util.regular-expressions :as util.regex])
[gpml.util.regular-expressions])
(:import [java.io File]
[java.net URL]
[java.net URL URLEncoder]
[java.util Base64]
[java.util UUID]))

Expand Down Expand Up @@ -182,3 +182,7 @@
[email]
(and string?
(re-matches gpml.util.regular-expressions/email-re email)))

(defn encode-url-param
[^String param]
(URLEncoder/encode param "utf-8"))
43 changes: 25 additions & 18 deletions backend/src/gpml/util/email.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
(:require [clj-http.client :as client]
[clojure.string :as str]
[gpml.db.stakeholder :as db.stakeholder]
[gpml.handler.util :as util]
[gpml.handler.util :as h.util]
[gpml.util :as util]
[jsonista.core :as j]))

(defn make-message [sender receiver subject text html]
Expand Down Expand Up @@ -87,7 +88,7 @@ Your submission has been published to %s/%s/%s.
- UNEP GPML Digital Platform
"
(:app-domain mailjet-config)
(util/get-api-topic-type topic-type topic-item)
(h.util/get-api-topic-type topic-type topic-item)
(:id topic-item)))

(defn notify-user-review-rejected-text [mailjet-config topic-type topic-item]
Expand All @@ -100,37 +101,38 @@ again, please visit this URL: %s/edit-%s/%s
- UNEP GPML Digital Platform
"
(util/get-title topic-type topic-item)
(h.util/get-title topic-type topic-item)
(:app-domain mailjet-config)
(-> (util/get-api-topic-type topic-type topic-item)
(-> (h.util/get-api-topic-type topic-type topic-item)
(str/replace "_" "-"))
(:id topic-item)))

(defn notify-user-review-subject [mailjet-config review-status topic-type topic-item]
(format "[%s] %s %s"
(:app-name mailjet-config)
(util/get-display-topic-type topic-type topic-item)
(h.util/get-display-topic-type topic-type topic-item)
(str/lower-case review-status)))

(defn notify-private-channel-invitation-request-subject
[app-name channel-name]
(format "[%s] Invitation request for private channel %s" app-name channel-name))
(format "[%s] Request to Join %s" app-name channel-name))

(defn notify-user-about-chat-private-channel-invitation-request-accepted-subject
[app-name channel-name]
(format "[%s] You've joined %s" app-name channel-name))

(defn notify-private-channel-invitation-request-text
[admin-name user-name user-email channel-name]
(format "Dear %s
[user-name channel-name review-request-link]
(format "%s wants to join %s
%s user with email %s, is requesting access to the private channel %s.
Visit the link below to review the request:
%s
- UNEP GPML Digital Platform"
admin-name
user-name
user-email
channel-name))
channel-name
review-request-link))

(defn notify-user-about-chat-private-channel-invitation-request-accepted-text
[channel-name base-url]
Expand Down Expand Up @@ -213,7 +215,7 @@ View the forums in your GPML workspace:
(send-email mailjet-config sender subject receivers texts htmls)))

(defn notify-admins-new-chat-private-channel-invitation-request
[mailjet-config admins user channel-name]
[mailjet-config admins user channel-id channel-name]
(let [sender unep-sender
subject (notify-private-channel-invitation-request-subject
(:app-name mailjet-config)
Expand All @@ -222,11 +224,16 @@ View the forums in your GPML workspace:
(fn [admin] {:Name (get-user-full-name admin)
:Email (:email admin)})
admins)
texts (map (fn [receiver]
(notify-private-channel-invitation-request-text (:Name receiver)
(get-user-full-name user)
(:email user)
channel-name))
texts (map (fn [_receiver]
(notify-private-channel-invitation-request-text
(get-user-full-name user)
channel-name
(format "%s/admin/forum/add-user?user_id=%s&channel_id=%s&email=%s&channel_name=%s"
(:app-domain mailjet-config)
(:id user)
(util/encode-url-param channel-id)
(util/encode-url-param (:email user))
(util/encode-url-param channel-name))))
receivers)
htmls (repeat nil)
{:keys [status body]} (send-email mailjet-config sender subject receivers texts htmls)]
Expand Down

0 comments on commit 2043a3c

Please sign in to comment.