diff --git a/backend/src/gpml/handler/chat.clj b/backend/src/gpml/handler/chat.clj index 9d80b813b..81c7e4ea0 100644 --- a/backend/src/gpml/handler/chat.clj +++ b/backend/src/gpml/handler/chat.clj @@ -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" @@ -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 {}) diff --git a/backend/src/gpml/service/chat.clj b/backend/src/gpml/service/chat.clj index 435cf64f4..19faa318f 100644 --- a/backend/src/gpml/service/chat.clj +++ b/backend/src/gpml/service/chat.clj @@ -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))) diff --git a/backend/src/gpml/util.clj b/backend/src/gpml/util.clj index f7049fede..1eb3cfe91 100644 --- a/backend/src/gpml/util.clj +++ b/backend/src/gpml/util.clj @@ -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])) @@ -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")) diff --git a/backend/src/gpml/util/email.clj b/backend/src/gpml/util/email.clj index 83520911e..02e45975a 100644 --- a/backend/src/gpml/util/email.clj +++ b/backend/src/gpml/util/email.clj @@ -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] @@ -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] @@ -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] @@ -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) @@ -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)]