Skip to content

Commit

Permalink
Add projects page
Browse files Browse the repository at this point in the history
  • Loading branch information
arkid15r committed Sep 10, 2024
1 parent b14b391 commit 8869f51
Show file tree
Hide file tree
Showing 20 changed files with 252 additions and 124 deletions.
1 change: 1 addition & 0 deletions backend/Dockerfile.staging
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ WORKDIR /home/owasp

COPY apps apps
COPY settings settings
COPY static static
COPY templates templates
COPY manage.py poetry.lock pyproject.toml wsgi.py ./

Expand Down
3 changes: 3 additions & 0 deletions backend/apps/github/index/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""GitHub app models index."""

from apps.github.index.issue import IssueIndex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""GitHub app index."""
"""GitHub issue index."""

from datetime import timedelta as td

Expand Down Expand Up @@ -40,7 +40,7 @@ class IssueIndex(AlgoliaIndex):
)

settings = {
"minProximity": 3,
"minProximity": 4,
"indexLanguages": ["en"],
"customRanking": [
"desc(idx_created_at)",
Expand All @@ -52,7 +52,6 @@ class IssueIndex(AlgoliaIndex):
],
"ranking": [
"typo",
"geo",
"words",
"filters",
"proximity",
Expand All @@ -61,8 +60,8 @@ class IssueIndex(AlgoliaIndex):
"custom",
],
"searchableAttributes": [
"unordered(idx_labels, idx_repository_languages)",
"unordered(idx_title, idx_project_name, idx_repository_name)",
"unordered(idx_labels, idx_repository_languages)",
"unordered(idx_project_description, idx_repository_description)",
"unordered(idx_project_tags, idx_repository_topics)",
"unordered(idx_author_login, idx_author_name)",
Expand All @@ -74,7 +73,6 @@ class IssueIndex(AlgoliaIndex):

def get_queryset(self):
"""Get queryset."""
# We index all unassigned issues and issues with no activity within 60 days.
return (
Issue.objects.select_related(
"repository",
Expand All @@ -84,8 +82,9 @@ def get_queryset(self):
"labels",
"repository__project_set",
)
# We index all unassigned issues and assigned issues with no activity within 90 days.
.filter(
Q(assignees__isnull=True)
| Q(assignees__isnull=False, updated_at__lte=timezone.now() - td(days=60))
| Q(assignees__isnull=False, updated_at__lte=timezone.now() - td(days=90))
)
)
5 changes: 5 additions & 0 deletions backend/apps/github/models/mixins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""GitHub app models mixins."""

from apps.github.models.mixins.issue import IssueIndexMixin
from apps.github.models.mixins.organization import OrganizationIndexMixin
from apps.github.models.mixins.repository import RepositoryIndexMixin
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""GitHub app models mixins."""
"""GitHub issue mixins."""

from apps.common.utils import join_values
from apps.github.constants import GITHUB_GHOST_USER_LOGIN


Expand Down Expand Up @@ -121,71 +120,3 @@ def idx_updated_at(self):
def idx_url(self):
"""Return URL for indexing."""
return self.url or None


class OrganizationIndexMixin:
"""Organization index mixin."""

@property
def idx_name(self):
"""Return name for indexing."""
return join_values((self.name, self.login))

@property
def idx_company(self):
"""Return company for indexing."""
return join_values((self.company, self.location))


class RepositoryIndexMixin:
"""Repository index mixin."""

@property
def idx_contributors_count(self):
"""Return contributors count for indexing."""
return self.contributors_count

@property
def idx_description(self):
"""Return description for indexing."""
return self.description

@property
def idx_forks_count(self):
"""Return forks count for indexing."""
return self.forks_count

@property
def idx_languages(self):
"""Return languages for indexing."""
return self.top_languages

@property
def idx_name(self):
"""Return name for indexing."""
return self.name

@property
def idx_open_issues_count(self):
"""Return open issues count for indexing."""
return self.open_issues_count

@property
def idx_pushed_at(self):
"""Return pushed at for indexing."""
return self.pushed_at

@property
def idx_stars_count(self):
"""Return stars count for indexing."""
return self.stars_count

@property
def idx_subscribers_count(self):
"""Return subscribers count for indexing."""
return self.stars_count

@property
def idx_topics(self):
"""Return topics for indexing."""
return self.topics
17 changes: 17 additions & 0 deletions backend/apps/github/models/mixins/organization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""GitHub organization mixins."""

from apps.common.utils import join_values


class OrganizationIndexMixin:
"""Organization index mixin."""

@property
def idx_name(self):
"""Return name for indexing."""
return join_values((self.name, self.login))

@property
def idx_company(self):
"""Return company for indexing."""
return join_values((self.company, self.location))
55 changes: 55 additions & 0 deletions backend/apps/github/models/mixins/repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""GitHub repository mixins."""


class RepositoryIndexMixin:
"""Repository index mixin."""

@property
def idx_contributors_count(self):
"""Return contributors count for indexing."""
return self.contributors_count

@property
def idx_description(self):
"""Return description for indexing."""
return self.description

@property
def idx_forks_count(self):
"""Return forks count for indexing."""
return self.forks_count

@property
def idx_languages(self):
"""Return languages for indexing."""
return self.top_languages

@property
def idx_name(self):
"""Return name for indexing."""
return self.name

@property
def idx_open_issues_count(self):
"""Return open issues count for indexing."""
return self.open_issues_count

@property
def idx_pushed_at(self):
"""Return pushed at for indexing."""
return self.pushed_at

@property
def idx_stars_count(self):
"""Return stars count for indexing."""
return self.stars_count

@property
def idx_subscribers_count(self):
"""Return subscribers count for indexing."""
return self.stars_count

@property
def idx_topics(self):
"""Return topics for indexing."""
return self.topics
1 change: 0 additions & 1 deletion backend/apps/owasp/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
from apps.owasp.api.committee import CommitteeViewSet
from apps.owasp.api.event import EventViewSet
from apps.owasp.api.project import ProjectViewSet
from apps.owasp.api.search import search_project
4 changes: 4 additions & 0 deletions backend/apps/owasp/api/search/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""OWASP app search API."""

from apps.owasp.api.search.issue import project_issues
from apps.owasp.api.search.project import projects
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""OWASP app search views."""
"""OWASP app issue search API."""

from algoliasearch_django import raw_search
from django.http import JsonResponse

from apps.github.models import Issue


def search_project(request):
"""Search project view."""
def project_issues(request):
"""Search project issues view."""
issues_params = {
"attributesToRetrieve": [
"idx_created_at",
Expand All @@ -16,9 +16,10 @@ def search_project(request):
"idx_title",
"idx_url",
],
"hitsPerPage": 100,
"hitsPerPage": 25,
}

issues = raw_search(Issue, request.GET.get("q", ""), issues_params)["hits"]

return JsonResponse(issues, safe=False)
return JsonResponse(
raw_search(Issue, request.GET.get("q", ""), issues_params)["hits"],
safe=False,
)
23 changes: 23 additions & 0 deletions backend/apps/owasp/api/search/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""OWASP app project search API."""

from algoliasearch_django import raw_search
from django.http import JsonResponse

from apps.owasp.models import Project


def projects(request):
"""Search projects view."""
params = {
"attributesToRetrieve": [
"idx_name",
"idx_topics",
"idx_url",
],
"hitsPerPage": 25,
}

return JsonResponse(
raw_search(Project, request.GET.get("q", ""), params)["hits"],
safe=False,
)
3 changes: 3 additions & 0 deletions backend/apps/owasp/index/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""OWASP app models index."""

from apps.owasp.index.project import ProjectIndex
39 changes: 28 additions & 11 deletions backend/apps/owasp/index.py → backend/apps/owasp/index/project.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""OWASP app index."""
"""OWASP app project index."""

from algoliasearch_django import AlgoliaIndex
from algoliasearch_django.decorators import register
Expand All @@ -13,6 +13,7 @@ class ProjectIndex(AlgoliaIndex):
index_name = "projects"

fields = (
"idx_companies",
"idx_contributors_count",
"idx_description",
"idx_forks_count",
Expand All @@ -21,30 +22,46 @@ class ProjectIndex(AlgoliaIndex):
"idx_level",
"idx_name",
"idx_organizations",
"idx_companies",
"idx_stars_count",
"idx_tags",
"idx_topics",
"idx_type",
"idx_updated_at",
"idx_url",
)

settings = {
"minProximity": 4,
"indexLanguages": ["en"],
"customRanking": [
"desc(idx_level)",
"desc(idx_stars_count)",
"desc(idx_forks_count)",
"desc(idx_contributors_count)",
"desc(idx_forks_count)",
"desc(idx_updated_at)",
],
"ranking": [
"typo",
"words",
"filters",
"proximity",
"attribute",
"exact",
"custom",
],
"searchableAttributes": [
"idx_description",
"idx_languages",
"idx_leaders",
"idx_name",
"idx_organizations",
"idx_companies",
"idx_tags",
"idx_topics",
"unordered(idx_name)",
"unordered(idx_tags, idx_topics, idx_languages)",
"unordered(idx_description)",
"unordered(idx_companies, idx_leaders, idx_organizations)",
],
}

should_index = "is_indexable"

def get_queryset(self):
"""Get queryset."""
return Project.objects.prefetch_related(
"organizations",
"repositories",
)
3 changes: 3 additions & 0 deletions backend/apps/owasp/models/mixins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""OWASP app models mixins."""

from apps.owasp.models.mixins.project import ProjectIndexMixin
Loading

0 comments on commit 8869f51

Please sign in to comment.