Warning, /network/tokodon/src/content/ui/ModerationTools/IpRulePage.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 Rule") 0018 icon.name: 'list-add' 0019 onTriggered: newIpRuleDialog.open() 0020 } 0021 0022 Kirigami.PromptDialog { 0023 id: newIpRuleDialog 0024 0025 title: i18n("New IP Rule") 0026 0027 property string calculatedSeverity: signupLimit.checked ? "sign_up_requires_approval" : signupBlock.checked ? "sign_up_block" : "no_access" 0028 0029 contentPadding: 0 0030 implicitWidth: Kirigami.Units.gridUnit * 20 0031 0032 mainItem: ColumnLayout { 0033 spacing: 0 0034 0035 FormCard.FormTextFieldDelegate { 0036 id: ip 0037 label: i18nc("@info:Enter the domain address of the domain block", "IP*") 0038 placeholderText: "192.0.2.0/24" 0039 } 0040 FormCard.FormDelegateSeparator {above: expireAfter; below: ip} 0041 FormCard.FormComboBoxDelegate { 0042 id: expireAfter 0043 text: i18nc("@info:Time after which the rule will be lifted", "Expire After") 0044 textRole: "display" 0045 valueRole: "value" 0046 model: [ 0047 { 0048 display: i18nc("@info:Option to block out the IP for 1 day", "1 day"), 0049 value: IpRulesToolModel.Oneday 0050 }, 0051 { 0052 display: i18nc("@info:Option to block out the IP for 2 weeks", "2 weeks"), 0053 value: IpRulesToolModel.Twoweeks 0054 }, 0055 { 0056 display: i18nc("@info:Option to block out the IP for 1 month", "1 month"), 0057 value: IpRulesToolModel.Onemonth 0058 }, 0059 { 0060 display: i18nc("@info:Option to block out the IP for 6 months", "6 month"), 0061 value: IpRulesToolModel.Sixmonths 0062 }, 0063 { 0064 display: i18nc("@info:Option to block out the IP for 1 year", "1 year"), 0065 value: IpRulesToolModel.OneYear 0066 }, 0067 { 0068 display: i18nc("@info:Option to block out the IP for 3 years", "3 year"), 0069 value: IpRulesToolModel.ThreeYears 0070 }, 0071 ] 0072 0073 Component.onCompleted: {expireAfter.currentIndex = expireAfter.indexOfValue(IpRulesToolModel.Oneday); 0074 } 0075 } 0076 FormCard.FormDelegateSeparator {above: comment; below: expireAfter} 0077 FormCard.FormTextFieldDelegate { 0078 id: comment 0079 label: i18nc("@info: The comment attached with the ip rule", "Comment") 0080 placeholderText: i18n("Optional. Remember why you added this rule.") 0081 0082 } 0083 FormCard.FormDelegateSeparator { below: comment } 0084 0085 FormCard.FormHeader { 0086 id: rule 0087 title: i18nc("@info:The rule attached with the ip rule", "Rule *") 0088 } 0089 0090 QQC2.Label { 0091 text: i18n("Choose what will happen with requests from this IP") 0092 Layout.leftMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing 0093 Layout.rightMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing 0094 } 0095 0096 FormCard.FormRadioDelegate { 0097 id: signupLimit 0098 text: i18n("Limit sign-ups") 0099 description: i18n("New sign-ups will require your approval") 0100 checked: true 0101 } 0102 0103 FormCard.FormRadioDelegate { 0104 id: signupBlock 0105 text: i18n("Block sign-ups") 0106 description: i18n("New sign-ups will not be possible") 0107 } 0108 0109 FormCard.FormRadioDelegate { 0110 id: accessBlock 0111 text: i18n("Block access") 0112 description: i18n("Block access to all resources") 0113 } 0114 0115 FormCard.FormDelegateSeparator { below: accessBlock } 0116 } 0117 0118 standardButtons: Kirigami.Dialog.NoButton 0119 customFooterActions: [ 0120 Kirigami.Action { 0121 text: i18nc("@info:Cancel button to close the dailog", "Cancel") 0122 icon.name: "dialog-cancel" 0123 onTriggered: newIpRuleDialog.close(); 0124 }, 0125 Kirigami.Action { 0126 text: i18nc("@info:Button to create a IP rule", "Create IP rule") 0127 icon.name: "checkbox" 0128 onTriggered: { 0129 ipRuleView.model.newIpBlock(ip.text, expireAfter.currentValue, comment.text, newIpRuleDialog.calculatedSeverity) 0130 showPassiveNotification(i18n("New IP rule added")) 0131 newIpRuleDialog.close(); 0132 } 0133 } 0134 ] 0135 } 0136 0137 ListView { 0138 id: ipRuleView 0139 0140 model: IpRulesToolModel {} 0141 currentIndex: -1 0142 0143 delegate: Delegates.RoundedItemDelegate { 0144 id: delegate 0145 0146 required property int index 0147 required property int id 0148 required property string ip 0149 required property int severity 0150 required property string comment 0151 required property date createdAt 0152 required property date expiredAt 0153 0154 property string displaySeverity: { 0155 if (delegate.severity === IpInfo.LimitSignUps) { 0156 return i18nc("@label", "Limit sign-ups"); 0157 } else if (delegate.severity === IpInfo.BlockSignUps) { 0158 return i18nc("@label", "Block sign-ups"); 0159 } else { 0160 return i18nc("@label", "Block access"); 0161 } 0162 } 0163 0164 width: ListView.view.width 0165 0166 onClicked: applicationWindow().pageStack.layers.push("./MainIpRulePage.qml", 0167 { 0168 index: delegate.index, 0169 model: ipRuleView.model, 0170 id: delegate.id, 0171 ip: delegate.ip, 0172 severity: delegate.severity, 0173 comment: delegate.comment, 0174 createdAt: delegate.createdAt, 0175 expiredAt: delegate.expiredAt 0176 }) 0177 0178 text: delegate.ip 0179 0180 contentItem: RowLayout { 0181 Delegates.SubtitleContentItem { 0182 itemDelegate: delegate 0183 bold: true 0184 subtitle: delegate.displaySeverity 0185 } 0186 0187 Item { 0188 Layout.fillWidth: true 0189 } 0190 0191 Kirigami.Heading { 0192 level: 3 0193 text: delegate.createdAt.toLocaleDateString() 0194 type: Kirigami.Heading.Type.Secondary 0195 Layout.alignment: Qt.AlignRight 0196 } 0197 } 0198 } 0199 0200 QQC2.ProgressBar { 0201 visible: ipRuleView.model.loading && ipRuleView.count === 0 0202 anchors.centerIn: parent 0203 indeterminate: true 0204 } 0205 Kirigami.PlaceholderMessage { 0206 anchors.centerIn: parent 0207 text: i18n("No IP rules found") 0208 visible: ipRuleView.count === 0 && !ipRuleView.model.loading 0209 width: parent.width - Kirigami.Units.gridUnit * 4 0210 } 0211 } 0212 }