Warning, /network/tokodon/src/content/ui/ModerationTools/EmailBlockToolPage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 Rishi Kumar <rsi.dev17@gmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 import QtQuick
0005 import org.kde.kirigami 2 as Kirigami
0006 import QtQuick.Controls 2 as QQC2
0007 import QtQuick.Layouts
0008 import org.kde.tokodon
0009 import org.kde.kirigamiaddons.formcard 1 as FormCard
0010 import org.kde.kirigamiaddons.labs.components 1 as Components
0011 import org.kde.kirigamiaddons.delegates 1 as Delegates
0012 
0013 Kirigami.ScrollablePage {
0014     id: root
0015 
0016     actions: Kirigami.Action {
0017         text: i18nc("@action:button", "Create Email Block")
0018         icon.name: 'list-add'
0019         onTriggered: newEmailBlockDialog.open()
0020     }
0021 
0022     Kirigami.PromptDialog {
0023         id: emailInfoDialog
0024 
0025         property int index
0026         property string domain
0027         property int accountCount
0028         property date createdAt
0029         property int ipCount
0030 
0031         title: i18nc("@title", "E-Mail Domain Info")
0032 
0033         contentPadding: 0
0034         implicitWidth: Kirigami.Units.gridUnit * 20
0035 
0036         mainItem: ColumnLayout {
0037             spacing: 0
0038 
0039             FormCard.FormTextDelegate {
0040                 text: i18nc("@info The domain on which the block is imposed", "Email domain name")
0041                 description: emailInfoDialog.domain
0042                 Layout.fillWidth: true
0043             }
0044 
0045             FormCard.FormDelegateSeparator {}
0046 
0047             FormCard.FormTextDelegate {
0048                 text: i18nc("@info Time when the block was imposed.", "Block created at")
0049                 description: emailInfoDialog.createdAt.toDateString()
0050                 Layout.fillWidth: true
0051             }
0052 
0053             FormCard.FormDelegateSeparator {}
0054 
0055             FormCard.FormTextDelegate {
0056                 text: i18nc("@info The counted accounts signup attempts using that email domain within the last week.", "Account sign-up attempts in this week")
0057                 description: emailInfoDialog.accountCount
0058                 Layout.fillWidth: true
0059             }
0060 
0061             FormCard.FormDelegateSeparator {}
0062 
0063             FormCard.FormTextDelegate {
0064                 text: i18nc("@info The counted IP signup attempts of that email domain within that day.", "IP sign-up attempts in this week")
0065                 description: emailInfoDialog.ipCount
0066                 Layout.fillWidth: true
0067             }
0068         }
0069 
0070         standardButtons: Kirigami.Dialog.NoButton
0071         customFooterActions: [
0072             Kirigami.Action {
0073                 text: i18nc("@action:button", "Cancel")
0074                 icon.name: "dialog-cancel"
0075                 onTriggered: emailInfoDialog.close();
0076             },
0077             Kirigami.Action {
0078                 text: i18nc("@action:button", "Delete email block")
0079                 icon.name: "delete"
0080                 onTriggered: {
0081                     emailBlockView.model.deleteEmailBlock(emailInfoDialog.index)
0082                     showPassiveNotification(i18n("Email block deleted"))
0083                     emailInfoDialog.close();
0084                 }
0085             }
0086         ]
0087     }
0088 
0089     Kirigami.PromptDialog {
0090         id: newEmailBlockDialog
0091 
0092         title: i18nc("@title", "New E-Mail Domain Block")
0093 
0094         contentPadding: 0
0095         implicitWidth: Kirigami.Units.gridUnit * 20
0096 
0097         mainItem: ColumnLayout {
0098             spacing: 0
0099 
0100             FormCard.FormTextFieldDelegate {
0101                 id: email
0102                 label: i18nc("@info The domain on which the block will be imposed", "Domain *")
0103                 statusMessage: i18n("This can be the domain name that shows up in the e-mail address or the MX record it uses. They will be checked upon sign-up.")
0104                 status: Kirigami.MessageType.Information
0105             }
0106         }
0107 
0108         standardButtons: Kirigami.Dialog.NoButton
0109         customFooterActions: [
0110             Kirigami.Action {
0111                 text: i18nc("@action:button", "Cancel")
0112                 icon.name: "dialog-cancel"
0113                 onTriggered: newEmailBlockDialog.close();
0114             },
0115             Kirigami.Action {
0116                 text: i18nc("@action:button", "Resolve domain")
0117                 icon.name: "checkbox"
0118                 onTriggered: {
0119                     emailBlockView.model.newEmailBlock(email.text)
0120                     showPassiveNotification(i18n("New email block added"))
0121                     email.clear()
0122                     newEmailBlockDialog.close();
0123                 }
0124             }
0125         ]
0126     }
0127 
0128     ListView {
0129         id: emailBlockView
0130 
0131         model: EmailBlockToolModel {}
0132         currentIndex: -1
0133 
0134         delegate: Delegates.RoundedItemDelegate {
0135             id: delegate
0136 
0137             required property int index
0138             required property int id
0139             required property string domain
0140             required property date createdAt
0141             required property int accountCount
0142             required property int ipCount
0143 
0144             property int totalCount: delegate.ipCount + delegate.accountCount
0145 
0146             width: ListView.view.width
0147 
0148             text: delegate.domain
0149 
0150             onClicked: {
0151                 emailInfoDialog.index = delegate.index
0152                 emailInfoDialog.domain = delegate.domain
0153                 emailInfoDialog.createdAt = delegate.createdAt
0154                 emailInfoDialog.ipCount = delegate.ipCount
0155                 emailInfoDialog.accountCount = delegate.accountCount
0156                 emailInfoDialog.open()
0157             }
0158 
0159             contentItem: RowLayout {
0160                 Delegates.SubtitleContentItem {
0161                     itemDelegate: delegate
0162                     bold: true
0163                     subtitle: i18nc("@info", "%1 sign-up attempts over the last week", delegate.totalCount)
0164                 }
0165 
0166                 Item {
0167                     Layout.fillWidth: true
0168                 }
0169 
0170                 Kirigami.Heading {
0171                     level: 3
0172                     text: delegate.createdAt.toLocaleDateString()
0173                     type: Kirigami.Heading.Type.Secondary
0174                     Layout.alignment: Qt.AlignRight
0175                 }
0176             }
0177 
0178             QQC2.ProgressBar {
0179                 visible: emailBlockView.model.loading && emailBlockView.count === 0
0180                 anchors.centerIn: parent
0181                 indeterminate: true
0182             }
0183             Kirigami.PlaceholderMessage {
0184                 anchors.centerIn: parent
0185                 text: i18n("No email blocks found")
0186                 visible: emailBlockView.count === 0 && !emailBlockView.model.loading
0187                 width: parent.width - Kirigami.Units.gridUnit * 4
0188             }
0189         }
0190     }
0191 }