Warning, /network/tokodon/src/content/ui/ModerationTools/MainIpRulePage.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 FormCard.FormCardPage { 0014 id: root 0015 0016 property int index 0017 property var model 0018 property int id 0019 property string ip 0020 property int severity 0021 property string comment 0022 property date createdAt 0023 property date expiredAt 0024 0025 title: root.ip 0026 0027 property string displaySeverity: { 0028 if (root.severity === IpInfo.LimitSignUps) { 0029 return i18nc("@label", "Limit sign-ups"); 0030 } else if (root.severity === IpInfo.BlockSignUps) { 0031 return i18nc("@label", "Block sign-ups"); 0032 } else { 0033 return i18nc("@label", "Block access"); 0034 } 0035 } 0036 0037 0038 actions.contextualActions: Kirigami.Action { 0039 icon.name: "edit-delete-remove" 0040 text: i18nc("@action:inmenu", "Remove IP Rule") 0041 onTriggered: { 0042 root.model.deleteIpBlock(root.index) 0043 showPassiveNotification(i18n("IP Rule Removed")) 0044 pageStack.layers.pop() 0045 } 0046 } 0047 0048 data: Kirigami.PromptDialog { 0049 id: updateIpRuleDialog 0050 0051 title: i18nc("@title:window", "Update IP Rule") 0052 0053 property string calculatedseverity: signupLimit.checked ? "sign_up_requires_approval" : signupBlock.checked ? "sign_up_block" : "no_access" 0054 0055 contentPadding: 0 0056 implicitWidth: Kirigami.Units.gridUnit * 20 0057 0058 mainItem: ColumnLayout { 0059 spacing: 0 0060 0061 FormCard.FormTextDelegate { 0062 id: ip 0063 text: i18nc("@info IP address of the ip block", "IP") 0064 description: root.ip 0065 } 0066 0067 FormCard.FormDelegateSeparator {below: ip; above: expireAfter} 0068 0069 FormCard.FormComboBoxDelegate { 0070 id: expireAfter 0071 property var currentDate: new Date() 0072 text: i18nc("@info Time after which the rule will be lifted", "Expire After") 0073 textRole: "display" 0074 valueRole: "value" 0075 model: [ 0076 { 0077 display: i18nc("@info Option to block out the IP for 1 day", "1 day"), 0078 value: IpRulesToolModel.Oneday 0079 }, 0080 { 0081 display: i18nc("@info Option to block out the IP for 2 weeks", "2 weeks"), 0082 value: IpRulesToolModel.Twoweeks 0083 }, 0084 { 0085 display: i18nc("@info Option to block out the IP for 1 month", "1 month"), 0086 value: IpRulesToolModel.Onemonth 0087 }, 0088 { 0089 display: i18nc("@info Option to block out the IP for 6 months", "6 month"), 0090 value: IpRulesToolModel.Sixmonths 0091 }, 0092 { 0093 display: i18nc("@info Option to block out the IP for 1 year", "1 year"), 0094 value: IpRulesToolModel.OneYear 0095 }, 0096 { 0097 display: i18nc("@info Option to block out the IP for 3 years", "3 year"), 0098 value: IpRulesToolModel.ThreeYears 0099 }, 0100 ] 0101 onCurrentIndexChanged: root.expiredAt = new Date(currentDate.getTime() + (model[currentIndex].value * 1000)); 0102 Component.onCompleted: {expireAfter.currentIndex = expireAfter.indexOfValue(IpRulesToolModel.Oneday); 0103 } 0104 } 0105 FormCard.FormDelegateSeparator {below: expireAfter; above: comment} 0106 FormCard.FormTextFieldDelegate { 0107 id: comment 0108 label: i18nc("@info The comment attached with the ip rule", "Comment") 0109 text: root.comment 0110 placeholderText: i18n("Optional. Remember why you added this rule.") 0111 0112 } 0113 FormCard.FormDelegateSeparator {below: comment; above: rule} 0114 0115 FormCard.FormHeader { 0116 id: rule 0117 title: i18nc("@info The rule attached with the ip rule", "Rule *") 0118 } 0119 0120 QQC2.Label { 0121 text: i18n("Choose what will happen with requests from this IP") 0122 Layout.fillWidth: true 0123 Layout.leftMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing 0124 Layout.rightMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing 0125 } 0126 0127 FormCard.FormRadioDelegate { 0128 id: signupLimit 0129 text: i18n("Limit sign-ups") 0130 description: i18n("New sign-ups will require your approval") 0131 onToggled: root.severity = IpInfo.LimitSignUps 0132 } 0133 0134 FormCard.FormRadioDelegate { 0135 id: signupBlock 0136 text: i18n("Block sign-ups") 0137 description: i18n("New sign-ups will not be possible") 0138 onToggled: root.severity = IpInfo.BlockSignUps 0139 } 0140 0141 FormCard.FormRadioDelegate { 0142 id: accessBlock 0143 text: i18n("Block access") 0144 description: i18n("Block access to all resources") 0145 onToggled: root.severity = IpInfo.BlockAccess 0146 } 0147 0148 FormCard.FormDelegateSeparator {below: accessBlock} 0149 } 0150 0151 standardButtons: Kirigami.Dialog.NoButton 0152 customFooterActions: [ 0153 Kirigami.Action { 0154 text: i18nc("@info Cancel button to close the dailog", "Cancel") 0155 icon.name: "dialog-cancel" 0156 onTriggered: updateIpRuleDialog.close(); 0157 }, 0158 Kirigami.Action { 0159 text: i18nc("@info Button to update an IP rule", "Update IP rule") 0160 icon.name: "checkbox" 0161 onTriggered: { 0162 root.comment = comment.text 0163 root.model.updateIpBlock(root.index, root.ip, updateIpRuleDialog.calculatedseverity, comment.text, expireAfter.currentValue) 0164 showPassiveNotification(i18n("IP rule updated")) 0165 updateIpRuleDialog.close(); 0166 } 0167 } 0168 ] 0169 } 0170 0171 FormCard.FormCard { 0172 Layout.topMargin: Kirigami.Units.largeSpacing 0173 0174 FormCard.FormTextDelegate { 0175 text: i18n("Blocked at") 0176 description: root.createdAt.toLocaleDateString() 0177 } 0178 0179 FormCard.FormDelegateSeparator {} 0180 0181 FormCard.FormTextDelegate { 0182 text: i18nc("@info Time after which the rule will be lifted", "Expires at") 0183 description: root.expiredAt.toLocaleDateString() 0184 } 0185 0186 FormCard.FormDelegateSeparator {} 0187 0188 FormCard.FormTextDelegate { 0189 text: i18nc("@info The comment attached with the ip rule", "Comment") 0190 description: root.comment.length !== 0 ? root.comment : i18nc("@info No public comment provided", "None") 0191 } 0192 0193 FormCard.FormDelegateSeparator {} 0194 0195 FormCard.FormTextDelegate { 0196 text: i18nc("@info The severity to be applied by this IP rule", "Severity") 0197 description: root.displaySeverity 0198 } 0199 } 0200 0201 footer: QQC2.ToolBar { 0202 contentItem: RowLayout { 0203 Item { 0204 Layout.fillWidth: true 0205 } 0206 QQC2.Button { 0207 text: i18nc("@action:button", "Update IP Rule") 0208 icon.name: 'cell_edit' 0209 Layout.margins: Kirigami.Units.smallSpacing 0210 onClicked: { 0211 updateIpRuleDialog.open() 0212 } 0213 } 0214 } 0215 } 0216 }