Skip to content

Commit

Permalink
Merge 0cf3cb5 into bd22c40
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed May 24, 2019
2 parents bd22c40 + 0cf3cb5 commit 1b39bcd
Show file tree
Hide file tree
Showing 41 changed files with 293 additions and 255 deletions.
10 changes: 1 addition & 9 deletions devproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
"misago.acl.context_processors.user_acl",
"misago.conf.context_processors.conf",
"misago.core.context_processors.misago_version",
"misago.core.context_processors.site_address",
"misago.core.context_processors.request_path",
"misago.core.context_processors.momentjs_locale",
"misago.search.context_processors.search_providers",
"misago.themes.context_processors.theme",
Expand Down Expand Up @@ -342,14 +342,6 @@
# Misago specific settings
# https://misago.readthedocs.io/en/latest/developers/settings.html

# Complete HTTP address to your Misago site homepage. Misago relies on this address to create
# links in e-mails that are sent to site users.
# On Misago admin panel home page you will find a message telling you if you have entered the
# correct value, or what value is correct in case you've didn't.

MISAGO_ADDRESS = "http://my-misago-site.com/"


# On dev instance, generate only three sizes of avatars instead of default 6 sizes.

MISAGO_AVATARS_SIZES = [400, 200, 100]
Expand Down
3 changes: 0 additions & 3 deletions devproject/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]

# Default misago address to test address
MISAGO_ADDRESS = "http://testserver/"

# Use english search config
MISAGO_SEARCH_CONFIG = "english"

Expand Down
51 changes: 30 additions & 21 deletions misago/admin/tests/test_admin_system_checks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from datetime import timedelta
from unittest.mock import Mock

import pytest
from django.contrib.auth import get_user_model
from django.test import override_settings
from django.urls import reverse
from django.utils import timezone

from ...conf.test import override_dynamic_settings
from ...test import assert_contains
from ...users.datadownloads import request_user_data_download
from ...users.models import DataDownload
Expand All @@ -14,9 +16,9 @@
check_cache,
check_data_downloads,
check_debug_status,
check_forum_address,
check_https,
check_inactive_users,
check_misago_address,
)

User = get_user_model()
Expand Down Expand Up @@ -111,58 +113,65 @@ def test_warning_about_unprocessed_data_downloads_is_displayed_on_checks_list(
class RequestMock:
absolute_uri = "https://misago-project.org/somewhere/"

def __init__(self, settings):
self.settings = settings

def build_absolute_uri(self, location):
assert location == "/"
return self.absolute_uri


request = RequestMock()
@pytest.fixture
def request_mock(dynamic_settings):
return RequestMock(dynamic_settings)


incorrect_address = "http://somewhere.com"
correct_address = request.absolute_uri
correct_address = RequestMock.absolute_uri


@override_settings(MISAGO_ADDRESS=None)
def test_misago_address_check_handles_setting_not_configured():
result = check_misago_address(request)
@override_dynamic_settings(forum_address=None)
def test_forum_address_check_handles_setting_not_configured(request_mock):
result = check_forum_address(request_mock)
assert result == {
"is_ok": False,
"set_address": None,
"correct_address": request.absolute_uri,
"correct_address": request_mock.absolute_uri,
}


@override_settings(MISAGO_ADDRESS=incorrect_address)
def test_misago_address_check_detects_invalid_address_configuration():
result = check_misago_address(request)
@override_dynamic_settings(forum_address=incorrect_address)
def test_forum_address_check_detects_invalid_address_configuration(request_mock):
result = check_forum_address(request_mock)
assert result == {
"is_ok": False,
"set_address": incorrect_address,
"correct_address": request.absolute_uri,
"correct_address": request_mock.absolute_uri,
}


@override_settings(MISAGO_ADDRESS=correct_address)
def test_misago_address_check_detects_valid_address_configuration():
result = check_misago_address(request)
@override_dynamic_settings(forum_address=correct_address)
def test_forum_address_check_detects_valid_address_configuration(request_mock):
result = check_forum_address(request_mock)
assert result == {
"is_ok": True,
"set_address": correct_address,
"correct_address": request.absolute_uri,
"correct_address": request_mock.absolute_uri,
}


@override_settings(MISAGO_ADDRESS=None)
def test_warning_about_unset_misago_address_is_displayed_on_checks_list(admin_client):
@override_dynamic_settings(forum_address=None)
def test_warning_about_unset_forum_address_is_displayed_on_checks_list(admin_client):
response = admin_client.get(admin_link)
assert_contains(response, "MISAGO_ADDRESS")
assert_contains(response, "address")


@override_settings(MISAGO_ADDRESS=incorrect_address)
def test_warning_about_incorrect_misago_address_is_displayed_on_checks_list(
@override_dynamic_settings(forum_address=incorrect_address)
def test_warning_about_incorrect_forum_address_is_displayed_on_checks_list(
admin_client
):
response = admin_client.get(admin_link)
assert_contains(response, "MISAGO_ADDRESS")
assert_contains(response, "address")


@override_settings(DEBUG=False)
Expand Down
8 changes: 4 additions & 4 deletions misago/admin/views/index.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from datetime import timedelta

from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.cache import cache
from django.utils import timezone

from . import render
from ...conf import settings
from ...threads.models import Post, Thread, Attachment
from ...users.models import DataDownload

Expand All @@ -17,7 +17,7 @@
def admin_index(request):
totals = count_db_items()
checks = {
"address": check_misago_address(request),
"address": check_forum_address(request),
"cache": check_cache(),
"data_downloads": check_data_downloads(),
"debug": check_debug_status(),
Expand Down Expand Up @@ -45,8 +45,8 @@ def check_https(request):
return {"is_ok": request.is_secure()}


def check_misago_address(request):
set_address = settings.MISAGO_ADDRESS
def check_forum_address(request):
set_address = request.settings.forum_address
correct_address = request.build_absolute_uri("/")

return {
Expand Down
18 changes: 18 additions & 0 deletions misago/conf/admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
class ChangeSettingsForm(forms.Form):
settings = []

def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request")
super().__init__(*args, **kwargs)

def save(self, settings):
self.save_settings(settings)
self.clear_cache()
Expand Down Expand Up @@ -125,6 +129,7 @@ def clean(self):
class ChangeGeneralSettingsForm(ChangeSettingsForm):
settings = [
"forum_name",
"forum_address",
"index_header",
"index_title",
"index_meta_description",
Expand All @@ -136,6 +141,7 @@ class ChangeGeneralSettingsForm(ChangeSettingsForm):
]

forum_name = forms.CharField(label=_("Forum name"), min_length=2, max_length=255)
forum_address = forms.URLField(label=_("Forum address"), max_length=255)

index_header = forms.CharField(
label=_("Header text"),
Expand Down Expand Up @@ -196,6 +202,18 @@ class ChangeGeneralSettingsForm(ChangeSettingsForm):
required=False,
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

address = self.request.build_absolute_uri("/")
self["forum_address"].help_text = _(
"Misago uses this setting to build links in e-mails sent to site "
'users. Address under which site is running appears to be "%(address)s".'
) % {"address": address}

def clean_forum_address(self):
return self.cleaned_data["forum_address"].lower()


class ChangeThreadsSettingsForm(ChangeSettingsForm):
settings = [
Expand Down
4 changes: 2 additions & 2 deletions misago/conf/admin/tests/test_change_settings_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Form(ChangeSettingsForm):


def test_form_updates_setting_on_save(setting):
form = Form({"forum_name": "New Value"})
form = Form({"forum_name": "New Value"}, request=None)
assert form.is_valid()
form.save({"forum_name": setting})

Expand All @@ -22,6 +22,6 @@ def test_form_updates_setting_on_save(setting):

def test_form_invalidates_settings_cache_on_save(setting):
with assert_invalidates_cache(SETTINGS_CACHE):
form = Form({"forum_name": "New Value"})
form = Form({"forum_name": "New Value"}, request=None)
assert form.is_valid()
form.save({"forum_name": setting})
57 changes: 43 additions & 14 deletions misago/conf/admin/tests/test_image_setting_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_image_setting_can_be_set(admin_client, setting):
with open(IMAGE, "rb") as image:
admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo": image},
{"forum_name": "Misago", "forum_address": "http://test.com", "logo": image},
)

setting.refresh_from_db()
Expand All @@ -36,7 +36,7 @@ def test_setting_image_also_sets_its_dimensions(admin_client, setting):
with open(IMAGE, "rb") as image:
admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo": image},
{"forum_name": "Misago", "forum_address": "http://test.com", "logo": image},
)

setting.refresh_from_db()
Expand All @@ -48,7 +48,7 @@ def test_setting_image_filename_is_prefixed_with_setting_name(admin_client, sett
with open(IMAGE, "rb") as image:
admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo": image},
{"forum_name": "Misago", "forum_address": "http://test.com", "logo": image},
)

setting.refresh_from_db()
Expand All @@ -59,7 +59,7 @@ def test_setting_image_filename_is_hashed(admin_client, setting):
with open(IMAGE, "rb") as image:
admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo": image},
{"forum_name": "Misago", "forum_address": "http://test.com", "logo": image},
)

setting.refresh_from_db()
Expand All @@ -70,7 +70,11 @@ def test_image_setting_rejects_non_image_file(admin_client, setting):
with open(OTHER_FILE, "rb") as not_image:
admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo": not_image},
{
"forum_name": "Misago",
"forum_address": "http://test.com",
"logo": not_image,
},
)

setting.refresh_from_db()
Expand All @@ -82,7 +86,11 @@ def setting_with_value(admin_client, setting):
with open(IMAGE, "rb") as not_image:
admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo": not_image},
{
"forum_name": "Misago",
"forum_address": "http://test.com",
"logo": not_image,
},
)

setting.refresh_from_db()
Expand All @@ -98,7 +106,11 @@ def test_invalid_file_is_not_set_as_value(admin_client, setting):
with open(OTHER_FILE, "rb") as not_image:
admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo": not_image},
{
"forum_name": "Misago",
"forum_address": "http://test.com",
"logo": not_image,
},
)

setting.refresh_from_db()
Expand All @@ -111,7 +123,11 @@ def test_uploading_invalid_file_doesnt_remove_already_set_image(
with open(OTHER_FILE, "rb") as not_image:
admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo": not_image},
{
"forum_name": "Misago",
"forum_address": "http://test.com",
"logo": not_image,
},
)

setting_with_value.refresh_from_db()
Expand All @@ -124,7 +140,11 @@ def test_set_image_is_still_rendered_when_invalid_file_was_uploaded(
with open(OTHER_FILE, "rb") as not_image:
response = admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo": not_image},
{
"forum_name": "Misago",
"forum_address": "http://test.com",
"logo": not_image,
},
)

assert_contains(response, setting_with_value.image.url)
Expand All @@ -136,7 +156,11 @@ def test_uploading_new_image_replaces_already_set_image(
with open(OTHER_IMAGE, "rb") as not_image:
admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo": not_image},
{
"forum_name": "Misago",
"forum_address": "http://test.com",
"logo": not_image,
},
)

setting_with_value.refresh_from_db()
Expand All @@ -147,7 +171,11 @@ def test_uploading_new_image_deletes_image_file(admin_client, setting_with_value
with open(OTHER_IMAGE, "rb") as not_image:
admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo": not_image},
{
"forum_name": "Misago",
"forum_address": "http://test.com",
"logo": not_image,
},
)

assert not os.path.exists(setting_with_value.image.path)
Expand All @@ -157,7 +185,8 @@ def test_omitting_setting_value_doesnt_remove_already_set_image(
admin_client, setting_with_value
):
admin_client.post(
reverse("misago:admin:settings:general:index"), {"forum_name": "Misago"}
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "forum_address": "http://test.com"},
)

setting_with_value.refresh_from_db()
Expand All @@ -167,7 +196,7 @@ def test_omitting_setting_value_doesnt_remove_already_set_image(
def test_set_image_can_be_deleted_by_extra_option(admin_client, setting_with_value):
admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo_delete": 1},
{"forum_name": "Misago", "forum_address": "http://test.com", "logo_delete": 1},
)

setting_with_value.refresh_from_db()
Expand All @@ -179,7 +208,7 @@ def test_using_image_deletion_option_deletes_image_file(
):
admin_client.post(
reverse("misago:admin:settings:general:index"),
{"forum_name": "Misago", "logo_delete": 1},
{"forum_name": "Misago", "forum_address": "http://test.com", "logo_delete": 1},
)

assert not os.path.exists(setting_with_value.image.path)
Loading

0 comments on commit 1b39bcd

Please sign in to comment.