diff --git a/messages.pot b/messages.pot index e4b2be0..144a7d0 100644 --- a/messages.pot +++ b/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-10-14 10:41+0200\n" +"POT-Creation-Date: 2021-10-14 14:32+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -2017,15 +2017,19 @@ msgstr "" msgid "Short name is already taken" msgstr "" -#: project/views/js.py:40 +#: project/views/js.py:43 +msgid "Name is already taken" +msgstr "" + +#: project/views/js.py:57 msgid "An account already exists with this email." msgstr "" -#: project/views/js.py:80 +#: project/views/js.py:97 msgid "Places of organization" msgstr "" -#: project/views/js.py:88 +#: project/views/js.py:105 msgid "Places of Google Maps" msgstr "" diff --git a/project/templates/_macros.html b/project/templates/_macros.html index aa1ea53..1ab54e8 100644 --- a/project/templates/_macros.html +++ b/project/templates/_macros.html @@ -1550,6 +1550,25 @@ $('#allday').on('change', function() { } }); + $("#name").rules("add", { + remote: { + url: "{{ url_for('js_check_org_name') }}", + type: "post" + {% if admin_unit %} + ,data: { + admin_unit_id: function() { + return "{{ admin_unit.id }}"; + } + } + {% if admin_unit.name %} + ,depends: function() { + return $('#name').val() != '{{ admin_unit.name }}'; + } + {% endif %} + {% endif %} + } + }); + $("#short_name").rules("add", "shortName"); $("#short_name").rules("add", { remote: { @@ -1586,6 +1605,7 @@ $('#allday').on('change', function() { }); if ($("#name").val().length > 0) { + $("#name").valid(); suggest_short_name(); } diff --git a/project/translations/de/LC_MESSAGES/messages.mo b/project/translations/de/LC_MESSAGES/messages.mo index 2104f57..6f1881f 100644 Binary files a/project/translations/de/LC_MESSAGES/messages.mo and b/project/translations/de/LC_MESSAGES/messages.mo differ diff --git a/project/translations/de/LC_MESSAGES/messages.po b/project/translations/de/LC_MESSAGES/messages.po index 6f4f129..86b2f96 100644 --- a/project/translations/de/LC_MESSAGES/messages.po +++ b/project/translations/de/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-10-14 10:41+0200\n" +"POT-Creation-Date: 2021-10-14 14:32+0200\n" "PO-Revision-Date: 2020-06-07 18:51+0200\n" "Last-Translator: FULL NAME \n" "Language: de\n" @@ -2070,15 +2070,19 @@ msgstr "Prüfungsstatus aktualisiert" msgid "Short name is already taken" msgstr "Der Kurzname ist bereits vergeben" -#: project/views/js.py:40 +#: project/views/js.py:43 +msgid "Name is already taken" +msgstr "Der Name ist bereits vergeben" + +#: project/views/js.py:57 msgid "An account already exists with this email." msgstr "Mit dieser E-Mail existiert bereits ein Account." -#: project/views/js.py:80 +#: project/views/js.py:97 msgid "Places of organization" msgstr "Orte der Organisation" -#: project/views/js.py:88 +#: project/views/js.py:105 msgid "Places of Google Maps" msgstr "Orte von Google Maps" diff --git a/project/translations/en/LC_MESSAGES/messages.mo b/project/translations/en/LC_MESSAGES/messages.mo index fe32177..8b55c32 100644 Binary files a/project/translations/en/LC_MESSAGES/messages.mo and b/project/translations/en/LC_MESSAGES/messages.mo differ diff --git a/project/translations/en/LC_MESSAGES/messages.po b/project/translations/en/LC_MESSAGES/messages.po index bfeecd5..ee54eaf 100644 --- a/project/translations/en/LC_MESSAGES/messages.po +++ b/project/translations/en/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-10-14 10:41+0200\n" +"POT-Creation-Date: 2021-10-14 14:32+0200\n" "PO-Revision-Date: 2021-04-30 15:04+0200\n" "Last-Translator: FULL NAME \n" "Language: en\n" @@ -148,11 +148,11 @@ msgstr "Profile information" #: project/i10n.py:45 msgid "Scope_user:read" -msgstr "" +msgstr "Read user settings" #: project/i10n.py:46 msgid "Scope_user:write" -msgstr "" +msgstr "Create, update and delete user settings" #: project/i10n.py:47 msgid "Scope_organizer:write" @@ -2018,15 +2018,19 @@ msgstr "" msgid "Short name is already taken" msgstr "" -#: project/views/js.py:40 +#: project/views/js.py:43 +msgid "Name is already taken" +msgstr "" + +#: project/views/js.py:57 msgid "An account already exists with this email." msgstr "" -#: project/views/js.py:80 +#: project/views/js.py:97 msgid "Places of organization" msgstr "" -#: project/views/js.py:88 +#: project/views/js.py:105 msgid "Places of Google Maps" msgstr "" diff --git a/project/views/js.py b/project/views/js.py index 79710ff..e5ad30a 100644 --- a/project/views/js.py +++ b/project/views/js.py @@ -27,6 +27,23 @@ def js_check_org_short_name(): return jsonify(error) +@app.route("/js/check/organization/name", methods=["POST"]) +def js_check_org_name(): + csrf.protect() + + name = request.form["name"] + admin_unit_id = ( + int(request.form["admin_unit_id"]) if "admin_unit_id" in request.form else -1 + ) + organization = AdminUnit.query.filter(AdminUnit.name == name).first() + + if not organization or organization.id == admin_unit_id: + return jsonify(True) + + error = gettext("Name is already taken") + return jsonify(error) + + @app.route("/js/check/register/email", methods=["POST"]) def js_check_register_email(): csrf.protect() diff --git a/tests/views/test_js.py b/tests/views/test_js.py index 97a6628..4deab54 100644 --- a/tests/views/test_js.py +++ b/tests/views/test_js.py @@ -41,6 +41,45 @@ def test_js_check_org_short_name_exists(client, seeder, utils): assert response.json == "Der Kurzname ist bereits vergeben" +def test_js_check_org_name(client, seeder, utils): + seeder.create_user(admin=True) + utils.login() + + url = utils.get_url("admin_unit_create") + response = utils.get(url) + + with client: + url = utils.get_url("js_check_org_name") + response = utils.post_form_data( + url, + { + "name": "Meine Crew", + }, + ) + utils.assert_response_ok(response) + assert response.json + + +def test_js_check_org_name_exists(client, seeder, utils): + seeder.create_user(admin=True) + user_id = utils.login() + seeder.create_admin_unit(user_id, "Meine Crew") + + url = utils.get_url("admin_unit_create") + response = utils.get(url) + + with client: + url = utils.get_url("js_check_org_name") + response = utils.post_form_data( + url, + { + "name": "Meine Crew", + }, + ) + utils.assert_response_ok(response) + assert response.json == "Der Name ist bereits vergeben" + + def test_js_js_check_register_email(client, seeder, utils): url = utils.get_url("security.register") response = utils.get(url)