forked from Github-Mirrors/canaille
refactor: profile button action renaming
This commit is contained in:
parent
267dbe15e4
commit
9940a98188
6 changed files with 33 additions and 25 deletions
|
@ -527,7 +527,7 @@ def profile_settings(user, edited_user):
|
|||
|
||||
if (
|
||||
request.method == "GET"
|
||||
or request.form.get("action") == "edit"
|
||||
or request.form.get("action") == "edit-settings"
|
||||
or request_is_htmx()
|
||||
):
|
||||
return profile_settings_edit(user, edited_user)
|
||||
|
@ -630,7 +630,11 @@ def profile_settings_edit(editor, edited_user):
|
|||
)
|
||||
form.process(CombinedMultiDict((request.files, request.form)) or None, data=data)
|
||||
|
||||
if request.form and request.form.get("action") == "edit" or request_is_htmx():
|
||||
if (
|
||||
request.form
|
||||
and request.form.get("action") == "edit-settings"
|
||||
or request_is_htmx()
|
||||
):
|
||||
if not form.validate():
|
||||
flash(_("Profile edition failed."), "error")
|
||||
|
||||
|
@ -642,7 +646,7 @@ def profile_settings_edit(editor, edited_user):
|
|||
if (
|
||||
"password1" in request.form
|
||||
and form["password1"].data
|
||||
and request.form["action"] == "edit"
|
||||
and request.form["action"] == "edit-settings"
|
||||
):
|
||||
edited_user.set_password(form["password1"].data)
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@
|
|||
|
||||
<div class="ui right aligned container">
|
||||
<div class="ui stackable buttons">
|
||||
<button type="submit" class="ui right floated primary button" name="action" value="edit" id="edit">
|
||||
<button type="submit" class="ui right floated primary button" name="action" value="create-profile" id="create-profile">
|
||||
{{ _("Submit") }}
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -162,7 +162,7 @@
|
|||
|
||||
<div class="ui right aligned container">
|
||||
<div class="ui stackable buttons">
|
||||
<button type="submit" class="ui right floated primary button" name="action" value="edit" id="edit">
|
||||
<button type="submit" class="ui right floated primary button" name="action" value="edit-profile" id="edit-profile">
|
||||
{{ _("Edit") }}
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -161,7 +161,7 @@
|
|||
</a>
|
||||
{% endif %}
|
||||
|
||||
<button type="submit" class="ui right floated primary button" name="action" value="edit" id="edit">
|
||||
<button type="submit" class="ui right floated primary button" name="action" value="edit-settings" id="edit-settings">
|
||||
{{ _("Edit") }}
|
||||
</button>
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ def test_user_creation_edition_and_deletion(
|
|||
res.form["password2"] = "totoyolo"
|
||||
|
||||
# User have been created
|
||||
res = res.form.submit(name="action", value="edit", status=302)
|
||||
res = res.form.submit(name="action", value="create-profile", status=302)
|
||||
assert ("success", "User account creation succeed.") in res.flashes
|
||||
res = res.follow(status=200)
|
||||
george = models.User.get_from_login("george")
|
||||
|
@ -39,11 +39,11 @@ def test_user_creation_edition_and_deletion(
|
|||
# User have been edited
|
||||
res = testclient.get("/profile/george", status=200)
|
||||
res.form["given_name"] = "Georgio"
|
||||
res = res.form.submit(name="action", value="edit").follow()
|
||||
res = res.form.submit(name="action", value="edit-profile").follow()
|
||||
|
||||
res = testclient.get("/profile/george/settings", status=200)
|
||||
res.form["groups"] = [foo_group.id, bar_group.id]
|
||||
res = res.form.submit(name="action", value="edit").follow()
|
||||
res = res.form.submit(name="action", value="edit-settings").follow()
|
||||
|
||||
george = models.User.get_from_login("george")
|
||||
assert "Georgio" == george.given_name[0]
|
||||
|
@ -88,7 +88,7 @@ def test_user_creation_without_password(testclient, logged_moderator):
|
|||
res.form["family_name"] = "Abitbol"
|
||||
res.form["emails-0"] = "george@abitbol.com"
|
||||
|
||||
res = res.form.submit(name="action", value="edit", status=302)
|
||||
res = res.form.submit(name="action", value="create-profile", status=302)
|
||||
assert ("success", "User account creation succeed.") in res.flashes
|
||||
res = res.follow(status=200)
|
||||
george = models.User.get_from_login("george")
|
||||
|
@ -106,7 +106,7 @@ def test_user_creation_form_validation_failed(
|
|||
res.mustcontain(no="george")
|
||||
|
||||
res = testclient.get("/profile", status=200)
|
||||
res = res.form.submit(name="action", value="edit")
|
||||
res = res.form.submit(name="action", value="create-profile")
|
||||
assert ("error", "User account creation failed.") in res.flashes
|
||||
assert models.User.get_from_login("george") is None
|
||||
|
||||
|
@ -118,7 +118,7 @@ def test_username_already_taken(
|
|||
res.form["user_name"] = "user"
|
||||
res.form["family_name"] = "foo"
|
||||
res.form["emails-0"] = "any@thing.com"
|
||||
res = res.form.submit(name="action", value="edit")
|
||||
res = res.form.submit(name="action", value="create-profile")
|
||||
assert ("error", "User account creation failed.") in res.flashes
|
||||
res.mustcontain("The login 'user' already exists")
|
||||
|
||||
|
@ -128,7 +128,7 @@ def test_email_already_taken(testclient, logged_moderator, user, foo_group, bar_
|
|||
res.form["user_name"] = "user2"
|
||||
res.form["family_name"] = "foo"
|
||||
res.form["emails-0"] = "john@doe.com"
|
||||
res = res.form.submit(name="action", value="edit")
|
||||
res = res.form.submit(name="action", value="create-profile")
|
||||
assert ("error", "User account creation failed.") in res.flashes
|
||||
res.mustcontain("The email 'john@doe.com' is already used")
|
||||
|
||||
|
@ -140,7 +140,9 @@ def test_cn_setting_with_given_name_and_surname(testclient, logged_moderator):
|
|||
res.form["family_name"] = "Abitbol"
|
||||
res.form["emails-0"] = "george@abitbol.com"
|
||||
|
||||
res = res.form.submit(name="action", value="edit", status=302).follow(status=200)
|
||||
res = res.form.submit(name="action", value="create-profile", status=302).follow(
|
||||
status=200
|
||||
)
|
||||
|
||||
george = models.User.get_from_login("george")
|
||||
assert george.formatted_name[0] == "George Abitbol"
|
||||
|
@ -153,7 +155,9 @@ def test_cn_setting_with_surname_only(testclient, logged_moderator):
|
|||
res.form["family_name"] = "Abitbol"
|
||||
res.form["emails-0"] = "george@abitbol.com"
|
||||
|
||||
res = res.form.submit(name="action", value="edit", status=302).follow(status=200)
|
||||
res = res.form.submit(name="action", value="create-profile", status=302).follow(
|
||||
status=200
|
||||
)
|
||||
|
||||
george = models.User.get_from_login("george")
|
||||
assert george.formatted_name[0] == "Abitbol"
|
||||
|
|
|
@ -23,7 +23,7 @@ def test_edition(
|
|||
assert "readonly" in res.form["user_name"].attrs
|
||||
|
||||
res.form["user_name"] = "toto"
|
||||
res = res.form.submit(name="action", value="edit")
|
||||
res = res.form.submit(name="action", value="edit-settings")
|
||||
assert res.flashes == [("error", "Profile edition failed.")]
|
||||
logged_user.reload()
|
||||
|
||||
|
@ -65,7 +65,7 @@ def test_edition_without_groups(
|
|||
res = testclient.get("/profile/user/settings", status=200)
|
||||
testclient.app.config["ACL"]["DEFAULT"]["READ"] = []
|
||||
|
||||
res = res.form.submit(name="action", value="edit")
|
||||
res = res.form.submit(name="action", value="edit-settings")
|
||||
assert res.flashes == [("success", "Profile updated successfully.")]
|
||||
res = res.follow()
|
||||
|
||||
|
@ -84,7 +84,7 @@ def test_password_change(testclient, logged_user):
|
|||
res.form["password1"] = "new_password"
|
||||
res.form["password2"] = "new_password"
|
||||
|
||||
res = res.form.submit(name="action", value="edit").follow()
|
||||
res = res.form.submit(name="action", value="edit-settings").follow()
|
||||
|
||||
logged_user.reload()
|
||||
assert logged_user.check_password("new_password")[0]
|
||||
|
@ -94,7 +94,7 @@ def test_password_change(testclient, logged_user):
|
|||
res.form["password1"] = "correct horse battery staple"
|
||||
res.form["password2"] = "correct horse battery staple"
|
||||
|
||||
res = res.form.submit(name="action", value="edit")
|
||||
res = res.form.submit(name="action", value="edit-settings")
|
||||
assert ("success", "Profile updated successfully.") in res.flashes
|
||||
res = res.follow()
|
||||
|
||||
|
@ -108,7 +108,7 @@ def test_password_change_fail(testclient, logged_user):
|
|||
res.form["password1"] = "new_password"
|
||||
res.form["password2"] = "other_password"
|
||||
|
||||
res = res.form.submit(name="action", value="edit", status=200)
|
||||
res = res.form.submit(name="action", value="edit-settings", status=200)
|
||||
|
||||
logged_user.reload()
|
||||
assert logged_user.check_password("correct horse battery staple")[0]
|
||||
|
@ -118,7 +118,7 @@ def test_password_change_fail(testclient, logged_user):
|
|||
res.form["password1"] = "new_password"
|
||||
res.form["password2"] = ""
|
||||
|
||||
res = res.form.submit(name="action", value="edit", status=200)
|
||||
res = res.form.submit(name="action", value="edit-settings", status=200)
|
||||
|
||||
logged_user.reload()
|
||||
assert logged_user.check_password("correct horse battery staple")[0]
|
||||
|
@ -347,7 +347,7 @@ def test_past_lock_date(
|
|||
second=0, microsecond=0
|
||||
) - datetime.timedelta(days=30)
|
||||
res.form["lock_date"] = expiration_datetime.strftime("%Y-%m-%d %H:%M")
|
||||
res = res.form.submit(name="action", value="edit")
|
||||
res = res.form.submit(name="action", value="edit-settings")
|
||||
assert res.flashes == [("success", "Profile updated successfully.")]
|
||||
|
||||
res = res.follow()
|
||||
|
@ -370,7 +370,7 @@ def test_future_lock_date(
|
|||
second=0, microsecond=0
|
||||
) + datetime.timedelta(days=30)
|
||||
res.form["lock_date"] = expiration_datetime.strftime("%Y-%m-%d %H:%M")
|
||||
res = res.form.submit(name="action", value="edit")
|
||||
res = res.form.submit(name="action", value="edit-settings")
|
||||
assert res.flashes == [("success", "Profile updated successfully.")]
|
||||
|
||||
res = res.follow()
|
||||
|
@ -394,7 +394,7 @@ def test_empty_lock_date(
|
|||
|
||||
res = testclient.get("/profile/user/settings", status=200)
|
||||
res.form["lock_date"] = ""
|
||||
res = res.form.submit(name="action", value="edit")
|
||||
res = res.form.submit(name="action", value="edit-settings")
|
||||
assert res.flashes == [("success", "Profile updated successfully.")]
|
||||
|
||||
res = res.follow()
|
||||
|
@ -416,7 +416,7 @@ def test_account_limit_values(
|
|||
microsecond=0, tzinfo=datetime.timezone.utc
|
||||
)
|
||||
res.form["lock_date"] = expiration_datetime.strftime("%Y-%m-%d %H:%M:%S")
|
||||
res = res.form.submit(name="action", value="edit")
|
||||
res = res.form.submit(name="action", value="edit-settings")
|
||||
assert res.flashes == [("success", "Profile updated successfully.")]
|
||||
|
||||
res = res.follow()
|
||||
|
|
Loading…
Reference in a new issue