in backend/services/project_search_service.py [0:0]
def create_search_query(user=None):
query = (
db.session.query(
Project.id.label("id"),
Project.mapper_level,
Project.priority,
Project.default_locale,
Project.centroid.ST_AsGeoJSON().label("centroid"),
Project.organisation_id,
Project.tasks_bad_imagery,
Project.tasks_mapped,
Project.tasks_validated,
Project.status,
Project.total_tasks,
Project.last_updated,
Project.due_date,
Project.country,
Organisation.name.label("organisation_name"),
Organisation.logo.label("organisation_logo"),
)
.filter(Project.geometry is not None)
.outerjoin(Organisation, Organisation.id == Project.organisation_id)
.group_by(Organisation.id, Project.id)
)
# Get public projects only for anonymous user.
if user is None:
query = query.filter(Project.private.is_(False))
if user is not None and user.role != UserRole.ADMIN.value:
# Get also private projects of teams that the user is member.
project_ids = [[p.project_id for p in t.team.projects] for t in user.teams]
# Get projects that belong to user organizations.
orgs_projects_ids = [[p.id for p in u.projects] for u in user.organisations]
project_ids.extend(orgs_projects_ids)
project_ids = tuple(
set([item for sublist in project_ids for item in sublist])
)
query = query.filter(
or_(Project.private.is_(False), Project.id.in_(project_ids))
)
# If the user is admin, no filter.
return query