-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #351 from scidsg/contact-method
Add optional contact method field
- Loading branch information
Showing
9 changed files
with
209 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
// Handle message deletion confirmation | ||
document.getElementById('deleteMessageButton')?.addEventListener('click', function(event) { | ||
const confirmed = confirm('Are you sure you want to delete this message? This cannot be undone.'); | ||
if (!confirmed) { | ||
event.preventDefault(); | ||
// Listen for clicks anywhere in the document | ||
document.addEventListener('click', function(event) { | ||
// Check if the clicked element or its parents have the 'btn-danger' class | ||
let targetElement = event.target; | ||
while (targetElement != null) { | ||
if (targetElement.classList && targetElement.classList.contains('btn-danger')) { | ||
// Confirm before deletion | ||
const confirmed = confirm('Are you sure you want to delete this message? This cannot be undone.'); | ||
if (!confirmed) { | ||
event.preventDefault(); | ||
} | ||
return; // Exit the loop and function after handling the click | ||
} | ||
targetElement = targetElement.parentElement; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""empty message | ||
Revision ID: 2e5a6b20908d | ||
Revises: cab44a7264a5 | ||
Create Date: 2024-05-24 19:57:36.878591 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "2e5a6b20908d" | ||
down_revision = "cab44a7264a5" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("message", schema=None) as batch_op: | ||
batch_op.add_column(sa.Column("contact_method", sa.String(length=255), nullable=True)) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("message", schema=None) as batch_op: | ||
batch_op.drop_column("contact_method") | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""empty message | ||
Revision ID: 73306df7f74c | ||
Revises: 2e5a6b20908d | ||
Create Date: 2024-05-25 01:04:44.495978 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "73306df7f74c" | ||
down_revision = "2e5a6b20908d" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("message", schema=None) as batch_op: | ||
batch_op.drop_column("contact_method") | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("message", schema=None) as batch_op: | ||
batch_op.add_column(sa.Column("contact_method", sa.VARCHAR(length=255), nullable=True)) | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""empty message | ||
Revision ID: cab44a7264a5 | ||
Revises: 9803e4dcb0a6 | ||
Create Date: 2024-05-24 19:55:09.067118 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "cab44a7264a5" | ||
down_revision = "9803e4dcb0a6" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
pass | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
pass | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,46 @@ def test_submit_message(client): | |
|
||
# Assert that the submitted message is displayed in the inbox | ||
assert b"This is a test message." in response.data | ||
|
||
|
||
def test_submit_message_with_contact_method(client): | ||
# Register a user | ||
user = register_user(client, "test_user_concat", "Secure-Test-Pass123") | ||
assert user is not None | ||
|
||
# Log in the user | ||
login_success = login_user(client, "test_user_concat", "Secure-Test-Pass123") | ||
assert login_success | ||
|
||
# Prepare the message and contact method data | ||
message_content = "This is a test message." | ||
contact_method = "[email protected]" | ||
message_data = { | ||
"content": message_content, | ||
"contact_method": contact_method, | ||
"client_side_encrypted": "false", # Simulate that this is not client-side encrypted | ||
} | ||
|
||
# Send a POST request to submit the message | ||
response = client.post( | ||
f"/submit_message/{user.primary_username}", | ||
data=message_data, | ||
follow_redirects=True, | ||
) | ||
|
||
# Assert that the response status code is 200 (OK) | ||
assert response.status_code == 200 | ||
assert b"Message submitted successfully." in response.data | ||
|
||
# Verify that the message is saved in the database | ||
message = Message.query.filter_by(user_id=user.id).first() | ||
assert message is not None | ||
|
||
# Check if the message content includes the concatenated contact method | ||
expected_content = f"Contact Method: {contact_method}\n\n{message_content}" | ||
assert message.content == expected_content | ||
|
||
# Navigate to the inbox to check if the message displays correctly | ||
response = client.get(f"/inbox?username={user.primary_username}", follow_redirects=True) | ||
assert response.status_code == 200 | ||
assert expected_content.encode() in response.data |