Skip to content

Commit

Permalink
refactor: profile button action renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Jul 30, 2023
1 parent 267dbe1 commit 9940a98
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
10 changes: 7 additions & 3 deletions canaille/core/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion canaille/templates/profile_add.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ <h4 class="ui dividing header">{% trans %}Account settings{% endtrans %}</h4>

<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>
Expand Down
2 changes: 1 addition & 1 deletion canaille/templates/profile_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h2 class="ui center aligned header">

<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>
Expand Down
2 changes: 1 addition & 1 deletion canaille/templates/profile_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ <h2 class="ui center aligned header">
</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>

Expand Down
22 changes: 13 additions & 9 deletions tests/core/test_profile_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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]
Expand Down Expand Up @@ -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")
Expand All @@ -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

Expand All @@ -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 &#39;user&#39; already exists")

Expand All @@ -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 &#39;john@doe.com&#39; is already used")

Expand All @@ -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"
Expand All @@ -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"
Expand Down
20 changes: 10 additions & 10 deletions tests/core/test_profile_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand All @@ -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]
Expand All @@ -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()

Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 9940a98

Please sign in to comment.