master
Romain J 7 months ago
parent 0ab6dd705c
commit 886f187411
No known key found for this signature in database
GPG Key ID: 3227578329C2A3A7
  1. 0
      .idea/sonarlint/issuestore/c/5/c590740c4ac867b1db50168e191a9f5bbca5397c
  2. 2
      .idea/sonarlint/issuestore/index.pb
  3. 1
      .pylintrc
  4. 6
      Makefile
  5. 10
      README.rst
  6. 14
      chat/apps/guilds/features/channels/consumers/consumers.py
  7. 2
      chat/apps/guilds/features/channels/consumers/message_types.py
  8. 8
      chat/apps/guilds/features/channels/models.py
  9. 2
      chat/apps/guilds/features/channels/views.py
  10. 2
      chat/apps/guilds/features/invites/views.py
  11. 18
      chat/apps/guilds/forms.py
  12. 2
      chat/apps/guilds/views.py
  13. 4
      chat/apps/users/forms.py
  14. 10
      chat/apps/users/views.py
  15. 2
      chat/libs/templatetags/guilds.py
  16. 5
      chat/utils/middleware.py
  17. 6
      config/settings/base.py

@ -31,8 +31,6 @@ h
.chat/apps/guilds/features/channels/__init__.py,1/e/1ec598764d7b8851aa9d3cd178d3c844b5d132b9
B
chat/pages/apps.py,b/6/b61d6a1f522283203801f2468bf9caba725507ae
H
chat/apps/users/forms.py,c/5/c590740c4ac867b1db50168e191a9f5bbca5397c
@
.readthedocs.yml,8/1/81ccd5c4e1f93eb3ab80c73b5532455bf4f82fe9
V

@ -1,5 +1,6 @@
[MASTER]
load-plugins=pylint_django
ignore=tests
disable=
W0221, # arguments-differ
R0201, # no-self-use

@ -8,8 +8,6 @@ PYTHON_PATH := $(VIRTUAL_ENV)/bin/python
MANAGE_PY := DJANGO_READ_DOT_ENV_FILE=True $(PYTHON_PATH) manage.py
TESTS := chat/pages/tests/ chat/users/tests/ chat/guilds/tests/
#######################
# Dev
#######################
@ -58,9 +56,7 @@ graph_model:
lint:
$(PYTHON_PATH) -m pylint chat \
--load-plugins=pylint_django \
--django-settings-module=config.settings.local \
$(addprefix -d duplicate-code , $(TESTS)) \
$(addprefix -d line-too-long , $(TESTS))
--django-settings-module=config.settings.local
.PHONY: black
black:

@ -27,20 +27,18 @@ Setting Up Your Users
* To create a **normal user account**, just go to Sign Up and fill out the form. Once you submit it, you'll see a "Verify Your E-mail Address" page. Go to your console to see a simulated email verification message. Copy the link into your browser. Now the user's email should be verified and ready to go.
* To create an **superuser account**, use this command::
$ python manage.py createsuperuser
* To create an **superuser account**, create a normal user account then change `is_staff` and `is_superuser` manually in database.
For convenience, you can keep your normal user logged in on Chrome and your superuser logged in on Firefox (or similar), so that you can see how the site behaves for both kinds of users.
Type checks
Style/lint checks
^^^^^^^^^^^
Running type checks with mypy:
Running type checking and linter with:
::
$ mypy chat
$ make style
Test coverage
^^^^^^^^^^^^^

@ -150,10 +150,14 @@ class ChatConsumer(AsyncWebsocketConsumer):
for member in await self._get_members(guild):
public_keys[str(member.id)] = member.public_key
await self.send(text_data=json.dumps({
"cmd": message_types.OutgoingMessageTypes.GiveMembersPubKeys,
"data": public_keys
}))
await self.send(
text_data=json.dumps(
{
"cmd": message_types.OutgoingMessageTypes.GiveMembersPubKeys,
"data": public_keys,
}
)
)
# =========================================================================
# =========================================================================
@ -212,5 +216,5 @@ class ChatConsumer(AsyncWebsocketConsumer):
"recipient": str(message.recipient.id),
"content": escape(message.content),
"nonce": escape(message.nonce),
}
},
}

@ -5,7 +5,7 @@ from typing import NamedTuple
class MessageTypes(enum.EnumMeta):
def __contains__(cls, item):
return item in [v.value for v in cls.__members__.values()]
return item in [v.value for v in cls.__members__.values()] # type: ignore
class OutgoingMessageTypes(str, enum.Enum, metaclass=MessageTypes):

@ -53,7 +53,11 @@ class Channel(models.Model):
position = models.IntegerField(default=1)
parent = models.ForeignKey(
"Category", on_delete=models.SET_NULL, default=None, blank=True, null=True
"Category",
on_delete=models.SET_NULL,
default=None,
blank=True,
null=True,
)
name = models.TextField(max_length=100)
@ -61,7 +65,7 @@ class Channel(models.Model):
# =========================================================================
def get_messages(self, recipient: User):
def get_messages(self, recipient):
return Message.objects.filter(channel=self, recipient=recipient)
# =========================================================================

@ -90,6 +90,6 @@ class GuildChannelDetailView(BaseChannelView):
guild_id: uuid.UUID,
channel_id: uuid.UUID,
) -> JsonResponse:
result = {}
result = {} # type: ignore
return JsonResponse(result)

@ -26,7 +26,7 @@ class GuildJoinInviteView(LoginRequiredMixin, View):
return redirect("guild:guild_details", guild_id=guild.id)
invite.uses += 1
guild.members.add(self.request.user) # type: ignore
guild.members.add(self.request.user)
guild.save()
invite.save()

@ -84,6 +84,7 @@ class GuildCategoriesForm(forms.ModelForm):
fields = ["name"]
# =============================================================================
@ -93,6 +94,7 @@ class GuildChannelsForm(forms.ModelForm):
fields = ["parent", "name", "topic"]
# =============================================================================
# Custom forms
# =============================================================================
@ -116,11 +118,13 @@ def move_row(request: ASGIRequest, data: dict) -> Optional[Tuple[bool, dict]]:
}
row.position += 1 if direction == "down" else -1
old_row = Category.objects.filter(guild=guild, position=row.position).first()
old_row.position -= 1 if direction == "down" else -1
old_row = Category.objects.filter(
guild=guild, position=row.position
).first()
old_row.position -= 1 if direction == "down" else -1 # type: ignore
row.save()
old_row.save()
old_row.save() # type: ignore
if isinstance(row, Channel):
if (direction == "up" and row.position == 1) or (
@ -135,11 +139,13 @@ def move_row(request: ASGIRequest, data: dict) -> Optional[Tuple[bool, dict]]:
}
row.position += 1 if direction == "down" else -1
old_row = Channel.objects.filter(guild=guild, position=row.position).first()
old_row.position -= 1 if direction == "down" else -1
old_row = Channel.objects.filter(
guild=guild, position=row.position
).first()
old_row.position -= 1 if direction == "down" else -1 # type: ignore
row.save()
old_row.save()
old_row.save() # type: ignore
return True, {
"data": {"success": True, "message": "Row moved."},

@ -146,7 +146,7 @@ class GuildInvitesView(BaseGuildView):
if not (invite := Invite.objects.filter(guild_id=guild.id).first()):
invite = Invite(
guild=guild,
author=self.request.user, # type: ignore
author=self.request.user,
)
invite.save()

@ -88,8 +88,8 @@ class ResetPasswordForm(forms.Form):
username=cleaned_data["username"]
).first()
if not (self.user and self.user.mnemonic) or not check_password(
cleaned_data["mnemonic"], self.user.mnemonic
if not (self.user and self.user.mnemonic) or not check_password( # type: ignore
cleaned_data["mnemonic"], self.user.mnemonic # type: ignore
):
self.add_error("__all__", _("Username or mnemonic incorrect."))

@ -51,7 +51,7 @@ class UserRedirectView(BaseUsersView, RedirectView):
def get_redirect_url(self):
return reverse(
"users:detail", kwargs={"username": self.request.user.username}
"users:detail", kwargs={"username": self.request.user.username} # type: ignore
)
@ -127,7 +127,9 @@ class UserFistConnectView(BaseUsersView, View):
template_name = template_path + "first_connect"
def get(self, request: ASGIRequest, page: str = "first") -> HttpResponse:
if (user_settings := User.objects.get(id=request.user.id)) and not user_settings.first_connect:
if (
user_settings := User.objects.get(id=request.user.id) # type: ignore
) and not user_settings.first_connect:
return redirect("users:redirect")
if page == "first":
@ -182,7 +184,7 @@ class UserFistConnectView(BaseUsersView, View):
del request.session["mnemonics"]
user = User.objects.get(id=request.user.id)
user = User.objects.get(id=request.user.id) # type: ignore
user.mnemonic = make_password(mnemonic)
user.public_key = public_key
user.first_connect = False
@ -198,4 +200,4 @@ class UserFistConnectView(BaseUsersView, View):
),
)
return redirect("users:detail", username=request.user.username)
return redirect("users:detail", username=request.user.username) # type: ignore

@ -45,7 +45,7 @@ def show_channels_from_category(category: Category):
@register.simple_tag(name="collapsed_category")
def collapsed_category(category: Category, member: User): # type: ignore
if hasattr(member, "settings") and member.settings:
if hasattr(member, "settings") and member.settings: # type: ignore
user_settings: UserSettings = member.settings # type: ignore
return user_settings.collapsed_categories.filter(

@ -96,7 +96,7 @@ class CustomLocaleMiddleware(LocaleMiddleware):
prefixed_default_language,
) = is_language_prefix_patterns_used(urlconf)
language = translation.get_language_from_request(
request, check_path=i18n_patterns_used
request, check_path=i18n_patterns_used # type: ignore
)
language_from_path = translation.get_language_from_path(
request.path_info
@ -110,7 +110,7 @@ class CustomLocaleMiddleware(LocaleMiddleware):
language = settings.LANGUAGE_CODE
if request.user.is_authenticated and hasattr(request.user, "settings"):
language = getattr(request.user.settings, "language", language)
language = getattr(request.user.settings, "language", language) # type: ignore
translation.activate(language)
request.LANGUAGE_CODE = translation.get_language() # type: ignore
@ -129,6 +129,7 @@ class EnsureMnemonicGeneration(MiddlewareMixin):
):
return None
# noinspection PyUnresolvedReferences
if request.user.is_authenticated and request.user.first_connect:
return redirect("users:first_connect")

@ -323,7 +323,11 @@ ACCOUNT_FORMS = {
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
CORS_ALLOWED_ORIGINS = ["https://c3e.gnous.eu", "http://127.0.0.1:8000", "http://127.0.0.1:3000"]
CORS_ALLOWED_ORIGINS = [
"https://c3e.gnous.eu",
"http://127.0.0.1:8000",
"http://127.0.0.1:3000",
]
CHANNEL_LAYERS = {
"default": {"BACKEND": "channels.layers.InMemoryChannelLayer"}

Loading…
Cancel
Save