Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commitabeb9ff

Browse files
committed
feat(mailer): notify admin user for new content
1 parent49d3dd2 commitabeb9ff

File tree

4 files changed

+534
-17
lines changed

4 files changed

+534
-17
lines changed

‎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
importHelper.ErrorCode
99
importShortMaps
1010

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

13-
aliasGroupherServer.Accounts.User
14-
aliasGroupherServer.{CMS,Delivery,Statistics}
13+
aliasAccounts.User
14+
aliasCMS.{Author,Community,Delegate,Tag,Topic}
1515

16-
aliasCMS.Delegate.ArticleOperation
17-
aliasHelper.{ORM,QueryBuilder}
16+
aliasDelegate.ArticleOperation
17+
aliasHelper.{Later,ORM,QueryBuilder}
1818

19-
aliasCMS.{Author,Community,Tag,Topic}
2019
aliasEcto.Multi
2120

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

401-
defpcreate_content_result({:ok,%{create_content:result}}),do:{:ok,result}
400+
defpcreate_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+
defnofify_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
defpcreate_content_result({:error,:create_content,%Ecto.Changeset{}=result,_steps})do
404426
{:error,result}

‎lib/groupher_server/mailer/email.ex‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ defmodule GroupherServer.Email do
77
importBamboo.Email
88
importHelper.Utils,only:[get_config:2]
99

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

1212
aliasAccounts.User
1313
aliasBilling.BillRecord
14+
aliasCMS.{Post,Job,Repo,Video}
1415
aliasEmail.Templates
1516
aliasMailer
1617

@@ -86,15 +87,16 @@ defmodule GroupherServer.Email do
8687
end
8788

8889
# notify admin when new post has created
89-
defnotify_admin(:create,_post)do
90+
defnotify_admin(%{type:type,title:title}=info,:new_content)do
9091
case@conf_notify_admin_on_content_createddo
9192
true->
92-
base_mail()
93-
|>to(@admin_email)
94-
|>subject("新帖子: ... ")
95-
# |> html_body(Templates.NotifyAdminRegister.html(user))
96-
# |> text_body(Templates.NotifyAdminRegister.text())
97-
|>Mailer.deliver_later()
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()
98100

99101
false->
100102
{:ok,:pass}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp