Skip to content

Commit

Permalink
Merge pull request #282 from shaunwarman/feat/abuse-monitoring
Browse files Browse the repository at this point in the history
feat: add total domain and aliases into respective admin pages
  • Loading branch information
titanism authored Aug 29, 2024
2 parents 2505e34 + 2fcee76 commit 7cccd5a
Show file tree
Hide file tree
Showing 29 changed files with 160 additions and 40 deletions.
38 changes: 30 additions & 8 deletions app/controllers/web/admin/domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,37 @@ async function list(ctx) {
}
}

const sortField = ctx.query.sort
? ctx.query.sort.replace('-', '')
: 'created_at';
const sortOrder = ctx.query.sort && ctx.query.sort.startsWith('-') ? -1 : 1;

const aggregationPipeline = [
{ $match: query },
{
$lookup: {
from: 'aliases',
let: { domainId: '$_id' },
pipeline: [
{ $match: { $expr: { $eq: ['$domain', '$$domainId'] } } },
{ $count: 'totalAliases' }
],
as: 'totalAliasesInfo'
}
},
{
$addFields: {
totalAliases: { $arrayElemAt: ['$totalAliasesInfo.totalAliases', 0] }
}
},
{ $unset: 'totalAliasesInfo' },
{ $sort: { [sortField]: sortOrder } },
{ $skip: ctx.paginate.skip },
{ $limit: ctx.query.limit }
];

const [domains, itemCount] = await Promise.all([
// eslint-disable-next-line unicorn/no-array-callback-reference
Domains.find(query)
.limit(ctx.query.limit)
.skip(ctx.paginate.skip)
.sort(ctx.query.sort || '-created_at')
.populate('members.user', 'id email')
.lean()
.exec(),
Domains.aggregate(aggregationPipeline).exec(),
Domains.countDocuments(query)
]);

Expand Down
37 changes: 30 additions & 7 deletions app/controllers/web/admin/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,37 @@ async function list(ctx) {
}
}

const sortField = ctx.query.sort
? ctx.query.sort.replace('-', '')
: 'created_at';
const sortOrder = ctx.query.sort && ctx.query.sort.startsWith('-') ? -1 : 1;

const aggregationPipeline = [
{ $match: query },
{
$lookup: {
from: 'domains',
let: { userId: '$_id' },
pipeline: [
{ $match: { $expr: { $in: ['$$userId', '$members.user'] } } },
{ $count: 'totalDomains' }
],
as: 'domainInfo'
}
},
{
$addFields: {
totalDomains: { $arrayElemAt: ['$domainInfo.totalDomains', 0] }
}
},
{ $unset: 'domainInfo' },
{ $sort: { [sortField]: sortOrder } },
{ $skip: ctx.paginate.skip },
{ $limit: ctx.query.limit }
];

const [users, itemCount] = await Promise.all([
// eslint-disable-next-line unicorn/no-array-callback-reference
Users.find(query)
.limit(ctx.query.limit)
.skip(ctx.paginate.skip)
.lean()
.sort(ctx.query.sort || '-created_at')
.exec(),
Users.aggregate(aggregationPipeline).exec(),
Users.countDocuments(query)
]);

Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/domains/_table.pug
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ include ../../_pagination
th(scope="col")
+sortHeader('is_global', 'Global', '#table-domains')
th.align-middle(scope="col")= t("Members")
th(scope="col")
+sortHeader('aliases', 'Aliases', '#table-domains')
th(scope="col")
+sortHeader('plan', 'Plan', '#table-domains')
th(scope="col")
Expand Down Expand Up @@ -52,6 +54,7 @@ include ../../_pagination
= "("
code.text-muted= member.user.id
= ")"
td.align-middle.text-center= domain.totalAliases
td.align-middle.text-center
= t(titleize(humanize(domain.plan)))
td.align-middle.text-center
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/users/_table.pug
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ include ../../_pagination
+sortHeader(config.passport.fields.familyName, 'Last Name', '#table-users')
th(scope="col")
+sortHeader('email', null, '#table-users')
th(scope="col")
+sortHeader('domains', null, '#table-users')
th(scope="col")
+sortHeader('plan', null, '#table-users')
th(scope="col")
Expand Down Expand Up @@ -43,6 +45,7 @@ include ../../_pagination
= "("
code.text-muted= user.id
= ")"
td.align-middle= user.totalDomains
td.align-middle= titleize(humanize(user.plan))
td.align-middle= titleize(humanize(user.group))
td.align-middle.dayjs(
Expand Down
4 changes: 3 additions & 1 deletion locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "خدمة استضافة البريد الإلكتروني مفتوحة المصدر",
"Custom Domain Email Forwarding": "إعادة توجيه البريد الإلكتروني إلى نطاق مخصص",
"Suggested": "مقترح",
"Its description from its website is:": "وصفه من موقعه على الإنترنت هو:"
"Its description from its website is:": "وصفه من موقعه على الإنترنت هو:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "Open-source e-mailová hostingová služba",
"Custom Domain Email Forwarding": "Přeposílání e-mailů na vlastní doménu",
"Suggested": "Doporučeno",
"Its description from its website is:": "Jeho popis z jeho webu je:"
"Its description from its website is:": "Jeho popis z jeho webu je:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -7297,5 +7297,7 @@
"Legacy Free Guide": "Legacy gratis guide",
"Suggested": "Foreslået",
"Its description from its website is:": "Beskrivelsen fra dens hjemmeside er:",
"Compare <span class=\"notranslate\">%s</span> with <span class=\"notranslate\">%d</span> email services": "Sammenlign <span class=\"notranslate\">%s</span> med <span class=\"notranslate\">%d</span> e-mail-tjenester"
"Compare <span class=\"notranslate\">%s</span> with <span class=\"notranslate\">%d</span> email services": "Sammenlign <span class=\"notranslate\">%s</span> med <span class=\"notranslate\">%d</span> e-mail-tjenester",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -9349,5 +9349,7 @@
"Open-source Email Hosting Service": "Open-Source-E-Mail-Hosting-Dienst",
"Custom Domain Email Forwarding": "Benutzerdefinierte Domänen-E-Mail-Weiterleitung",
"Suggested": "Empfohlen",
"Its description from its website is:": "Die Beschreibung auf der Website lautet:"
"Its description from its website is:": "Die Beschreibung auf der Website lautet:",
"domains": "domains",
"Replying to": "Replying to"
}
23 changes: 22 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6693,5 +6693,26 @@
"If your ISP blocks outbound port 25, then you will have to find an alternate solution or contact them.": "If your ISP blocks outbound port 25, then you will have to find an alternate solution or contact them.",
"You can run": "You can run",
"from command line or terminal to see if your outbound port 25 connection is blocked.": "from command line or terminal to see if your outbound port 25 connection is blocked.",
"Español": "Español"
"Español": "Español",
"You do not belong to the administrative user group.": "You do not belong to the administrative user group.",
"Admin - Users": "Admin - Users",
"Search for users": "Search for users",
"Search by first name, last name, or email": "Search by first name, last name, or email",
"First Name": "First Name",
"Last Name": "Last Name",
"email": "email",
"domains": "domains",
"plan": "plan",
"group": "group",
"Last Login": "Last Login",
"Log in as user": "Log in as user",
"Admin - Inquiries": "Admin - Inquiries",
"Search for inquiries": "Search for inquiries",
"Search by email": "Search by email",
"Selected": "Selected",
"Reply": "Reply",
"Resolve": "Resolve",
"Bulk Reply": "Bulk Reply",
"Replying to": "Replying to",
"Submit Bulk Reply": "Submit Bulk Reply"
}
4 changes: 3 additions & 1 deletion locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -10308,5 +10308,7 @@
"Open-source Email Hosting Service": "Servicio de alojamiento de correo electrónico de código abierto",
"Custom Domain Email Forwarding": "Reenvío de correo electrónico de dominio personalizado",
"Suggested": "Sugerido",
"Its description from its website is:": "Su descripción desde su sitio web es:"
"Its description from its website is:": "Su descripción desde su sitio web es:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -10157,5 +10157,7 @@
"Open-source Email Hosting Service": "Avoimen lähdekoodin sähköpostipalvelu",
"Custom Domain Email Forwarding": "Mukautetun verkkotunnuksen sähköpostin edelleenlähetys",
"Suggested": "Ehdotettu",
"Its description from its website is:": "Sen kuvaus sen verkkosivuilta on:"
"Its description from its website is:": "Sen kuvaus sen verkkosivuilta on:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -7834,5 +7834,7 @@
"Custom Domain Email Forwarding": "Transfert d'e-mails de domaine personnalisé",
"Legacy Free Guide": "Guide gratuit sur l'héritage",
"Suggested": "Suggéré",
"Its description from its website is:": "Sa description sur son site Web est :"
"Its description from its website is:": "Sa description sur son site Web est :",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -8330,5 +8330,7 @@
"Custom Domain Email Forwarding": "העברת דואר אלקטרוני בדומיין מותאם אישית",
"Legacy Free Guide": "מדריך חינם מדור קודם",
"Suggested": "מוּצָע",
"Its description from its website is:": "התיאור שלו מהאתר שלו הוא:"
"Its description from its website is:": "התיאור שלו מהאתר שלו הוא:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "Nyílt forráskódú e-mail hosting szolgáltatás",
"Custom Domain Email Forwarding": "Egyéni domain e-mail továbbítása",
"Suggested": "Javasolt",
"Its description from its website is:": "Leírása a honlapjáról a következő:"
"Its description from its website is:": "Leírása a honlapjáról a következő:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "Layanan Hosting Email Sumber Terbuka",
"Custom Domain Email Forwarding": "Penerusan Email Domain Kustom",
"Suggested": "Disarankan",
"Its description from its website is:": "Uraian dari situs webnya adalah:"
"Its description from its website is:": "Uraian dari situs webnya adalah:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "Servizio di hosting di posta elettronica open source",
"Custom Domain Email Forwarding": "Inoltro e-mail di dominio personalizzato",
"Suggested": "Suggerito",
"Its description from its website is:": "La descrizione dal suo sito web è:"
"Its description from its website is:": "La descrizione dal suo sito web è:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "オープンソースのメールホスティングサービス",
"Custom Domain Email Forwarding": "カスタムドメインメール転送",
"Suggested": "提案",
"Its description from its website is:": "ウェブサイトからの説明は次のとおりです。"
"Its description from its website is:": "ウェブサイトからの説明は次のとおりです。",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "오픈소스 이메일 호스팅 서비스",
"Custom Domain Email Forwarding": "사용자 정의 도메인 이메일 전달",
"Suggested": "제안된",
"Its description from its website is:": "해당 웹사이트의 설명은 다음과 같습니다."
"Its description from its website is:": "해당 웹사이트의 설명은 다음과 같습니다.",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "Open-source e-mailhostingservice",
"Custom Domain Email Forwarding": "E-mail doorsturen naar aangepast domein",
"Suggested": "Voorgesteld",
"Its description from its website is:": "De beschrijving op de website is:"
"Its description from its website is:": "De beschrijving op de website is:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -10315,5 +10315,7 @@
"Open-source Email Hosting Service": "Åpen kildekode e-postvertstjeneste",
"Custom Domain Email Forwarding": "Egendefinert domene-e-postvideresending",
"Suggested": "Foreslått",
"Its description from its website is:": "Beskrivelsen fra nettstedet er:"
"Its description from its website is:": "Beskrivelsen fra nettstedet er:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "Usługa hostingu poczty e-mail typu open source",
"Custom Domain Email Forwarding": "Przekierowanie poczty e-mail na domenę niestandardową",
"Suggested": "Sugerowane",
"Its description from its website is:": "Opis na stronie internetowej brzmi następująco:"
"Its description from its website is:": "Opis na stronie internetowej brzmi następująco:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "Serviço de hospedagem de e-mail de código aberto",
"Custom Domain Email Forwarding": "Encaminhamento de e-mail de domínio personalizado",
"Suggested": "Sugerido",
"Its description from its website is:": "A descrição no seu site é:"
"Its description from its website is:": "A descrição no seu site é:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "Служба хостинга электронной почты с открытым исходным кодом",
"Custom Domain Email Forwarding": "Пересылка электронной почты на пользовательский домен",
"Suggested": "Предложенный",
"Its description from its website is:": "Описание на сайте:"
"Its description from its website is:": "Описание на сайте:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "E-postvärdtjänst med öppen källkod",
"Custom Domain Email Forwarding": "Anpassad vidarebefordran av e-post på domän",
"Suggested": "Föreslog",
"Its description from its website is:": "Dess beskrivning från dess hemsida är:"
"Its description from its website is:": "Dess beskrivning från dess hemsida är:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "บริการโฮสติ้งอีเมล์โอเพ่นซอร์ส",
"Custom Domain Email Forwarding": "การส่งต่ออีเมลโดเมนที่กำหนดเอง",
"Suggested": "ข้อเสนอแนะ",
"Its description from its website is:": "คำอธิบายจากเว็บไซต์มีดังนี้:"
"Its description from its website is:": "คำอธิบายจากเว็บไซต์มีดังนี้:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "Açık Kaynaklı E-posta Barındırma Hizmeti",
"Custom Domain Email Forwarding": "Özel Alan Adı E-posta Yönlendirme",
"Suggested": "Önerilen",
"Its description from its website is:": "Web sitesindeki açıklaması şöyle:"
"Its description from its website is:": "Web sitesindeki açıklaması şöyle:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -10310,5 +10310,7 @@
"Open-source Email Hosting Service": "Служба хостингу електронної пошти з відкритим кодом",
"Custom Domain Email Forwarding": "Переадресація електронної пошти власного домену",
"Suggested": "Запропоновано",
"Its description from its website is:": "Його опис на веб-сайті:"
"Its description from its website is:": "Його опис на веб-сайті:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -7839,5 +7839,7 @@
"Custom Domain Email Forwarding": "Chuyển tiếp Email theo tên miền tùy chỉnh",
"Legacy Free Guide": "Hướng dẫn miễn phí Legacy",
"Suggested": "Đề xuất",
"Its description from its website is:": "Mô tả từ trang web của nó như sau:"
"Its description from its website is:": "Mô tả từ trang web của nó như sau:",
"domains": "domains",
"Replying to": "Replying to"
}
4 changes: 3 additions & 1 deletion locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -10003,5 +10003,7 @@
"Open-source Email Hosting Service": "开源电子邮件托管服务",
"Custom Domain Email Forwarding": "自定义域名电子邮件转发",
"Suggested": "建议",
"Its description from its website is:": "其网站上的描述是:"
"Its description from its website is:": "其网站上的描述是:",
"domains": "domains",
"Replying to": "Replying to"
}

0 comments on commit 7cccd5a

Please sign in to comment.