Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 2c6f1de

Browse files
committed
chore: Merge branch 'dev'
2 parents c76d26a + 988eed4 commit 2c6f1de

File tree

9 files changed

+848
-69
lines changed

9 files changed

+848
-69
lines changed

config/config.exs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ config :groupher_server, GroupherServerWeb.Gettext, default_locale: "zh_CN", loc
6868

6969
# config email services
7070
config :groupher_server, :system_emails,
71-
support: "coderplanets <support@group.coderplanets.com>",
72-
admin: "mydearxym@qq.com"
71+
support_email: "coderplanets <support@group.coderplanets.com>",
72+
admin_email: "mydearxym@qq.com",
73+
welcome_new_register: true,
74+
notify_admin_on_new_user: true,
75+
notify_admin_on_content_created: true
7376

7477
config :groupher_server, GroupherServer.Mailer,
7578
adapter: Bamboo.MailgunAdapter,

lib/groupher_server/accounts/delegates/profile.ex

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ defmodule GroupherServer.Accounts.Delegate.Profile do
66
import Helper.Utils, only: [done: 1, get_config: 2]
77
import ShortMaps
88

9-
alias GroupherServer.Accounts
9+
alias GroupherServer.{Accounts, CMS, Email, Repo}
10+
11+
alias Accounts.{Achievement, GithubUser, User, Social}
1012
alias Helper.{Guardian, ORM, QueryBuilder, RadarSearch}
11-
alias GroupherServer.Accounts.{Achievement, GithubUser, User, Social}
12-
alias GroupherServer.{CMS, Repo}
13-
alias GroupherServer.Email
1413

1514
alias Ecto.Multi
1615

lib/groupher_server/cms/delegates/article_curd.ex

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
88
import Helper.ErrorCode
99
import ShortMaps
1010

11-
alias GroupherServer.Repo
11+
alias GroupherServer.{Accounts, CMS, Delivery, Email, Repo, Statistics}
1212

13-
alias GroupherServer.Accounts.User
14-
alias GroupherServer.{CMS, Delivery, Statistics}
13+
alias Accounts.User
14+
alias CMS.{Author, Community, Delegate, Tag, Topic}
1515

16-
alias CMS.Delegate.ArticleOperation
17-
alias Helper.{ORM, QueryBuilder}
16+
alias Delegate.ArticleOperation
17+
alias Helper.{Later, ORM, QueryBuilder}
1818

19-
alias CMS.{Author, Community, Tag, Topic}
2019
alias Ecto.Multi
2120

2221
@doc """
@@ -398,7 +397,30 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
398397
end
399398
end
400399

401-
defp create_content_result({:ok, %{create_content: result}}), do: {:ok, result}
400+
defp create_content_result({:ok, %{create_content: result}}) do
401+
# Later.exec({__MODULE__, :nofify_admin_new_content, [result]})
402+
nofify_admin_new_content(result)
403+
{:ok, result}
404+
end
405+
406+
def nofify_admin_new_content(%{id: id} = result) do
407+
target = result.__struct__
408+
preload = [:origial_community, author: :user]
409+
410+
with {:ok, content} <- ORM.find(target, id, preload: preload) do
411+
info = %{
412+
id: content.id,
413+
title: content.title,
414+
digest: content.digest,
415+
author_name: content.author.user.nickname,
416+
community_raw: content.origial_community.raw,
417+
type:
418+
result.__struct__ |> to_string |> String.split(".") |> List.last() |> String.downcase()
419+
}
420+
421+
Email.notify_admin(info, :new_content)
422+
end
423+
end
402424

403425
defp create_content_result({:error, :create_content, %Ecto.Changeset{} = result, _steps}) do
404426
{:error, result}

lib/groupher_server/mailer/email.ex

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,37 @@ defmodule GroupherServer.Email do
77
import Bamboo.Email
88
import Helper.Utils, only: [get_config: 2]
99

10-
alias GroupherServer.{Accounts, Billing, Email, Mailer}
10+
alias GroupherServer.{Accounts, Billing, CMS, Email, Mailer}
1111

1212
alias Accounts.User
1313
alias Billing.BillRecord
14+
alias CMS.{Post, Job, Repo, Video}
1415
alias Email.Templates
1516
alias Mailer
1617

17-
@support_email get_config(:system_emails, :support)
18-
@admin_email get_config(:system_emails, :admin)
18+
@support_email get_config(:system_emails, :support_email)
19+
@admin_email get_config(:system_emails, :admin_email)
20+
21+
@conf_welcome_new_register get_config(:system_emails, :welcome_new_register)
22+
@conf_notify_admin_on_new_user get_config(:system_emails, :notify_admin_on_new_user)
23+
@conf_notify_admin_on_content_created get_config(
24+
:system_emails,
25+
:notify_admin_on_content_created
26+
)
1927

2028
def welcome(%User{email: email} = user) when not is_nil(email) do
21-
base_mail()
22-
|> to(email)
23-
|> subject("欢迎来到 coderplanets")
24-
|> html_body(Templates.Welcome.html(user))
25-
|> text_body(Templates.Welcome.text())
26-
|> Mailer.deliver_later()
29+
case @conf_welcome_new_register do
30+
true ->
31+
base_mail()
32+
|> to(email)
33+
|> subject("欢迎来到 coderplanets")
34+
|> html_body(Templates.Welcome.html(user))
35+
|> text_body(Templates.Welcome.text())
36+
|> Mailer.deliver_later()
37+
38+
false ->
39+
{:ok, :pass}
40+
end
2741
end
2842

2943
# user has no email log to somewhere
@@ -42,19 +56,27 @@ defmodule GroupherServer.Email do
4256
|> Mailer.deliver_later()
4357
end
4458

59+
# notify admin when new user register
4560
def notify_admin(%User{from_github: true} = user, :new_register) do
46-
base_mail()
47-
|> to(@admin_email)
48-
|> subject("新用户(#{user.nickname})注册")
49-
|> html_body(Templates.NotifyAdminRegister.html(user))
50-
|> text_body(Templates.NotifyAdminRegister.text())
51-
|> Mailer.deliver_later()
61+
case @conf_notify_admin_on_new_user do
62+
true ->
63+
base_mail()
64+
|> to(@admin_email)
65+
|> subject("新用户(#{user.nickname})注册")
66+
|> html_body(Templates.NotifyAdminRegister.html(user))
67+
|> text_body(Templates.NotifyAdminRegister.text())
68+
|> Mailer.deliver_later()
69+
70+
false ->
71+
{:ok, :pass}
72+
end
5273
end
5374

5475
def notify_admin(_user, :new_register) do
5576
{:ok, :pass}
5677
end
5778

79+
# notify admin when someone donote
5880
def notify_admin(%BillRecord{} = record, :payment) do
5981
base_mail()
6082
|> to(@admin_email)
@@ -64,6 +86,23 @@ defmodule GroupherServer.Email do
6486
|> Mailer.deliver_later()
6587
end
6688

89+
# notify admin when new post has created
90+
def notify_admin(%{type: type, title: title} = info, :new_content) do
91+
case @conf_notify_admin_on_content_created do
92+
true ->
93+
hello =
94+
base_mail()
95+
|> to(@admin_email)
96+
|> subject("new #{type}: #{title}")
97+
|> html_body(Templates.NotifyAdminOnContentCreated.html(info))
98+
|> text_body(Templates.NotifyAdminRegister.text())
99+
|> Mailer.deliver_later()
100+
101+
false ->
102+
{:ok, :pass}
103+
end
104+
end
105+
67106
# some one comment to your post ..
68107
# the author's publish content being deleted ..
69108
# def notify_author, do: IO.inspect("notify_author")
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
defmodule GroupherServer.Email.Templates.MentionAuthor do
2+
@moduledoc """
3+
template for mention author, like but not limit to:
4+
5+
post, job, video, repo ...
6+
or mention in comment ..
7+
8+
if you want change style or debug the template
9+
just copy and paste raw string to: https://mjml.io/try-it-live
10+
"""
11+
12+
def html(record) do
13+
"""
14+
TODO
15+
"""
16+
end
17+
18+
def text() do
19+
"""
20+
有人发帖了
21+
"""
22+
end
23+
24+
defp raw() do
25+
"""
26+
<mjml>
27+
<mj-head>
28+
<mj-title>Discount Light</mj-title>
29+
<mj-preview>Pre-header Text</mj-preview>
30+
<mj-attributes>
31+
<mj-all font-family="'Helvetica Neue', Helvetica, Arial, sans-serif"></mj-all>
32+
<mj-text font-weight="400" font-size="16px" color="#000000" line-height="24px" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif"></mj-text>
33+
</mj-attributes>
34+
<mj-style inline="inline">
35+
.body-section { -webkit-box-shadow: 1px 4px 11px 0px rgba(0, 0, 0, 0.15); -moz-box-shadow: 1px 4px 11px 0px rgba(0, 0, 0, 0.15); box-shadow: 1px 4px 11px 0px rgba(0, 0, 0, 0.15); }
36+
</mj-style>
37+
<mj-style inline="inline">
38+
.text-link { color: #5e6ebf }
39+
</mj-style>
40+
<mj-style inline="inline">
41+
.footer-link { color: #888888 }
42+
</mj-style>
43+
44+
</mj-head>
45+
<mj-body background-color="#002B34" width="600px">
46+
<mj-section full-width="full-width" background-color="#183a42" padding-bottom="0">
47+
<mj-column width="100%">
48+
<mj-text color="#17CBC4" font-weight="bold" align="center" font-size="18px" letter-spacing="1px" padding-top="20px">
49+
coderplanets
50+
<br/>
51+
</mj-text>
52+
<mj-text color="#0d8396" align="center" font-size="13px" padding-top="0" font-weight="bold" letter-spacing="1px" line-height="20px">
53+
the most sexiest community for developers, ever.
54+
</mj-text>
55+
56+
</mj-column>
57+
</mj-section>
58+
59+
<mj-wrapper padding-top="0" padding-bottom="0" css-class="body-section">
60+
<mj-section background-color="#042f3a" padding-left="6px" padding-right="6px">
61+
<mj-column width="100%">
62+
<mj-text color="#6f8696" font-weight="bold" font-size="18px">
63+
<br/>
64+
xxx 在文章/评论标题里提及/回复了你
65+
</mj-text>
66+
<mj-text color="#637381" font-size="16px">
67+
文章内容或评论内容摘要
68+
</mj-text>
69+
70+
<mj-divider border-width="1px" border-style="dashed" border-color="#113A41" />
71+
72+
73+
<mj-text color="#637381" font-size="16px" padding-top="10px" align="center">
74+
<a class="text-link" href="https://github.com/coderplanets.com">去看看 -></a>
75+
</mj-text>
76+
77+
</mj-column>
78+
</mj-section>
79+
80+
</mj-wrapper>
81+
82+
<mj-wrapper full-width="full-width">
83+
<mj-section>
84+
<mj-column width="100%" padding="0">
85+
<mj-social font-size="15px" icon-size="30px" mode="horizontal" padding="0" align="center">
86+
<mj-social-element name="github" href="https://github.com/coderplanets" background-color="#296C7D">
87+
</mj-social-element>
88+
</mj-social>
89+
90+
91+
<mj-text color="#445566" font-size="11px" align="center" line-height="16px">
92+
&copy; Coderplanets Inc., All Rights Reserved.
93+
</mj-text>
94+
</mj-column>
95+
</mj-section>
96+
<mj-section padding-top="0">
97+
<mj-group>
98+
<mj-column width="100%" padding-right="0">
99+
<mj-text color="#445566" font-size="11px" align="center" line-height="16px" font-weight="bold">
100+
<a class="footer-link" href="https://coderplanets.com/home/post/45">Privacy</a>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<a class="footer-link" href="https://www.github.com/coderplanets/coderplanets_web/issues">Unsubscribe</a>
101+
</mj-text>
102+
</mj-column>
103+
</mj-group>
104+
105+
</mj-section>
106+
</mj-wrapper>
107+
108+
</mj-body>
109+
</mjml>
110+
"""
111+
end
112+
end

0 commit comments

Comments
 (0)