✨ Settle task rules and notifications from the design-review answers

Apply the answers to the review of #12939 about tasks:

- A task records whether it created its thread on the canvas
  (file_task.created_thread). Relinking moves only such a thread, so
  a task made from the first message of an existing thread no longer
  drags that thread along.
- Renaming a canvas task rewrites the first message of its thread when
  the renamer wrote it. The renamed event is written in every case.
- A team owner or admin may delete a task besides its author. Deleting
  a thread writes a deleted event for each task it removes.
- A Tasks email setting (all, mine, none; mine by default) governs task
  emails. Done emails the creator, reopened emails the assignee, and
  nobody is emailed about their own move. A task created on the canvas
  sends no new-comment email to all-comments subscribers.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
Álvaro Tejero Cantero 2026-11-23 15:56:59 +01:00
parent 96b89436e3
commit 910ca1f90a
No known key found for this signature in database
20 changed files with 1191 additions and 149 deletions

View File

@ -0,0 +1,251 @@
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<title>
</title>
<!--[if !mso]><!-- -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--<![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
#outlook a {
padding: 0;
}
body {
margin: 0;
padding: 0;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
table,
td {
border-collapse: collapse;
mso-table-lspace: 0pt;
mso-table-rspace: 0pt;
}
img {
border: 0;
height: auto;
line-height: 100%;
outline: none;
text-decoration: none;
-ms-interpolation-mode: bicubic;
}
p {
display: block;
margin: 13px 0;
}
</style>
<!--[if mso]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!--[if lte mso 11]>
<style type="text/css">
.mj-outlook-group-fix { width:100% !important; }
</style>
<![endif]-->
<!--[if !mso]><!-->
<link href="https://fonts.googleapis.com/css?family=Source%20Sans%20Pro" rel="stylesheet" type="text/css">
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Source%20Sans%20Pro);
</style>
<!--<![endif]-->
<style type="text/css">
@media only screen and (min-width:480px) {
.mj-column-per-100 {
width: 100% !important;
max-width: 100%;
}
.mj-column-px-425 {
width: 425px !important;
max-width: 425px;
}
}
</style>
<style type="text/css">
@media only screen and (max-width:480px) {
table.mj-full-width-mobile {
width: 100% !important;
}
td.mj-full-width-mobile {
width: auto !important;
}
}
</style>
</head>
<body style="background-color:#E5E5E5;">
<div style="background-color:#E5E5E5;">
<!--[if mso | IE]>
<table
align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
>
<tr>
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
<![endif]-->
<div style="margin:0px auto;max-width:600px;">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
<tbody>
<tr>
<td style="direction:ltr;font-size:0px;padding:0;text-align:center;">
<!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
<tr>
<td
class="" style="vertical-align:top;width:600px;"
>
<![endif]-->
<div class="mj-column-per-100 mj-outlook-group-fix"
style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;"
width="100%">
<tr>
<td align="left" style="font-size:0px;padding:16px;word-break:break-word;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation"
style="border-collapse:collapse;border-spacing:0px;">
<tbody>
<tr>
<td style="width:97px;">
<img height="32" src="{{ public-uri }}/images/email/logo-penpot.svg"
style="border:0;display:block;outline:none;text-decoration:none;height:32px;width:100%;font-size:13px;"
width="97" />
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</div>
<!--[if mso | IE]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
</tbody>
</table>
</div>
<!--[if mso | IE]>
</td>
</tr>
</table>
<table
align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
>
<tr>
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
<![endif]-->
<div style="background:#FFFFFF;background-color:#FFFFFF;margin:0px auto;max-width:600px;">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation"
style="background:#FFFFFF;background-color:#FFFFFF;width:100%;">
<tbody>
<tr>
<td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;">
<!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
<tr>
<td
class="" style="vertical-align:top;width:600px;"
>
<![endif]-->
<div class="mj-column-per-100 mj-outlook-group-fix"
style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;"
width="100%">
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div
style="font-family:Source Sans Pro, sans-serif;font-size:24px;font-weight:600;line-height:150%;text-align:left;color:#000000;">
Hello {{name|abbreviate:25}}!</div>
</td>
</tr>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
<span style="font-weight:bold;">{{ source-user }}</span> marked this task as done:</div>
</td>
</tr>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div style="font-family:Source Sans Pro, sans-serif;font-size:16px;font-style:italic;line-height:150%;text-align:left;color:#212426;
border-top: 1px solid #bfbfbf; border-bottom: 1px solid #bfbfbf; padding: 32px 0px;">
{{ task-title }}
</div>
</td>
</tr>
<tr>
<td align="center" vertical-align="middle"
style="font-size:0px;padding:10px 25px;word-break:break-word;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation"
style="border-collapse:separate;line-height:100%;">
<tr>
<td align="center" bgcolor="#6911d4" role="presentation"
style="border:none;border-radius:8px;cursor:auto;mso-padding-alt:10px 25px;background:#6911d4;"
valign="middle">
<a href="{{ task-url }}"
style="display:inline-block;background:#6911d4;color:#FFFFFF;font-family:Source Sans Pro, sans-serif;font-size:16px;font-weight:normal;line-height:120%;margin:0;text-decoration:none;text-transform:none;padding:10px 25px;mso-padding-alt:0px;border-radius:8px;"
target="_blank"> OPEN THE TASK </a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
Open it to verify it, or reopen it if the work is not finished.</div>
</td>
</tr>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
The Penpot team.</div>
</td>
</tr>
</table>
</div>
<!--[if mso | IE]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
</tbody>
</table>
</div>
{% include "app/email/includes/footer.html" %}
</div>
</body>
</html>

View File

@ -0,0 +1 @@
A task is ready to verify

View File

@ -0,0 +1,11 @@
Hello {{name|abbreviate:25}}!
{{ source-user }} marked this task as done:
{{ task-title }}
Open it to verify it, or reopen it if the work is not finished.
{{ task-url }}
The Penpot team.

View File

@ -0,0 +1,251 @@
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<title>
</title>
<!--[if !mso]><!-- -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--<![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
#outlook a {
padding: 0;
}
body {
margin: 0;
padding: 0;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
table,
td {
border-collapse: collapse;
mso-table-lspace: 0pt;
mso-table-rspace: 0pt;
}
img {
border: 0;
height: auto;
line-height: 100%;
outline: none;
text-decoration: none;
-ms-interpolation-mode: bicubic;
}
p {
display: block;
margin: 13px 0;
}
</style>
<!--[if mso]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!--[if lte mso 11]>
<style type="text/css">
.mj-outlook-group-fix { width:100% !important; }
</style>
<![endif]-->
<!--[if !mso]><!-->
<link href="https://fonts.googleapis.com/css?family=Source%20Sans%20Pro" rel="stylesheet" type="text/css">
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Source%20Sans%20Pro);
</style>
<!--<![endif]-->
<style type="text/css">
@media only screen and (min-width:480px) {
.mj-column-per-100 {
width: 100% !important;
max-width: 100%;
}
.mj-column-px-425 {
width: 425px !important;
max-width: 425px;
}
}
</style>
<style type="text/css">
@media only screen and (max-width:480px) {
table.mj-full-width-mobile {
width: 100% !important;
}
td.mj-full-width-mobile {
width: auto !important;
}
}
</style>
</head>
<body style="background-color:#E5E5E5;">
<div style="background-color:#E5E5E5;">
<!--[if mso | IE]>
<table
align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
>
<tr>
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
<![endif]-->
<div style="margin:0px auto;max-width:600px;">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
<tbody>
<tr>
<td style="direction:ltr;font-size:0px;padding:0;text-align:center;">
<!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
<tr>
<td
class="" style="vertical-align:top;width:600px;"
>
<![endif]-->
<div class="mj-column-per-100 mj-outlook-group-fix"
style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;"
width="100%">
<tr>
<td align="left" style="font-size:0px;padding:16px;word-break:break-word;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation"
style="border-collapse:collapse;border-spacing:0px;">
<tbody>
<tr>
<td style="width:97px;">
<img height="32" src="{{ public-uri }}/images/email/logo-penpot.svg"
style="border:0;display:block;outline:none;text-decoration:none;height:32px;width:100%;font-size:13px;"
width="97" />
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</div>
<!--[if mso | IE]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
</tbody>
</table>
</div>
<!--[if mso | IE]>
</td>
</tr>
</table>
<table
align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
>
<tr>
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
<![endif]-->
<div style="background:#FFFFFF;background-color:#FFFFFF;margin:0px auto;max-width:600px;">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation"
style="background:#FFFFFF;background-color:#FFFFFF;width:100%;">
<tbody>
<tr>
<td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;">
<!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
<tr>
<td
class="" style="vertical-align:top;width:600px;"
>
<![endif]-->
<div class="mj-column-per-100 mj-outlook-group-fix"
style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;"
width="100%">
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div
style="font-family:Source Sans Pro, sans-serif;font-size:24px;font-weight:600;line-height:150%;text-align:left;color:#000000;">
Hello {{name|abbreviate:25}}!</div>
</td>
</tr>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
<span style="font-weight:bold;">{{ source-user }}</span> reopened this task:</div>
</td>
</tr>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div style="font-family:Source Sans Pro, sans-serif;font-size:16px;font-style:italic;line-height:150%;text-align:left;color:#212426;
border-top: 1px solid #bfbfbf; border-bottom: 1px solid #bfbfbf; padding: 32px 0px;">
{{ task-title }}
</div>
</td>
</tr>
<tr>
<td align="center" vertical-align="middle"
style="font-size:0px;padding:10px 25px;word-break:break-word;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation"
style="border-collapse:separate;line-height:100%;">
<tr>
<td align="center" bgcolor="#6911d4" role="presentation"
style="border:none;border-radius:8px;cursor:auto;mso-padding-alt:10px 25px;background:#6911d4;"
valign="middle">
<a href="{{ task-url }}"
style="display:inline-block;background:#6911d4;color:#FFFFFF;font-family:Source Sans Pro, sans-serif;font-size:16px;font-weight:normal;line-height:120%;margin:0;text-decoration:none;text-transform:none;padding:10px 25px;mso-padding-alt:0px;border-radius:8px;"
target="_blank"> OPEN THE TASK </a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
The work is back with you.</div>
</td>
</tr>
<tr>
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
The Penpot team.</div>
</td>
</tr>
</table>
</div>
<!--[if mso | IE]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
</tbody>
</table>
</div>
{% include "app/email/includes/footer.html" %}
</div>
</body>
</html>

View File

@ -0,0 +1 @@
A task is reopened

View File

@ -0,0 +1,11 @@
Hello {{name|abbreviate:25}}!
{{ source-user }} reopened this task:
{{ task-title }}
The work is back with you.
{{ task-url }}
The Penpot team.

View File

@ -606,6 +606,34 @@
:id ::tasks-moved
:schema schema:tasks-moved))
(def ^:private schema:task-done
[:map
[:name ::sm/text]
[:source-user ::sm/text]
[:task-title ::sm/text]
[:task-url ::sm/text]])
(def task-done
"Email sent to the author of a task when somebody marks it as done, so
they verify it."
(template-factory
:id ::task-done
:schema schema:task-done))
(def ^:private schema:task-reopened
[:map
[:name ::sm/text]
[:source-user ::sm/text]
[:task-title ::sm/text]
[:task-url ::sm/text]])
(def task-reopened
"Email sent to the assignee of a task when somebody reopens it: the
work is back with them."
(template-factory
:id ::task-reopened
:schema schema:task-reopened))
(def ^:private schema:comment-mention
[:map
[:name ::sm/text]
@ -687,6 +715,8 @@
"comment-notification" (template-entry comment-notification schema:comment-notification)
"review-request" (template-entry review-request schema:review-request)
"task-assigned" (template-entry task-assigned schema:task-assigned)
"task-done" (template-entry task-done schema:task-done)
"task-reopened" (template-entry task-reopened schema:task-reopened)
"tasks-moved" (template-entry tasks-moved schema:tasks-moved)})
(defn render-template

View File

@ -593,7 +593,10 @@
:fn (mg/resource "app/migrations/sql/0814-mod-file-task-give-thread.sql")}
{:name "0815-add-file-branch-change-review-table"
:fn (mg/resource "app/migrations/sql/0815-add-file-branch-change-review-table.sql")}])
:fn (mg/resource "app/migrations/sql/0815-add-file-branch-change-review-table.sql")}
{:name "0816-mod-file-task-add-created-thread"
:fn (mg/resource "app/migrations/sql/0816-mod-file-task-add-created-thread.sql")}])
(defn apply-migrations!
[pool name migrations]

View File

@ -0,0 +1,13 @@
-- A task created on the canvas gets a thread whose first message is its
-- title. A task made from a message of a thread someone already wrote
-- keeps that thread and that message. The code derived the difference from
-- the message being the first of the thread, which is equally true of a
-- task made from the first message of an existing thread: relinking such
-- a task moved a thread its author never gave it, and a rename would
-- rewrite a message its author did not write.
--
-- Record the fact instead. No backfill: the databases of this line are
-- recreated from the migrations.
ALTER TABLE file_task
ADD COLUMN created_thread boolean NOT NULL DEFAULT false;

View File

@ -100,7 +100,11 @@
(not= :none (-> props :notifications :email-comments)))
(defn send-comment-emails!
[{:keys [::db/conn] :as cfg} profile comment thread file]
"Tell by email the people a comment concerns: the ones it mentions, the
ones the thread mentions and, unless `skip-subscriber-emails` is set,
the members with all comments on. A task created on the canvas sets it,
so its thread sends the task email and no comment email."
[{:keys [::db/conn] :as cfg} profile comment thread file & {:keys [skip-subscriber-emails]}]
(let [team-users (get-team-users conn (:team-id file))
comment-reference (format-comment-ref thread file)
comment-content (format-comment comment)
@ -159,20 +163,21 @@
:comment-url comment-url}))))
;; Send to users with the "all" flag activated
(doseq [user-id notificate-users-ids]
(let [{:keys [id fullname email props]} (get team-users user-id)]
(when (notification-email? id (:owner-id thread) props)
(eml/send-template
cfg
{::eml/reuse-conn true
::eml/template "comment-notification"
:public-uri (cf/get :public-uri)
:to email
:name fullname
:source-user (:fullname profile)
:comment-reference comment-reference
:comment-content comment-content
:comment-url comment-url}))))))
(when-not skip-subscriber-emails
(doseq [user-id notificate-users-ids]
(let [{:keys [id fullname email props]} (get team-users user-id)]
(when (notification-email? id (:owner-id thread) props)
(eml/send-template
cfg
{::eml/reuse-conn true
::eml/template "comment-notification"
:public-uri (cf/get :public-uri)
:to email
:name fullname
:source-user (:fullname profile)
:comment-reference comment-reference
:comment-content comment-content
:comment-url comment-url})))))))
(defn- decode-row
[{:keys [participants position mentions area anchor-type] :as row}]
@ -551,9 +556,11 @@
"Create a thread with its first message on the page `page-id` of
`file-id`, once the quotes of threads and comments allow it. It joins
the transaction of `cfg` when there is one: a task created on the canvas
gets its thread this way (`app.rpc.commands.files-task`). The caller
checks the permissions. Returns the thread with the id of its first
message (`:comment-id`)."
gets its thread this way (`app.rpc.commands.files-task`), with
`::skip-subscriber-emails` set so the thread sends no email to the
members with all comments on (the ones it mentions are still told). The
caller checks the permissions. Returns the thread with the id of its
first message (`:comment-id`)."
[cfg {:keys [::rpc/profile-id file-id page-id] :as params}]
(let [{:keys [team-id project-id] :as file} (get-file cfg file-id page-id)]
(-> cfg
@ -576,12 +583,14 @@
[cfg {:keys [::rpc/profile-id file-id page-id share-id] :as params}]
(let [perms (files/check-comment-permissions! cfg profile-id file-id share-id)]
(check-page-scope perms page-id)
(create-comment-thread cfg params)))
;; The flag belongs to the backend callers: a client may not silence
;; the emails of its team.
(create-comment-thread cfg (dissoc params ::skip-subscriber-emails))))
(defn- insert-comment-thread
[{:keys [::db/conn] :as cfg}
{:keys [::rpc/profile-id ::rpc/request-at ::file position content mentions frame-id
pull-request-id anchor]}]
pull-request-id anchor ::skip-subscriber-emails]}]
(let [;; NOTE: we take the next seq number from a separate query
;; because we need to lock the file for avoid race conditions
@ -636,7 +645,8 @@
(update-thread-seqn conn file-id seqn)
;; Send mentions emails
(send-comment-emails! cfg profile comment thread file)
(send-comment-emails! cfg profile comment thread file
:skip-subscriber-emails skip-subscriber-emails)
(-> thread
(add-owner profile)
@ -825,15 +835,35 @@
thread_id = NULL,
comment_id = NULL
WHERE thread_id = ?
AND deleted_at IS NULL")
AND deleted_at IS NULL
RETURNING id, title")
(defn- insert-task-event
"Record an event of a task that a thread delete removes, encoded as the
task commands of `app.rpc.commands.files-task` encode theirs. That
namespace owns the events, but it requires this one to create the thread
of a task, so the insert is repeated here instead of closing a cycle."
[conn task-id profile-id type payload]
(db/insert! conn :file-task-event
{:id (uuid/next)
:task-id task-id
:profile-id profile-id
:type type
:payload (some-> payload db/tjson)
:created-at (ct/now)}
{::db/return-keys false}))
(defn- delete-thread-tasks
"Delete the tasks of the thread `thread-id`, which live in its messages,
and tell the open clients of `file-id` once the transaction commits."
"Delete the tasks of the thread `thread-id`, which live in its messages.
Each one gets a `deleted` event first, since the row loses the thread and
the message it lived in, and the open clients of `file-id` are told once
the transaction commits."
[{:keys [::db/conn ::mbus/msgbus]} profile-id file-id thread-id]
(let [ts (ct/now)
result (db/exec-one! conn [sql:delete-thread-tasks ts ts thread-id])]
(when (pos? (db/get-update-count result))
(let [ts (ct/now)
tasks (db/exec! conn [sql:delete-thread-tasks ts ts thread-id])]
(doseq [{:keys [id title]} tasks]
(insert-task-event conn id profile-id "deleted" {:title title}))
(when (seq tasks)
(db/after-commit
#(mbus/pub! msgbus
:topic file-id

View File

@ -10,11 +10,12 @@
Every task lives in a message of a comment thread, so its thread can
go on: a task made from a message keeps that thread, and a task
created on the canvas gets a thread whose first message is its title.
A task may also belong to a design review. Everybody who can read the
file may create a task and move it between states; every move is
recorded as an event of the task with who made it, which is what the
thread of the task shows between its comments.
created on the canvas gets a thread whose first message is its title
(`created-thread` records which). A task may also belong to a design
review. Everybody who can read the file may create a task and move it
between states; every move is recorded as an event of the task with
who made it, which is what the thread of the task shows between its
comments.
The merge of a branch moves its tasks into main (`move-branch-tasks`,
called from `app.rpc.commands.files-branch`): the open ones keep going
@ -124,6 +125,7 @@
t.status,
t.assignee_id,
t.created_by,
t.created_thread,
t.page_id,
t.frame_id,
t.shape_id,
@ -213,25 +215,71 @@
:team-id team-id
:task-id id})]))
(defn- team-users
"The users of `team-id` by id, with their props: the task emails read
the notification setting of each one."
[conn team-id]
(->> (teams/get-users+props conn team-id)
(map profile/decode-row)
(d/index-by :id)))
(defn- task-emails?
"Whether the task emails of a file reach the profile with `props`:
`:none` refuses them all, and the rest (an absent setting counts as
`:partial`) admit them."
[props]
(not= :none (-> props :notifications :email-tasks)))
(defn- send-task-assigned-email
"Tell `assignee-id` that `actor-id` assigned the task to them. Nobody is
told about the tasks they assign to themselves."
told about the tasks they assign to themselves, and a profile that
refuses the task emails is told nothing."
[{:keys [::db/conn] :as cfg} team-id actor-id {:keys [assignee-id title] :as task}]
(when (and (some? assignee-id) (not= assignee-id actor-id))
(let [users (->> (teams/get-users+props conn team-id)
(map profile/decode-row)
(d/index-by :id))]
(when-let [{:keys [fullname email]} (get users assignee-id)]
(eml/send-template
cfg
{::eml/reuse-conn true
::eml/template "task-assigned"
:public-uri (cf/get :public-uri)
:to email
:name fullname
:source-user (get-in users [actor-id :fullname] "")
:task-title title
:task-url (format-task-url task team-id)})))))
(let [users (team-users conn team-id)]
(when-let [{:keys [fullname email props]} (get users assignee-id)]
(when (task-emails? props)
(eml/send-template
cfg
{::eml/reuse-conn true
::eml/template "task-assigned"
:public-uri (cf/get :public-uri)
:to email
:name fullname
:source-user (get-in users [actor-id :fullname] "")
:task-title title
:task-url (format-task-url task team-id)}))))))
(def ^:private status-email
"The mail a move of a task sends, and the person it tells: the creator
when the task is done, the assignee when it is reopened. The other
moves (verified, won't do) tell nobody."
{"done" {:recipient :created-by :template "task-done"}
"reopened" {:recipient :assignee-id :template "task-reopened"}})
(defn- send-task-status-email
"Tell the person a move of `task` concerns about it: its creator when
it is done, its assignee when it is reopened. Nobody is told about
their own move, and a profile that refuses the task emails is told
nothing."
[{:keys [::db/conn] :as cfg} actor-id {:keys [status file-id] :as task}]
(when-let [{:keys [recipient template]} (get status-email status)]
(when-let [recipient-id (get task recipient)]
(when (not= recipient-id actor-id)
(let [team-id (perms/get-team-id-for-file conn file-id)
users (team-users conn team-id)]
(when-let [{:keys [fullname email props]} (get users recipient-id)]
(when (task-emails? props)
(eml/send-template
cfg
{::eml/reuse-conn true
::eml/template template
:public-uri (cf/get :public-uri)
:to email
:name fullname
:source-user (get-in users [actor-id :fullname] "")
:task-title (:title task)
:task-url (format-task-url task team-id)}))))))))
;; --- COMMAND QUERY: get-file-tasks
@ -341,7 +389,9 @@
(defn- create-task-thread
"The thread of a task created on the canvas: its first message is the
title, it points at the layer of the task (at the spot of the canvas
when there is none) and belongs to the design review of the task."
when there is none) and belongs to the design review of the task. The
task tells its assignee by email, so the thread tells nobody that a
comment was added."
[cfg profile-id {:keys [file-id title page-id frame-id shape-id position pull-request-id]}]
(comments/create-comment-thread
cfg
@ -352,6 +402,7 @@
:frame-id frame-id
:position position
:content title
::comments/skip-subscriber-emails true
:anchor (if (some? shape-id)
{:type :layer :shape-id shape-id}
{:type :canvas})}
@ -362,8 +413,9 @@
message it was made from (`thread-id` and `comment-id`), or the first
message of a new thread that carries its title. A task created in a
design review belongs to it. The assignee, when there is one, must be
a member of the team and is told by email. A deleted file takes no
task: a merge deletes its branch file (see `lock-file`)."
a member of the team and is told by email. The thread created with the
task sends no comment email of its own. A deleted file takes no task:
a merge deletes its branch file (see `lock-file`)."
{::doc/added "2.16"
::webhooks/event? true
::sm/params schema:create-task}
@ -402,6 +454,7 @@
:review-title (:title review)
:thread-id (or thread-id (:id thread))
:comment-id (or comment-id (:comment-id thread))
:created-thread (some? thread)
:title (str/trim title)
:status "open"
:assignee-id assignee-id
@ -420,6 +473,31 @@
(send-task-assigned-email cfg team-id profile-id task)
task))))
;; --- Helpers: the message of a task
(defn- rename-task-message
"Rewrite the message of `task`, the first message of the thread the task
created, so the thread reads with the new `title`. Only the profile that
wrote the message renames it: anybody who can read the file may rename
a task, and that must not let them rewrite somebody else's words. A
task made from a message of an existing thread keeps that message as it
is. The message and its thread take the new modified time, as
`update-comment` makes them. The mentions stay: the message of a task
created on the canvas carries none, and a rename adds none."
[conn profile-id {:keys [comment-id thread-id created-thread title]} ts]
(when (and created-thread (some? comment-id))
(let [comment (db/get* conn :comment {:id comment-id} {::sql/for-update true})]
(when (and (some? comment) (= profile-id (:owner-id comment)))
(db/update! conn :comment
{:content title :modified-at ts}
{:id comment-id}
{::db/return-keys false})
(when (some? thread-id)
(db/update! conn :comment-thread
{:modified-at ts}
{:id thread-id}
{::db/return-keys false}))))))
;; --- COMMAND: update-task
(def ^:private schema:update-task
@ -431,7 +509,9 @@
(sv/defmethod ::update-task
"Rename a task or change its assignee. Each change is an event of the
task; a new assignee is told by email."
task, and a new assignee is told by email. A rename also rewrites the
first message of the thread the task created when the renamer wrote
it, so the thread reads with the new title."
{::doc/added "2.16"
::sm/params schema:update-task}
[cfg {:keys [::rpc/profile-id ::rpc/session-id id title] :as params}]
@ -451,7 +531,8 @@
reassign? (and (contains? params :assignee-id)
(not= (:assignee-id params) (:assignee-id task)))
rename? (and (some? title) (not= (str/trim title) (:title task)))
changes (cond-> {:updated-at (ct/now)}
ts (ct/now)
changes (cond-> {:updated-at ts}
rename? (assoc :title (str/trim title))
reassign? (assoc :assignee-id (:assignee-id params)))
task (merge task changes)]
@ -459,7 +540,8 @@
(check-assignee conn team-id (:assignee-id params)))
(db/update! conn :file-task changes {:id id} {::db/return-keys false})
(when rename?
(insert-event conn id profile-id "renamed" {:title (:title task)}))
(insert-event conn id profile-id "renamed" {:title (:title task)})
(rename-task-message conn profile-id task ts))
(when reassign?
(insert-event conn id profile-id "assigned" {:assignee-id (:assignee-id task)})
(send-task-assigned-email cfg team-id profile-id task))
@ -474,7 +556,9 @@
(sv/defmethod ::set-task-status
"Move a task to another state (see `transitions`). Anybody who can read
the file may do it; the event records who did."
the file may do it, and the event records who did. The creator of the
task is told by email when it is done and its assignee when it is
reopened."
{::doc/added "2.16"
::webhooks/event? true
::sm/params schema:set-task-status}
@ -485,7 +569,7 @@
(run-and-notify
cfg {:file-id (:file-id task) :profile-id profile-id :session-id session-id}
(comp vector :id)
(fn [{:keys [::db/conn]}]
(fn [{:keys [::db/conn] :as cfg}]
(let [task (get-task conn id {::sql/for-update true})
from (:status task)
ts (ct/now)]
@ -503,34 +587,22 @@
{:id id}
{::db/return-keys false})
(insert-event conn id profile-id "status" {:from from :to status})
(assoc task
:status status
:status-changed-at ts
:status-changed-by profile-id))))))
(let [task (assoc task
:status status
:status-changed-at ts
:status-changed-by profile-id)]
(send-task-status-email cfg profile-id task)
task))))))
;; --- Helpers: the thread created with a task
(def ^:private sql:get-first-comment
"SELECT id FROM comment
WHERE thread_id = ?
ORDER BY created_at ASC, id ASC
LIMIT 1")
(defn- created-with-task?
"The thread of `task` was created with it: the message of the task is
the first message of the thread. A thread a task was made from later
keeps its own place."
[conn {:keys [thread-id comment-id]}]
(and (some? thread-id)
(some? comment-id)
(= comment-id (:id (db/exec-one! conn [sql:get-first-comment thread-id])))))
(defn- move-task-thread
"Point the thread created with `task` where the task points now: at the
layer `shape-id`; with no layer, at the rectangle `area` of the canvas,
or at the spot `position` when there is no area either."
or at the spot `position` when there is no area either. A thread the
task was made from keeps its own place."
[conn task {:keys [frame-id shape-id area position]}]
(when (created-with-task? conn task)
(when (:created-thread task)
(db/update! conn :comment-thread
(cond
(some? shape-id)
@ -709,22 +781,32 @@
[:map {:title "delete-task" :closed true}
[:id ::sm/uuid]])
(defn- check-delete-permissions
"Deleting a task is allowed to its author and to the team admins and
owners of the file, which may clean up after someone who left the team.
Everybody else gets the same refusal, and a profile that cannot read
the file gets the usual not-found."
[cfg profile-id {:keys [id created-by file-id]}]
(let [perms (perms/get-file-read-permissions cfg profile-id file-id)]
(files/check-read-permissions! perms)
(when-not (or (= created-by profile-id) (:is-admin perms))
(ex/raise :type :validation
:code :not-allowed
:hint "only the author of a task or a team admin may delete it"
:task-id id))))
(sv/defmethod ::delete-task
"Delete a task. Only its author may; anybody who can read the file may
still move it to won't do. A `deleted` event, written before the task
goes, records who deleted it. Its thread stays: the message the task
lived in goes on as a plain comment."
"Delete a task. Its author and the team admins and owners of the file
may. Anybody who can read the file may still move it to won't do. A
`deleted` event, written before the task goes, records who deleted it.
Its thread stays: the message the task lived in goes on as a plain
comment."
{::doc/added "2.16"
::sm/params schema:delete-task}
[cfg {:keys [::rpc/profile-id ::rpc/session-id id]}]
(check-tasks-enabled)
(let [task (db/run! cfg (fn [{:keys [::db/conn]}] (get-task conn id)))]
(files/check-read-permissions! cfg profile-id (:file-id task))
(when (not= profile-id (:created-by task))
(ex/raise :type :validation
:code :not-allowed
:hint "only the author of a task may delete it"
:task-id id))
(check-delete-permissions cfg profile-id task)
(run-and-notify
cfg {:file-id (:file-id task) :profile-id profile-id :session-id session-id}
(constantly [id])
@ -808,29 +890,28 @@
(defn- send-tasks-moved-emails
[{:keys [::db/conn] :as cfg} {:keys [team-id main-id actor-id branch-name file-name]} tasks]
(let [users (->> (teams/get-users+props conn team-id)
(map profile/decode-row)
(d/index-by :id))
(let [users (team-users conn team-id)
actor (get-in users [actor-id :fullname] "")]
(doseq [[assignee-id tasks] (group-by :assignee-id tasks)]
(when-let [{:keys [fullname email]} (and (some? assignee-id)
(not= assignee-id actor-id)
(get users assignee-id))]
(eml/send-template
cfg
{::eml/reuse-conn true
::eml/template "tasks-moved"
:public-uri (cf/get :public-uri)
:to email
:name fullname
:source-user actor
:branch-name branch-name
:file-name file-name
:task-titles (str/join "\n" (map #(str "- " (:title %)) tasks))
:file-url (str/join [(cf/get :public-uri)
"/#/workspace?"
(uri/map->query-string {:file-id main-id
:team-id team-id})])})))))
(when-let [{:keys [fullname email props]} (and (some? assignee-id)
(not= assignee-id actor-id)
(get users assignee-id))]
(when (task-emails? props)
(eml/send-template
cfg
{::eml/reuse-conn true
::eml/template "tasks-moved"
:public-uri (cf/get :public-uri)
:to email
:name fullname
:source-user actor
:branch-name branch-name
:file-name file-name
:task-titles (str/join "\n" (map #(str "- " (:title %)) tasks))
:file-url (str/join [(cf/get :public-uri)
"/#/workspace?"
(uri/map->query-string {:file-id main-id
:team-id team-id})])}))))))
(defn- find-shape
[data page-id shape-id]

View File

@ -44,10 +44,14 @@
(declare strip-private-attrs)
(def schema:props-notifications
"The email choices of a profile. `:email-tasks` is optional because a
profile saved before the key existed does not have it, and the readers
of the setting take a missing one as `:partial`."
[:map {:title "props-notifications"}
[:dashboard-comments [::sm/one-of #{:all :partial :none}]]
[:email-comments [::sm/one-of #{:all :partial :none}]]
[:email-invites [::sm/one-of #{:all :none}]]])
[:email-invites [::sm/one-of #{:all :none}]]
[:email-tasks {:optional true} [::sm/one-of #{:all :partial :none}]]])
(def schema:nudge
[:map {:title "Nudge"}
@ -263,7 +267,8 @@
[:map {:title "update-profile-notifications"}
[:dashboard-comments [::sm/one-of #{:all :partial :none}]]
[:email-comments [::sm/one-of #{:all :partial :none}]]
[:email-invites [::sm/one-of #{:all :none}]]])
[:email-invites [::sm/one-of #{:all :none}]]
[:email-tasks {:optional true} [::sm/one-of #{:all :partial :none}]]])
(declare update-notifications!)
@ -275,14 +280,19 @@
(db/tx-run! cfg update-notifications! (assoc params :profile-id profile-id)))
(defn- update-notifications!
[{:keys [::db/conn] :as cfg} {:keys [profile-id dashboard-comments email-comments email-invites]}]
[{:keys [::db/conn] :as cfg} {:keys [profile-id dashboard-comments email-comments email-invites email-tasks]}]
(let [profile
(get-profile conn profile-id ::db/for-update true)
;; A client that predates `:email-tasks` does not send it: the
;; stored choice stays as the user left it.
notifications
{:dashboard-comments dashboard-comments
:email-comments email-comments
:email-invites email-invites}
(merge (get-in profile [:props :notifications])
{:dashboard-comments dashboard-comments
:email-comments email-comments
:email-invites email-invites}
(when (some? email-tasks)
{:email-tasks email-tasks}))
props
(-> (get profile :props)

View File

@ -9,7 +9,9 @@
[app.common.geom.point :as gpt]
[app.common.time :as ct]
[app.common.uuid :as uuid]
[app.config :as cf]
[app.db :as db]
[app.email :as eml]
[app.http :as http]
[app.rpc :as-alias rpc]
[app.rpc.commands.comments :as comments]
@ -1084,3 +1086,98 @@
result ((deref #'comments/get-file) th/*system* (:id file) page-id)]
(t/is (not (contains? result :storage-object-id)))))
(t/deftest thread-created-for-a-task-sends-no-comment-notification
;; A task created on the canvas makes its thread with
;; `::comments/skip-subscriber-emails`: the task email is the only one the
;; creation sends, while the people the message mentions are still told.
(let [owner (th/create-profile* 1 {:is-active true})
member (th/create-profile* 2 {:is-active true})
mentioned (th/create-profile* 3 {:is-active true})
team (th/create-team* 1 {:profile-id (:id owner)})
project (th/create-project* 1 {:team-id (:id team)
:profile-id (:id owner)})
file (th/create-file* 1 {:profile-id (:id owner)
:project-id (:id project)})
page-id (get-in file [:data :pages 0])
sent (atom [])]
(th/create-team-role* {:team-id (:id team)
:profile-id (:id member)
:role :editor})
(th/create-team-role* {:team-id (:id team)
:profile-id (:id mentioned)
:role :editor})
(th/db-update! :profile
{:props (db/tjson {:notifications {:dashboard-comments :all
:email-comments :all
:email-invites :all}})}
{:id (:id member)})
(let [create-thread! (fn [params]
(comments/create-comment-thread
th/*system*
(merge {::rpc/profile-id (:id owner)
::rpc/request-at (ct/now)
:file-id (:id file)
:page-id page-id
:position (gpt/point 0)
:frame-id uuid/zero}
params)))]
(with-redefs [eml/send-template (fn [_ params]
(swap! sent conj (::eml/template params))
nil)]
(t/testing "the flag silences the subscribers and keeps the mentions"
(create-thread! {::comments/skip-subscriber-emails true
:content (str "for you @[Profile 3](" (:id mentioned) ")")
:mentions #{(:id mentioned)}})
(t/is (= ["comment-mention"] @sent)))
(t/testing "without the flag the subscriber is told"
(reset! sent [])
(create-thread! {:content "hello again"})
(t/is (= ["comment-notification"] @sent)))))))
(t/deftest deleting-a-thread-records-a-deleted-event-for-its-tasks
;; The tasks of a thread live in its messages and go with it: each one
;; records who removed it, as the delete of a single task does.
(with-redefs [cf/flags (conj cf/flags :branching)]
(let [profile (th/create-profile* 1 {:is-active true})
team (th/create-team* 1 {:profile-id (:id profile)})
project (th/create-project* 1 {:team-id (:id team)
:profile-id (:id profile)})
file (th/create-file* 1 {:profile-id (:id profile)
:project-id (:id project)})
page-id (get-in file [:data :pages 0])
thread (:result (th/command! {::th/type :create-comment-thread
::rpc/profile-id (:id profile)
:file-id (:id file)
:page-id page-id
:position (gpt/point 0)
:content "A thread with a task"
:frame-id uuid/zero}))
task (:result (th/command! {::th/type :create-task
::rpc/profile-id (:id profile)
:file-id (:id file)
:page-id page-id
:frame-id uuid/zero
:position (gpt/point 0)
:title "Pay button"
:thread-id (:id thread)
:comment-id (:comment-id thread)}))]
(t/is (uuid? (:id task)))
(t/is (th/success? (th/command! {::th/type :delete-comment-thread
::rpc/profile-id (:id profile)
:id (:id thread)})))
(let [deleted (->> (th/db-query :file-task-event {:task-id (:id task)})
(filter #(= "deleted" (:type %))))]
(t/is (= 1 (count deleted)))
(t/is (= (:id profile) (:profile-id (first deleted))))
(t/is (= {:title "Pay button"}
(db/decode-transit-pgobject (:payload (first deleted)))))))))

View File

@ -745,6 +745,40 @@
(:id task)])]
(t/is (= [(:id author)] (mapv :profile-id rows))))))))
(t/deftest a-team-owner-or-admin-may-delete-the-task-of-somebody-else
(with-redefs [cf/flags (task-flags)]
(let [{:keys [author reviewer page-id branch-file-id]} (setup-review)
admin (th/create-profile* 3 {:is-active true})
_ (th/create-team-role* {:team-id (:default-team-id author)
:profile-id (:id admin)
:role :admin})
task* (fn [profile]
(:result (create-task* profile {:file-id branch-file-id :page-id page-id})))
delete (fn [profile task]
(th/command! {::th/type :delete-task
::rpc/profile-id (:id profile)
:id (:id task)}))
actor (fn [task]
(->> (th/db-exec! ["SELECT profile_id FROM file_task_event
WHERE task_id = ? AND type = 'deleted'"
(:id task)])
(mapv :profile-id)))]
(t/testing "the owner of the team may delete the task of an editor"
(let [task (task* reviewer)]
(t/is (nil? (:error (delete author task))))
(t/is (= [(:id author)] (actor task)))))
(t/testing "an admin of the team may delete the task of somebody else"
(let [task (task* reviewer)]
(t/is (nil? (:error (delete admin task))))
(t/is (= [(:id admin)] (actor task)))))
(t/testing "an editor who is not the author may not"
(let [task (task* author)]
(t/is (= :not-allowed (-> (delete reviewer task) :error ex-data :code)))
(t/is (nil? (:deleted-at (th/db-get :file-task {:id (:id task)})))))))))
;; --- Relinking a task
(t/deftest relinking-a-task-moves-the-thread-it-was-created-with
@ -791,3 +825,144 @@
(t/is (nil? (:error (relink task))))
(t/is (= rect-id (:shape-id (th/db-get :comment-thread {:id (:id thread)}))))
(t/is (= other-id (:shape-id (th/db-get :file-task {:id (:id task)})))))))))
(t/deftest relinking-a-task-made-from-the-first-message-leaves-its-thread
(with-redefs [cf/flags (task-flags)]
(let [{:keys [author page-id rect-id branch-file-id]} (setup-review)
other-id (uuid/random)
thread (:result (th/command! {::th/type :create-comment-thread
::rpc/profile-id (:id author)
:file-id branch-file-id
:page-id page-id
:frame-id uuid/zero
:position (gpt/point 0)
:content "the radius is off"
:anchor {:type :layer :shape-id rect-id}}))
task (:result (create-task* author {:file-id branch-file-id
:page-id page-id
:shape-id rect-id
:thread-id (:id thread)
:comment-id (:comment-id thread)}))]
(add-rect* author branch-file-id page-id other-id "Promo")
(t/is (false? (:created-thread (th/db-get :file-task {:id (:id task)}))))
(t/is (nil? (:error (th/command! {::th/type :relink-task
::rpc/profile-id (:id author)
:id (:id task)
:page-id page-id
:frame-id uuid/zero
:shape-id other-id
:shape-name "Promo"}))))
(t/is (= rect-id (:shape-id (th/db-get :comment-thread {:id (:id thread)}))))
(t/is (= other-id (:shape-id (th/db-get :file-task {:id (:id task)})))))))
;; --- Renaming a task
(defn- messages-of
[profile thread-id]
(mapv :content (:result (th/command! {::th/type :get-comments
::rpc/profile-id (:id profile)
:thread-id thread-id}))))
(defn- renamed-titles
[profile task]
(->> (:result (th/command! {::th/type :get-task-events
::rpc/profile-id (:id profile)
:id (:id task)}))
(filter #(= "renamed" (:type %)))
(mapv #(-> % :payload :title))))
(t/deftest renaming-a-task-rewrites-its-message-only-for-the-one-who-wrote-it
(with-redefs [cf/flags (task-flags)]
(let [{:keys [author reviewer page-id branch-file-id]} (setup-review)
rename (fn [profile task title]
(th/command! {::th/type :update-task
::rpc/profile-id (:id profile)
:id (:id task)
:title title}))]
(t/testing "the author renames the message of a task created on the canvas"
(let [task (:result (create-task* author {:file-id branch-file-id
:page-id page-id
:title "first title"}))]
(t/is (nil? (:error (rename author task "second title"))))
(t/is (= "second title" (:title (th/db-get :file-task {:id (:id task)}))))
(t/is (= ["second title"] (messages-of author (:thread-id task))))
(t/is (= ["second title"] (renamed-titles author task)))))
(t/testing "somebody else renames the task but not its message"
(let [task (:result (create-task* author {:file-id branch-file-id
:page-id page-id
:title "the author's words"}))]
(t/is (nil? (:error (rename reviewer task "the reviewer's words"))))
(t/is (= "the reviewer's words" (:title (th/db-get :file-task {:id (:id task)}))))
(t/is (= ["the author's words"] (messages-of author (:thread-id task))))
(t/is (= ["the reviewer's words"] (renamed-titles author task)))))
(t/testing "the message of an existing thread stays whatever the title"
(let [thread (:result (th/command! {::th/type :create-comment-thread
::rpc/profile-id (:id author)
:file-id branch-file-id
:page-id page-id
:frame-id uuid/zero
:position (gpt/point 0)
:content "the radius is off"}))
task (:result (create-task* author {:file-id branch-file-id
:page-id page-id
:thread-id (:id thread)
:comment-id (:comment-id thread)}))]
(t/is (false? (:created-thread (th/db-get :file-task {:id (:id task)}))))
(t/is (nil? (:error (rename author task "a better title"))))
(t/is (= ["the radius is off"] (messages-of author (:id thread))))
(t/is (= ["a better title"] (renamed-titles author task))))))))
;; --- Emails of a move
(t/deftest a-move-tells-the-person-it-concerns-and-nobody-else
(with-redefs [cf/flags (task-flags)]
(let [{:keys [author reviewer page-id branch-file-id]} (setup-review)
sent (atom [])]
(with-redefs [eml/send-template
(fn [_ params]
(swap! sent conj {:template (::eml/template params)
:to (:to params)
:task-title (:task-title params)}))]
(let [new-task (fn []
(:result (create-task* author {:file-id branch-file-id
:page-id page-id
:assignee-id (:id reviewer)})))
move (fn [profile task status]
(reset! sent [])
(let [out (set-status* profile (:id task) status)]
(t/is (nil? (:error out)))
@sent))]
(t/testing "done tells the creator"
(let [task (new-task)]
(t/is (= [{:template "task-done"
:to (:email author)
:task-title (:title task)}]
(move reviewer task "done")))))
(t/testing "a move that concerns only the actor tells nobody"
(let [task (new-task)]
(t/is (= [] (move author task "done")))))
(t/testing "reopened tells the assignee"
(let [task (new-task)]
(move reviewer task "done")
(t/is (= [{:template "task-reopened"
:to (:email reviewer)
:task-title (:title task)}]
(move author task "reopened")))))
(t/testing "verified tells nobody"
(let [task (new-task)]
(move reviewer task "done")
(t/is (= [] (move author task "verified")))))
(t/testing "a profile that refuses the task emails is told nothing"
(th/db-update! :profile
{:props (db/tjson {:notifications {:email-tasks :none}})}
{:id (:id author)})
(let [task (new-task)]
(t/is (= [] (move reviewer task "done"))))))))))

View File

@ -1918,6 +1918,33 @@
(t/is (th/ex-of-code? (:error out) :props-too-large))))))
(t/deftest update-profile-notifications-roundtrips-email-tasks
(let [profile (th/create-profile* 1)
stored (fn []
(-> (th/db-get :profile {:id (:id profile)})
(profile/decode-row)
(get-in [:props :notifications])))]
(t/testing "the task email choice is stored"
(let [out (th/command! {::th/type :update-profile-notifications
::rpc/profile-id (:id profile)
:dashboard-comments :all
:email-comments :partial
:email-invites :all
:email-tasks :none})]
(t/is (nil? (:error out)))
(t/is (= :none (:email-tasks (stored))))))
(t/testing "a client that predates the key keeps the stored choice"
(let [out (th/command! {::th/type :update-profile-notifications
::rpc/profile-id (:id profile)
:dashboard-comments :all
:email-comments :none
:email-invites :all})]
(t/is (nil? (:error out)))
(t/is (= :none (:email-tasks (stored))))
(t/is (= :none (:email-comments (stored))))))))
(t/deftest prepare-register-profile-password-too-short
(let [data {::th/type :prepare-register-profile
:email "user@example.com"

View File

@ -264,7 +264,8 @@
[:map {:title "NotificationsForm"}
[:dashboard-comments [::sm/one-of #{:all :partial :none}]]
[:email-comments [::sm/one-of #{:all :partial :none}]]
[:email-invites [::sm/one-of #{:all :none}]]])
[:email-invites [::sm/one-of #{:all :none}]]
[:email-tasks [::sm/one-of #{:all :partial :none}]]])
(def ^:private check-update-notifications-params
(sm/check-fn schema:update-notifications))

View File

@ -19,7 +19,8 @@
(def default-notification-settings
{:dashboard-comments :all
:email-comments :partial
:email-invites :all})
:email-invites :all
:email-tasks :partial})
(defn- on-submit
[form _event]
@ -30,7 +31,8 @@
[:map {:title "NotificationsForm"}
[:dashboard-comments [::sm/one-of #{:all :partial :none}]]
[:email-comments [::sm/one-of #{:all :partial :none}]]
[:email-invites [::sm/one-of #{:all :partial :none}]]])
[:email-invites [::sm/one-of #{:all :partial :none}]]
[:email-tasks [::sm/one-of #{:all :partial :none}]]])
(mf/defc notifications-page*
[{:keys [profile]}]
@ -70,6 +72,15 @@
:name :email-comments
:class (stl/css :radio-btns)}]]
[:h4 (tr "dashboard.settings.notifications.email-tasks.title")]
[:div {:class (stl/css :fields-row)}
[:& fm/radio-buttons
{:options [{:label (tr "dashboard.settings.notifications.email-tasks.all") :value "all"}
{:label (tr "dashboard.settings.notifications.email-tasks.partial") :value "partial"}
{:label (tr "dashboard.settings.notifications.email-tasks.none") :value "none"}]
:name :email-tasks
:class (stl/css :radio-btns)}]]
[:h4 (tr "dashboard.settings.notifications.email-invites.title")]
[:div {:class (stl/css :fields-row)}
[:& fm/radio-buttons

View File

@ -131,8 +131,15 @@
open? (deref open*)
status (:status task)
options (use-assignee-options)
team (mf/deref refs/team)
profile (mf/deref refs/profile)
;; Its author, and the owner or an admin of its team, may delete a
;; task; anybody who can read the file may still move it to won't do.
can-delete?
(or (= (:created-by task) (:id profile))
(boolean (get-in team [:permissions :is-admin])))
on-toggle
(mf/use-fn
(fn [event]
@ -195,8 +202,7 @@
(when-not (dwtk/closed? task)
[:> menu-item* {:id "relink"}
(tr "workspace.tasks.actions.relink")])
;; only its author may delete a task
(when (= (:id profile) (:created-by task))
(when can-delete?
[:> menu-item* {:id "delete"}
(tr "workspace.tasks.actions.delete")])]]))

View File

@ -1221,63 +1221,79 @@ msgstr "Penpot Light"
msgid "dashboard.select-ui-theme.system"
msgstr "System theme"
#: src/app/main/ui/settings/notifications.cljs:57
#: src/app/main/ui/settings/notifications.cljs:59
msgid "dashboard.settings.notifications.dashboard-comments.all"
msgstr "All comments, mentions and replies"
#: src/app/main/ui/settings/notifications.cljs:59
#: src/app/main/ui/settings/notifications.cljs:61
msgid "dashboard.settings.notifications.dashboard-comments.none"
msgstr "None"
#: src/app/main/ui/settings/notifications.cljs:58
#: src/app/main/ui/settings/notifications.cljs:60
msgid "dashboard.settings.notifications.dashboard-comments.partial"
msgstr "Only mentions and replies"
#: src/app/main/ui/settings/notifications.cljs:54
#: src/app/main/ui/settings/notifications.cljs:56
msgid "dashboard.settings.notifications.dashboard-comments.title"
msgstr "File comments"
#: src/app/main/ui/settings/notifications.cljs:53
#: src/app/main/ui/settings/notifications.cljs:55
msgid "dashboard.settings.notifications.dashboard.title"
msgstr "Dashboard Notifications"
#: src/app/main/ui/settings/notifications.cljs:67
#: src/app/main/ui/settings/notifications.cljs:69
msgid "dashboard.settings.notifications.email-comments.all"
msgstr "All comments, mentions and replies"
#: src/app/main/ui/settings/notifications.cljs:69
#: src/app/main/ui/settings/notifications.cljs:71
msgid "dashboard.settings.notifications.email-comments.none"
msgstr "None"
#: src/app/main/ui/settings/notifications.cljs:68
#: src/app/main/ui/settings/notifications.cljs:70
msgid "dashboard.settings.notifications.email-comments.partial"
msgstr "Only mentions and replies"
#: src/app/main/ui/settings/notifications.cljs:64
#: src/app/main/ui/settings/notifications.cljs:66
msgid "dashboard.settings.notifications.email-comments.title"
msgstr "File comments"
#: src/app/main/ui/settings/notifications.cljs:76
#: src/app/main/ui/settings/notifications.cljs:87
msgid "dashboard.settings.notifications.email-invites.all"
msgstr "All types of invites and requests"
#: src/app/main/ui/settings/notifications.cljs:79
#: src/app/main/ui/settings/notifications.cljs:90
msgid "dashboard.settings.notifications.email-invites.none"
msgstr "None"
#: src/app/main/ui/settings/notifications.cljs:73
#: src/app/main/ui/settings/notifications.cljs:84
msgid "dashboard.settings.notifications.email-invites.title"
msgstr "Invites and requests"
#: src/app/main/ui/settings/notifications.cljs:63
#: src/app/main/ui/settings/notifications.cljs:78
msgid "dashboard.settings.notifications.email-tasks.all"
msgstr "All tasks"
#: src/app/main/ui/settings/notifications.cljs:80
msgid "dashboard.settings.notifications.email-tasks.none"
msgstr "None"
#: src/app/main/ui/settings/notifications.cljs:79
msgid "dashboard.settings.notifications.email-tasks.partial"
msgstr "Only tasks I created or that are assigned to me"
#: src/app/main/ui/settings/notifications.cljs:75
msgid "dashboard.settings.notifications.email-tasks.title"
msgstr "Tasks"
#: src/app/main/ui/settings/notifications.cljs:65
msgid "dashboard.settings.notifications.email.title"
msgstr "Email Notifications"
#: src/app/main/ui/settings/notifications.cljs:84
#: src/app/main/ui/settings/notifications.cljs:95
msgid "dashboard.settings.notifications.submit"
msgstr "Update settings"
#: src/app/main/ui/settings/notifications.cljs:52
#: src/app/main/ui/settings/notifications.cljs:54
msgid "dashboard.settings.notifications.title"
msgstr "Notifications"

View File

@ -1241,63 +1241,79 @@ msgstr "Penpot Light"
msgid "dashboard.select-ui-theme.system"
msgstr "Sistema"
#: src/app/main/ui/settings/notifications.cljs:57
#: src/app/main/ui/settings/notifications.cljs:59
msgid "dashboard.settings.notifications.dashboard-comments.all"
msgstr "Todos los comentarios, menciones y respuestas"
#: src/app/main/ui/settings/notifications.cljs:59
#: src/app/main/ui/settings/notifications.cljs:61
msgid "dashboard.settings.notifications.dashboard-comments.none"
msgstr "Ninguna"
#: src/app/main/ui/settings/notifications.cljs:58
#: src/app/main/ui/settings/notifications.cljs:60
msgid "dashboard.settings.notifications.dashboard-comments.partial"
msgstr "Sólo menciones y respuestas"
#: src/app/main/ui/settings/notifications.cljs:54
#: src/app/main/ui/settings/notifications.cljs:56
msgid "dashboard.settings.notifications.dashboard-comments.title"
msgstr "Comentarios de ficheros"
#: src/app/main/ui/settings/notifications.cljs:53
#: src/app/main/ui/settings/notifications.cljs:55
msgid "dashboard.settings.notifications.dashboard.title"
msgstr "Notificaciones en el panel"
#: src/app/main/ui/settings/notifications.cljs:67
#: src/app/main/ui/settings/notifications.cljs:69
msgid "dashboard.settings.notifications.email-comments.all"
msgstr "Todos los comentarios, menciones y respuestas"
#: src/app/main/ui/settings/notifications.cljs:69
#: src/app/main/ui/settings/notifications.cljs:71
msgid "dashboard.settings.notifications.email-comments.none"
msgstr "Ninguna"
#: src/app/main/ui/settings/notifications.cljs:68
#: src/app/main/ui/settings/notifications.cljs:70
msgid "dashboard.settings.notifications.email-comments.partial"
msgstr "Sólo menciones y respuestas"
#: src/app/main/ui/settings/notifications.cljs:64
#: src/app/main/ui/settings/notifications.cljs:66
msgid "dashboard.settings.notifications.email-comments.title"
msgstr "Comentarios de ficheros"
#: src/app/main/ui/settings/notifications.cljs:76
#: src/app/main/ui/settings/notifications.cljs:87
msgid "dashboard.settings.notifications.email-invites.all"
msgstr "Todas las invitaciones y solicitudes"
#: src/app/main/ui/settings/notifications.cljs:79
#: src/app/main/ui/settings/notifications.cljs:90
msgid "dashboard.settings.notifications.email-invites.none"
msgstr "Ninguna"
#: src/app/main/ui/settings/notifications.cljs:73
#: src/app/main/ui/settings/notifications.cljs:84
msgid "dashboard.settings.notifications.email-invites.title"
msgstr "Invitaciones y solicitudes"
#: src/app/main/ui/settings/notifications.cljs:63
#: src/app/main/ui/settings/notifications.cljs:78
msgid "dashboard.settings.notifications.email-tasks.all"
msgstr "Todas las tareas"
#: src/app/main/ui/settings/notifications.cljs:80
msgid "dashboard.settings.notifications.email-tasks.none"
msgstr "Ninguna"
#: src/app/main/ui/settings/notifications.cljs:79
msgid "dashboard.settings.notifications.email-tasks.partial"
msgstr "Sólo las tareas que he creado o que tengo asignadas"
#: src/app/main/ui/settings/notifications.cljs:75
msgid "dashboard.settings.notifications.email-tasks.title"
msgstr "Tareas"
#: src/app/main/ui/settings/notifications.cljs:65
msgid "dashboard.settings.notifications.email.title"
msgstr "Notificaciones de correo electrónico"
#: src/app/main/ui/settings/notifications.cljs:84
#: src/app/main/ui/settings/notifications.cljs:95
msgid "dashboard.settings.notifications.submit"
msgstr "Actualizar configuración"
#: src/app/main/ui/settings/notifications.cljs:52
#: src/app/main/ui/settings/notifications.cljs:54
msgid "dashboard.settings.notifications.title"
msgstr "Notificaciones"