Skip to content

Commit 47e0e87

Browse files
authored
Merge pull request #24 from geotribu/fix/clean-username
fix(nickname): make `getuser` compliant with qchat
2 parents db50430 + 58a4534 commit 47e0e87

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

qchat/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
QCHAT_NICKNAME_MINLENGTH: int = 3
2+
QCHAT_NICKNAME_MAXLENGTH_DEFAULT: int = 32
23
ADMIN_MESSAGES_NICKNAME: str = "admin"
34
ADMIN_MESSAGES_AVATAR: str = "mIconWarning.svg"
45
ERROR_MESSAGES_COLOR: str = "#ff0000"

qchat/gui/dck_qchat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
QCHAT_MESSAGE_TYPE_NEWCOMER,
4242
QCHAT_MESSAGE_TYPE_POSITION,
4343
QCHAT_MESSAGE_TYPE_TEXT,
44+
QCHAT_NICKNAME_MAXLENGTH_DEFAULT,
4445
QCHAT_NICKNAME_MINLENGTH,
4546
)
4647
from qchat.gui.qchat_tree_widget_items import (
@@ -252,8 +253,8 @@ def on_widget_opened(self) -> None:
252253
self.max_author_length = rules["max_author_length"]
253254
except Exception as exc:
254255
self.iface.messageBar().pushCritical(self.tr("QChat error"), str(exc))
255-
self.min_author_length = 3
256-
self.max_author_length = 32
256+
self.min_author_length = QCHAT_NICKNAME_MINLENGTH
257+
self.max_author_length = QCHAT_NICKNAME_MAXLENGTH_DEFAULT
257258

258259
# clear channel combobox items
259260
self.cbb_channel.clear() # delete all items from comboBox

qchat/gui/gui_commons.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
# alphanumeric
1414
_alphanum_qreg = QRegularExpression("[a-z-A-Z-0-9-_]+")
15+
_alphanum_excl = r"[^a-zA-Z0-9-_]"
1516
QVAL_ALPHANUM = QRegularExpressionValidator(_alphanum_qreg)
1617

1718
# alphanumeric extended

qchat/toolbelt/preferences.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22

33
"""Plugin settings."""
44

5+
import re
6+
57
# standard
68
from dataclasses import asdict, dataclass, fields
79
from getpass import getuser
810

911
# PyQGIS
1012
from qgis.core import QgsSettings
1113

12-
# package
1314
import qchat.toolbelt.log_handler as log_hdlr
1415
from qchat.__about__ import __title__, __version__
16+
17+
# package
18+
from qchat.constants import QCHAT_NICKNAME_MAXLENGTH_DEFAULT
19+
from qchat.gui.gui_commons import _alphanum_excl
1520
from qchat.toolbelt.env_var_parser import EnvVarParser
1621

1722
# ############################################################################
@@ -60,7 +65,9 @@ class PlgSettingsStructure:
6065
f"utm_source=QGIS&utm_medium={__title__}&utm_campaign=plugin_{__version__}"
6166
)
6267

63-
nickname: str = getuser()
68+
nickname: str = re.sub(_alphanum_excl, "_", getuser())[
69+
:QCHAT_NICKNAME_MAXLENGTH_DEFAULT
70+
]
6471
avatar: str = "mGeoPackage.svg"
6572

6673
instance_uri: str = "https://qchat.geotribu.net"

0 commit comments

Comments
 (0)