Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made Inactive and archived entities to indexable #422

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions backend/apps/github/index/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ class RepositoryIndex(AlgoliaIndex, IndexBase):
"idx_subscribers_count",
"idx_top_contributors",
"idx_topics",
"idx_is_archived",
)

settings = {
"minProximity": 4,
"customRanking": [
"asc(idx_is_archived)",
"desc(idx_stars_count)",
"desc(idx_forks_count)",
"desc(idx_pushed_at)",
Expand Down
5 changes: 5 additions & 0 deletions backend/apps/github/models/mixins/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,8 @@ def idx_top_contributors(self):
def idx_topics(self):
"""Return topics for indexing."""
return self.topics

@property
def idx_is_archived(self):
"""Return URL for indexing."""
return self.is_archived
7 changes: 1 addition & 6 deletions backend/apps/github/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,7 @@ def __str__(self):
@property
def is_indexable(self):
"""Repositories to index."""
return (
not self.is_archived
and not self.is_empty
and not self.is_template
and self.project_set.exists()
)
return not self.is_empty and not self.is_template and self.project_set.exists()

@property
def latest_release(self):
Expand Down
4 changes: 4 additions & 0 deletions backend/apps/owasp/index/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class ChapterIndex(AlgoliaIndex):
"idx_tags",
"idx_updated_at",
"idx_url",
"idx_is_active",
"idx_is_chapter_archived",
)

geo_field = "idx_geo_location"
Expand All @@ -41,6 +43,8 @@ class ChapterIndex(AlgoliaIndex):
],
"indexLanguages": ["en"],
"customRanking": [
"desc(idx_is_active)",
"asc(idx_is_chapter_archived)",
"asc(idx_created_at)",
"desc(idx_updated_at)",
],
Expand Down
2 changes: 2 additions & 0 deletions backend/apps/owasp/index/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ProjectIndex(AlgoliaIndex, IndexBase):
"idx_type",
"idx_updated_at",
"idx_url",
"idx_is_active",
)

settings = {
Expand All @@ -51,6 +52,7 @@ class ProjectIndex(AlgoliaIndex, IndexBase):
],
"indexLanguages": ["en"],
"customRanking": [
"desc(idx_is_active)",
"desc(idx_level_raw)",
"desc(idx_stars_count)",
"desc(idx_contributors_count)",
Expand Down
7 changes: 1 addition & 6 deletions backend/apps/owasp/models/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ def active_chapters_count():
def is_indexable(self):
"""Chapters to index."""
return (
self.is_active
and self.latitude is not None
self.latitude is not None
and self.longitude is not None
and not self.owasp_repository.is_empty
and not self.owasp_repository.is_archived
)

def from_github(self, repository):
Expand Down Expand Up @@ -114,9 +112,6 @@ def generate_geo_location(self):

def generate_suggested_location(self, open_ai=None, max_tokens=100):
"""Generate project summary."""
if not self.is_active:
return

if not (prompt := Prompt.get_owasp_chapter_suggested_location()):
return

Expand Down
4 changes: 2 additions & 2 deletions backend/apps/owasp/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Meta:
@property
def is_indexable(self):
"""Entities to index."""
return self.is_active and self.has_active_repositories
return self.has_active_repositories

@property
def github_url(self):
Expand Down Expand Up @@ -105,7 +105,7 @@ def from_github(self, field_mapping, repository):

def generate_summary(self, prompt, open_ai=None, max_tokens=500):
"""Generate entity summary."""
if not self.is_active or not prompt:
if not prompt:
return

open_ai = open_ai or OpenAi()
Expand Down
2 changes: 0 additions & 2 deletions backend/apps/owasp/models/managers/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ def get_queryset(self):
return (
super()
.get_queryset()
.filter(is_active=True)
.select_related("owasp_repository")
.filter(
owasp_repository__is_archived=False,
owasp_repository__is_empty=False,
)
)
Expand Down
10 changes: 10 additions & 0 deletions backend/apps/owasp/models/mixins/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ def idx_top_contributors(self):
def idx_updated_at(self):
"""Return updated at for indexing."""
return (self.updated_at or self.owasp_repository.updated_at).timestamp()

@property
def idx_is_active(self):
"""Return URL for indexing."""
return self.is_active

@property
def idx_is_chapter_archived(self):
"""Return URL for indexing."""
return self.owasp_repository.is_archived
7 changes: 7 additions & 0 deletions backend/apps/owasp/models/mixins/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,11 @@ def idx_type(self):
@property
def idx_updated_at(self):
"""Return updated at for indexing."""
if not self.updated_at:
return None
return self.updated_at.timestamp()

@property
def idx_is_active(self):
"""Return URL for indexing."""
return self.is_active
2 changes: 1 addition & 1 deletion backend/apps/owasp/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def is_tool_type(self):
@property
def is_indexable(self):
"""Projects to index."""
return self.is_active and self.has_active_repositories
return self.has_active_repositories

@property
def nest_key(self):
Expand Down
14 changes: 4 additions & 10 deletions backend/tests/owasp/models/chapter_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,10 @@ def test_generate_suggested_location(

assert chapter.suggested_location == (expected_location or "")

if is_active:
mock_open_ai.set_input.assert_called_once_with(geo_string)
mock_open_ai.set_max_tokens.assert_called_once_with(100)
mock_open_ai.set_prompt.assert_called_once_with("Tell me the location")
mock_open_ai.complete.assert_called_once()
else:
mock_open_ai.set_input.assert_not_called()
mock_open_ai.set_max_tokens.assert_not_called()
mock_open_ai.set_prompt.assert_not_called()
mock_open_ai.complete.assert_not_called()
mock_open_ai.set_input.assert_called_once_with(geo_string)
mock_open_ai.set_max_tokens.assert_called_once_with(100)
mock_open_ai.set_prompt.assert_called_once_with("Tell me the location")
mock_open_ai.complete.assert_called_once()

@pytest.mark.parametrize(
("name", "key", "expected_str"),
Expand Down
11 changes: 4 additions & 7 deletions backend/tests/owasp/models/common_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ class Meta:

class TestRepositoryBasedEntityModel:
@pytest.mark.parametrize(
("is_active", "has_active_repositories", "expected"),
("has_active_repositories", "expected"),
[
(True, True, True),
(True, False, False),
(False, True, False),
(False, False, False),
(True, True),
(False, False),
],
)
def test_is_indexable(self, is_active, has_active_repositories, expected):
def test_is_indexable(self, has_active_repositories, expected):
model = EntityModel()
model.is_active = is_active
model.has_active_repositories = has_active_repositories

assert model.is_indexable == expected
Expand Down
Loading