Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
name: trim trailing whitespace
Expand Down Expand Up @@ -65,7 +65,7 @@ repos:

# Versioning: Commit messages & changelog
- repo: https://github.com/commitizen-tools/commitizen
rev: v4.6.1
rev: v4.16.3
hooks:
- id: commitizen
stages: [commit-msg]
Expand Down Expand Up @@ -105,15 +105,15 @@ repos:
# "!backend/tests/test_data/**",
# ]

- repo: https://github.com/psf/black
rev: 25.1.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 26.5.1
hooks:
- id: black
language_version: python3.10


- repo: https://github.com/PyCQA/flake8
rev: "7.2.0"
rev: "7.3.0"
hooks:
- id: flake8
name: flake8
Expand Down
1 change: 0 additions & 1 deletion backend/api/users/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from typing import Optional


router = APIRouter(
prefix="/users",
tags=["users"],
Expand Down
4 changes: 3 additions & 1 deletion backend/services/messaging/message_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,10 @@ async def send_team_join_notification(
team_link = MessageService.get_team_link(team_name, team_id, False)
user_link = MessageService.get_user_link(from_username)
message.subject = f"You have been added to team {team_link}"
message.message = f"You have been added to the team {team_link} as {role} by {user_link}.\
message.message = (
f"You have been added to the team {team_link} as {role} by {user_link}.\
Access the {team_link}'s page to view more info about this team."
)
message.date = timestamp()
message.read = False
user = await UserService.get_user_by_id(to_user, db)
Expand Down
22 changes: 6 additions & 16 deletions backend/services/project_search_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,26 +458,20 @@ async def _filter_projects(
tsquery_search = " & ".join([x for x in search_text.split(" ") if x])
ilike_search = f"%{search_text}%"

subquery_filters.append(
"""
subquery_filters.append("""
text_searchable @@ to_tsquery('english', :tsquery_search)
OR name ILIKE :text_search
"""
)
""")
params["tsquery_search"] = tsquery_search
params["text_search"] = ilike_search

filters.append(
"""
filters.append("""
p.id = ANY(
SELECT project_id
FROM project_info
WHERE {}
)
""".format(
" AND ".join(subquery_filters)
)
)
""".format(" AND ".join(subquery_filters)))

if search_dto.project_statuses:
statuses = [
Expand Down Expand Up @@ -697,17 +691,13 @@ async def _filter_projects(
)
params["partnership_to"] = partnership_to

filters.append(
"""
filters.append("""
p.id = ANY(
SELECT pp.project_id
FROM project_partnerships pp
WHERE {}
)
""".format(
" AND ".join(partner_conditions)
)
)
""".format(" AND ".join(partner_conditions)))

if search_dto.managed_by and user.role != UserRole.ADMIN.value:
project_ids = await ProjectSearchService.get_managed_projects(user.id, db)
Expand Down
18 changes: 6 additions & 12 deletions backend/services/stats_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,42 +755,36 @@ async def get_task_stats(
values["org_id"] = int(org_id)

if org_name:
filters.append(
"""
filters.append("""
AND organisation_id = (
SELECT id FROM organisations WHERE name = :org_name
)
"""
)
""")
values["org_name"] = org_name

if campaign:
filters.append(
"""
filters.append("""
AND id IN (
SELECT project_id FROM campaign_projects
WHERE campaign_id = (
SELECT id FROM campaigns WHERE name = :campaign
)
)
"""
)
""")
values["campaign"] = campaign

if project_id:
filters.append("AND id = ANY(:project_id)")
values["project_id"] = project_id

if country:
filters.append(
"""
filters.append("""
AND EXISTS (
SELECT 1
FROM unnest(country) AS c
WHERE c ILIKE :country
)
"""
)
""")
values["country"] = f"%{country}%"

final_query = base_query.format(filters=" ".join(filters))
Expand Down
6 changes: 2 additions & 4 deletions migrations/versions/451f6bd05a19_.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

def upgrade():
op.execute("DROP TRIGGER IF EXISTS tsvectorupdate ON project_info;")
op.execute(
"""
op.execute("""
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON project_info FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger(text_searchable, "pg_catalog.english", project_id_str, short_description, description)
"""
)
""")


def downgrade():
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/763165f937cf_.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "763165f937cf"
down_revision = "4489b9e235f8"
Expand Down
12 changes: 2 additions & 10 deletions migrations/versions/7bbc01082457_.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,9 @@ def upgrade():

if mapped_org not in orgs_inserted:
org_managers[mapped_org] = org_manager
conn.execute(
sa.text(
"insert into organisation_managers \
conn.execute(sa.text("insert into organisation_managers \
(organisation_id,user_id) \
values("
+ org_id
+ ","
+ org_manager
+ ")"
)
)
values(" + org_id + "," + org_manager + ")"))
print(
str(count)
+ "/"
Expand Down
20 changes: 6 additions & 14 deletions migrations/versions/909c5b13b1fc_.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,28 @@

def upgrade():
conn = op.get_bind()
cur = conn.execute(
sa.text(
"""
cur = conn.execute(sa.text("""
INSERT INTO mapping_badges (name, description, requirements, is_enabled, is_internal)
VALUES
('INTERMEDIATE_internal', '', '{\"changeset\": 250}', true, true),
('ADVANCED_internal', '', '{\"changeset\": 500}', true, true)
RETURNING id
"""
)
)
"""))
ids = [r[0] for r in cur.fetchall()]

conn.execute(
sa.text(
"""
sa.text("""
INSERT INTO mapping_level_badges (level_id, badge_id)
VALUES (:level_id, :badge_id)
"""
),
"""),
{"level_id": 2, "badge_id": ids[0]},
)

conn.execute(
sa.text(
"""
sa.text("""
INSERT INTO mapping_level_badges (level_id, badge_id)
VALUES (:level_id, :badge_id)
"""
),
"""),
{"level_id": 3, "badge_id": ids[1]},
)

Expand Down
1 change: 0 additions & 1 deletion migrations/versions/b720f42ce3e8_.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "b720f42ce3e8"
down_revision = "763165f937cf"
Expand Down
6 changes: 2 additions & 4 deletions scripts/commands/refresh_mapper_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,14 @@ async def _fetch_users_only_missing(conn) -> List[SimpleNamespace]:
"""
Return lightweight objects (id, username) for users missing user_stats entries.
"""
users = await conn.fetch_all(
query="""
users = await conn.fetch_all(query="""
SELECT u.id, u.username
FROM users u
WHERE NOT EXISTS (
SELECT 1 FROM user_stats s WHERE s.user_id = u.id
)
ORDER BY u.id
"""
)
""")
return users


Expand Down
24 changes: 6 additions & 18 deletions tests/api/helpers/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,20 @@ async def create_mapping_levels(db):
# Ensure clean slate (important for repeated test runs)
await db.execute(sa.text("DELETE FROM mapping_levels"))

await db.execute(
sa.text(
"""
await db.execute(sa.text("""
INSERT INTO mapping_levels (id, name, ordering, is_beginner, approvals_required)
VALUES (1, 'BEGINNER', 1, true, 0)
"""
)
)
"""))

await db.execute(
sa.text(
"""
await db.execute(sa.text("""
INSERT INTO mapping_levels (id, name, ordering, is_beginner, approvals_required)
VALUES (2, 'INTERMEDIATE', 2, false, 0)
"""
)
)
"""))

await db.execute(
sa.text(
"""
await db.execute(sa.text("""
INSERT INTO mapping_levels (id, name, ordering, is_beginner, approvals_required)
VALUES (3, 'ADVANCED', 3, false, 0)
"""
)
)
"""))


def get_canned_osm_user_details():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
TEST_USERNAME,
)


TEST_USER_EMAIL = "thinkwheretest@test.com"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from backend.models.postgis.message import Message
from backend.services.messaging.message_service import MessageService


MESSAGE_TYPES = "3,2,1"
TEST_USER_ID = 111111111

Expand Down
Loading