Skip to content

Commit

Permalink
fix(@desktop/communities): enforce alphanumerical characters in commu…
Browse files Browse the repository at this point in the history
…nity name, description, channel name
  • Loading branch information
mprakhov committed Jan 30, 2023
1 parent 3c4d972 commit 44cc6bb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ StatusInput {
minLength: 1
errorMessage: Utils.getErrorMessage(root.errors,
qsTr("community description"))
},
StatusRegularExpressionValidator {
regularExpression: Constants.regularExpressions.alphanumericalExpanded
errorMessage: Constants.errorMessages.alphanumericalExpandedRegExp
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ StatusInput {
label: qsTr("Name your community")
charLimit: 30
placeholderText: qsTr("A catchy name")

validators: [
StatusMinLengthValidator {
minLength: 1
errorMessage: Utils.getErrorMessage(root.errors,
qsTr("community name"))
},
StatusRegularExpressionValidator {
regularExpression: Constants.regularExpressions.alphanumericalExpanded
errorMessage: Constants.errorMessages.alphanumericalExpandedRegExp
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ StatusScrollView {
property size bottomReservedSpace: Qt.size(0, 0)
property bool bottomReservedSpaceActive: false

readonly property bool saveChangesButtonEnabled: true
readonly property bool saveChangesButtonEnabled: !((nameInput.input.dirty && !nameInput.valid) ||
(descriptionTextInput.input.dirty && !descriptionTextInput.valid))

ColumnLayout {
id: layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ StatusDialog {
StatusMinLengthValidator {
minLength: 1
errorMessage: Utils.getErrorMessage(nameInput.errors, qsTr("channel name"))
},
StatusRegularExpressionValidator {
regularExpression: Constants.regularExpressions.alphanumericalExpanded
errorMessage: Constants.errorMessages.alphanumericalExpandedRegExp
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ StatusScrollView {
objectName: "communityColorPanelSelectColorButton"
text: qsTr("Select Community Colour")
onClicked: root.accepted()
enabled: hexInput.valid
}

property alias color: colorSpace.color
Expand Down
8 changes: 8 additions & 0 deletions ui/imports/utils/Constants.qml
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,14 @@ QtObject {
readonly property int telegram: 6
}

readonly property QtObject regularExpressions: QtObject {
readonly property var alphanumericalExpanded: /^$|^[a-zA-Z0-9\-_ ]+$/
}

readonly property QtObject errorMessages: QtObject {
readonly property string alphanumericalExpandedRegExp: qsTr("Only letters, numbers, underscores, whitespaces and hyphens allowed")
}

readonly property var socialLinkPrefixesByType: [ // NB order must match the "socialLinkType" enum above
"",
"https://twitter.com/",
Expand Down

0 comments on commit 44cc6bb

Please sign in to comment.