Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aapeliv committed Sep 8, 2024
1 parent 215da15 commit 1f22e6c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 89 deletions.
2 changes: 1 addition & 1 deletion app/backend/src/couchers/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@
NEED_TO_SPECIFY_AT_LEAST_ONE_USER = "You need to specify at least one user."
NO_MULTIPOLYGON = "GeoJson was not of type MultiPolygon."
NO_PENDING_VERIFICATION = "No phone number to verify."
NOT_DONATED = "Please complete donation to get phone verified."
NO_RECIPIENTS = "No recipients."
NODE_MODERATE_PERMISSION_DENIED = "You're not allowed to moderate that community"
NOT_DONATED = "Please complete donation to get phone verified."
NOT_IN_COMMUNITY = "You're not in that community."
NOT_IN_GROUP = "You're not in that group."
NOT_THE_HOST = "You are not the host of this request."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,8 @@


def upgrade():
op.create_table(
"phone_verification_callback_events",
sa.Column("id", sa.BigInteger(), nullable=False),
sa.Column("verification_attempt_token", sa.String(), nullable=False),
sa.Column(
"status",
sa.Enum(
"succeeded",
"in_progress_waiting_on_user_to_open_app",
"in_progress_waiting_on_user_in_app",
"in_progress_waiting_on_backend",
"failed",
"deleted",
name="strongverificationattemptstatus",
),
nullable=False,
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_phone_verification_callback_events")),
sa.UniqueConstraint(
"verification_attempt_token", name=op.f("uq_phone_verification_callback_events_verification_attempt_token")
),
)
op.add_column("users", sa.Column("has_donated", sa.Boolean(), server_default=sa.text("false"), nullable=False))

op.execute("UPDATE USERS SET has_donated = true WHERE id IN (SELECT user_id FROM invoices)")

def downgrade():
op.drop_column("users", "has_donated")
op.drop_table("phone_verification_callback_events")
1 change: 1 addition & 0 deletions app/backend/src/couchers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class User(Base):
things_i_like = Column(String, nullable=True) # CommonMark without images
about_place = Column(String, nullable=True) # CommonMark without images
additional_information = Column(String, nullable=True) # CommonMark without images

is_banned = Column(Boolean, nullable=False, server_default=text("false"))
is_deleted = Column(Boolean, nullable=False, server_default=text("false"))
is_superuser = Column(Boolean, nullable=False, server_default=text("false"))
Expand Down
7 changes: 1 addition & 6 deletions app/backend/src/tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def db():
recreate_database()


def generate_user(*, delete_user=False, complete_profile=False, has_donated=True, **kwargs):
def generate_user(*, delete_user=False, complete_profile=False, **kwargs):
"""
Create a new user, return session token
Expand Down Expand Up @@ -304,11 +304,6 @@ def invocation_metadata(self):

session.commit()

# if has_donated:
# user.has_donated = True
#
# assert user.has_donated == has_donated

assert user.has_completed_profile == complete_profile

# refresh it, undoes the expiry
Expand Down
72 changes: 16 additions & 56 deletions app/media/src/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import pytest
from google.protobuf import empty_pb2
from google.protobuf.timestamp_pb2 import Timestamp
from media.server import create_app
from nacl.bindings.crypto_generichash import generichash_blake2b_salt_personal
from nacl.utils import random as random_bytes
from PIL import Image
from PIL.JpegImagePlugin import JpegImageFile

from media.server import create_app
from proto import media_pb2, media_pb2_grpc

DATADIR = Path(__file__).parent / "data"
Expand Down Expand Up @@ -94,9 +95,7 @@ def generate_hash_signature(message: bytes, key: bytes) -> bytes:
def generate_upload_path(request, media_server_secret_key):
req = request.SerializeToString()
data = urlsafe_b64encode(req).decode("utf8")
sig = urlsafe_b64encode(
generate_hash_signature(req, media_server_secret_key)
).decode("utf8")
sig = urlsafe_b64encode(generate_hash_signature(req, media_server_secret_key)).decode("utf8")

return "upload?" + urlencode({"data": data, "sig": sig})

Expand Down Expand Up @@ -138,10 +137,7 @@ def test_image_upload(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"


def test_image_resizing(client_with_secrets):
Expand All @@ -159,10 +155,7 @@ def test_image_resizing(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"

rv = client.get(f"/img/full/{key}.jpg")
assert rv.status_code == 200
Expand Down Expand Up @@ -190,10 +183,7 @@ def test_thumbnail_downscaling(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"

rv = client.get(f"/img/thumbnail/{key}.jpg")
assert rv.status_code == 200
Expand All @@ -219,10 +209,7 @@ def test_thumbnail_downscaling_wide(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"

rv = client.get(f"/img/thumbnail/{key}.jpg")
assert rv.status_code == 200
Expand All @@ -248,10 +235,7 @@ def test_thumbnail_downscaling_tall(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"

rv = client.get(f"/img/thumbnail/{key}.jpg")
assert rv.status_code == 200
Expand All @@ -277,10 +261,7 @@ def test_thumbnail_upscaling(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"

rv = client.get(f"/img/thumbnail/{key}.jpg")
assert rv.status_code == 200
Expand Down Expand Up @@ -335,10 +316,7 @@ def test_wrong_filename(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"

rv = client.get(f"/img/full/{key}.jpg")
assert rv.status_code == 200
Expand All @@ -365,10 +343,7 @@ def test_strips_exif(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"

rv = client.get(f"/img/full/{key}.jpg")
assert rv.status_code == 200
Expand All @@ -393,10 +368,7 @@ def test_jpg_pixel(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"

rv = client.get(f"/img/full/{key}.jpg")
assert rv.status_code == 200
Expand All @@ -419,10 +391,7 @@ def test_png_pixel(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"

rv = client.get(f"/img/full/{key}.jpg")
assert rv.status_code == 200
Expand All @@ -445,10 +414,7 @@ def test_gif_pixel(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"

rv = client.get(f"/img/full/{key}.jpg")
assert rv.status_code == 200
Expand Down Expand Up @@ -485,10 +451,7 @@ def test_cant_reuse(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"

rv = client.get(f"/img/full/{key}.jpg")
assert rv.status_code == 200
Expand Down Expand Up @@ -565,10 +528,7 @@ def test_cache_headers(client_with_secrets):
assert jd["key"] == key
assert jd["filename"] == f"{key}.jpg"
assert jd["full_url"] == f"https://testing.couchers.invalid/img/full/{key}.jpg"
assert (
jd["thumbnail_url"]
== f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"
)
assert jd["thumbnail_url"] == f"https://testing.couchers.invalid/img/thumbnail/{key}.jpg"

rv = client.get(f"/img/full/{key}.jpg")
assert rv.status_code == 200
Expand Down
4 changes: 2 additions & 2 deletions app/proto/account.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ message GetAccountInfoRes {
// the user's timezone name identifier, derived from their coordinates, for example "Australia/Melbourne"
string timezone = 6;

// strong verification info
bool has_donated = 5;
bool has_donated = 14;

// strong verification info
bool has_strong_verification = 10;
org.couchers.api.core.BirthdateVerificationStatus birthdate_verification_status = 11;
org.couchers.api.core.GenderVerificationStatus gender_verification_status = 12;
Expand Down
1 change: 1 addition & 0 deletions app/web/features/auth/email/ChangeEmail.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function setMocks({
birthdateVerificationStatus: 2,
genderVerificationStatus: 2,
doNotEmail: false,
hasDonated: false,
})
: Promise.reject(new Error("Error getting account info"));
mockedService.account.changeEmail = () =>
Expand Down
1 change: 1 addition & 0 deletions app/web/features/auth/email/ChangeEmail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const accountInfo = {
birthdateVerificationStatus: 1,
genderVerificationStatus: 3,
doNotEmail: false,
hasDonated: false,
};

describe("ChangeEmail", () => {
Expand Down

0 comments on commit 1f22e6c

Please sign in to comment.