-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMainIpRulePage.qml
216 lines (184 loc) · 7.79 KB
/
MainIpRulePage.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// SPDX-FileCopyrightText: 2023 Rishi Kumar <[email protected]>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import org.kde.kirigami 2 as Kirigami
import QtQuick.Controls 2 as QQC2
import QtQuick.Layouts
import org.kde.tokodon
import org.kde.kirigamiaddons.formcard 1 as FormCard
import org.kde.kirigamiaddons.labs.components 1 as Components
import org.kde.kirigamiaddons.delegates 1 as Delegates
FormCard.FormCardPage {
id: root
property int index
property var model
property int id
property string ip
property int severity
property string comment
property date createdAt
property date expiredAt
title: root.ip
property string displaySeverity: {
if (root.severity === IpInfo.LimitSignUps) {
return i18nc("@label", "Limit sign-ups");
} else if (root.severity === IpInfo.BlockSignUps) {
return i18nc("@label", "Block sign-ups");
} else {
return i18nc("@label", "Block access");
}
}
actions.contextualActions: Kirigami.Action {
icon.name: "edit-delete-remove"
text: i18nc("@action:inmenu", "Remove IP Rule")
onTriggered: {
root.model.deleteIpBlock(root.index)
showPassiveNotification(i18n("IP Rule Removed"))
pageStack.layers.pop()
}
}
data: Kirigami.PromptDialog {
id: updateIpRuleDialog
title: i18nc("@title:window", "Update IP Rule")
property string calculatedseverity: signupLimit.checked ? "sign_up_requires_approval" : signupBlock.checked ? "sign_up_block" : "no_access"
contentPadding: 0
implicitWidth: Kirigami.Units.gridUnit * 20
mainItem: ColumnLayout {
spacing: 0
FormCard.FormTextDelegate {
id: ip
text: i18nc("@info IP address of the ip block", "IP")
description: root.ip
}
FormCard.FormDelegateSeparator {below: ip; above: expireAfter}
FormCard.FormComboBoxDelegate {
id: expireAfter
property var currentDate: new Date()
text: i18nc("@info Time after which the rule will be lifted", "Expire After")
textRole: "display"
valueRole: "value"
model: [
{
display: i18nc("@info Option to block out the IP for 1 day", "1 day"),
value: IpRulesToolModel.Oneday
},
{
display: i18nc("@info Option to block out the IP for 2 weeks", "2 weeks"),
value: IpRulesToolModel.Twoweeks
},
{
display: i18nc("@info Option to block out the IP for 1 month", "1 month"),
value: IpRulesToolModel.Onemonth
},
{
display: i18nc("@info Option to block out the IP for 6 months", "6 month"),
value: IpRulesToolModel.Sixmonths
},
{
display: i18nc("@info Option to block out the IP for 1 year", "1 year"),
value: IpRulesToolModel.OneYear
},
{
display: i18nc("@info Option to block out the IP for 3 years", "3 year"),
value: IpRulesToolModel.ThreeYears
},
]
onCurrentIndexChanged: root.expiredAt = new Date(currentDate.getTime() + (model[currentIndex].value * 1000));
Component.onCompleted: {expireAfter.currentIndex = expireAfter.indexOfValue(IpRulesToolModel.Oneday);
}
}
FormCard.FormDelegateSeparator {below: expireAfter; above: comment}
FormCard.FormTextFieldDelegate {
id: comment
label: i18nc("@info The comment attached with the ip rule", "Comment")
text: root.comment
placeholderText: i18n("Optional. Remember why you added this rule.")
}
FormCard.FormDelegateSeparator {below: comment; above: rule}
FormCard.FormHeader {
id: rule
title: i18nc("@info The rule attached with the ip rule", "Rule *")
}
QQC2.Label {
text: i18n("Choose what will happen with requests from this IP")
Layout.fillWidth: true
Layout.leftMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
Layout.rightMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
}
FormCard.FormRadioDelegate {
id: signupLimit
text: i18n("Limit sign-ups")
description: i18n("New sign-ups will require your approval")
onToggled: root.severity = IpInfo.LimitSignUps
}
FormCard.FormRadioDelegate {
id: signupBlock
text: i18n("Block sign-ups")
description: i18n("New sign-ups will not be possible")
onToggled: root.severity = IpInfo.BlockSignUps
}
FormCard.FormRadioDelegate {
id: accessBlock
text: i18n("Block access")
description: i18n("Block access to all resources")
onToggled: root.severity = IpInfo.BlockAccess
}
FormCard.FormDelegateSeparator {below: accessBlock}
}
standardButtons: Kirigami.Dialog.NoButton
customFooterActions: [
Kirigami.Action {
text: i18nc("@info Cancel button to close the dailog", "Cancel")
icon.name: "dialog-cancel"
onTriggered: updateIpRuleDialog.close();
},
Kirigami.Action {
text: i18nc("@info Button to update an IP rule", "Update IP rule")
icon.name: "checkbox"
onTriggered: {
root.comment = comment.text
root.model.updateIpBlock(root.index, root.ip, updateIpRuleDialog.calculatedseverity, comment.text, expireAfter.currentValue)
showPassiveNotification(i18n("IP rule updated"))
updateIpRuleDialog.close();
}
}
]
}
FormCard.FormCard {
Layout.topMargin: Kirigami.Units.largeSpacing
FormCard.FormTextDelegate {
text: i18n("Blocked at")
description: root.createdAt.toLocaleDateString()
}
FormCard.FormDelegateSeparator {}
FormCard.FormTextDelegate {
text: i18nc("@info Time after which the rule will be lifted", "Expires at")
description: root.expiredAt.toLocaleDateString()
}
FormCard.FormDelegateSeparator {}
FormCard.FormTextDelegate {
text: i18nc("@info The comment attached with the ip rule", "Comment")
description: root.comment.length !== 0 ? root.comment : i18nc("@info No public comment provided", "None")
}
FormCard.FormDelegateSeparator {}
FormCard.FormTextDelegate {
text: i18nc("@info The severity to be applied by this IP rule", "Severity")
description: root.displaySeverity
}
}
footer: QQC2.ToolBar {
contentItem: RowLayout {
Item {
Layout.fillWidth: true
}
QQC2.Button {
text: i18nc("@action:button", "Update IP Rule")
icon.name: 'cell_edit'
Layout.margins: Kirigami.Units.smallSpacing
onClicked: {
updateIpRuleDialog.open()
}
}
}
}
}