Skip to content

Commit

Permalink
Made Inactive and archived entities to indexable (#422)
Browse files Browse the repository at this point in the history
* make inactive and archived indexable | modified tests

* removed unwanted lines

* fixed multi-line-summary-second-line

* adjusted the customRanking rules for inactive/archives

* fixed

* fix repository have no attribute is_active

* updated frontend

* Fixed status

* updated to have top 6 contributors instead of top 5

* updated test

* undo contribution fix

* fix suggestions

* removed status  from projects, add show Inactive in direct link access

* inactive projectdetail

* Update code

---------

Co-authored-by: Arkadii Yakovets <[email protected]>
Co-authored-by: Arkadii Yakovets <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2025
1 parent 990cd4d commit dbd501d
Show file tree
Hide file tree
Showing 20 changed files with 38 additions and 30 deletions.
1 change: 1 addition & 0 deletions backend/apps/owasp/index/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ChapterIndex(AlgoliaIndex):
fields = (
"idx_country",
"idx_created_at",
"idx_is_active",
"idx_key",
"idx_leaders",
"idx_name",
Expand Down
1 change: 1 addition & 0 deletions backend/apps/owasp/index/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ProjectIndex(AlgoliaIndex, IndexBase):
"idx_forks_count",
"idx_issues",
"idx_issues_count",
"idx_is_active",
"idx_key",
"idx_languages",
"idx_leaders",
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
5 changes: 5 additions & 0 deletions backend/apps/owasp/models/mixins/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def idx_geo_location(self):
"""Return geographic location for indexing."""
return self.latitude, self.longitude

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

@property
def idx_key(self):
"""Return key for indexing."""
Expand Down
5 changes: 5 additions & 0 deletions backend/apps/owasp/models/mixins/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def idx_issues_count(self):
"""Return issues count for indexing."""
return self.open_issues.count()

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

@property
def idx_key(self):
"""Return key for indexing."""
Expand Down
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
1 change: 1 addition & 0 deletions frontend/__tests__/src/data/mockChapterData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const mockChapterData = {
key: 'chapter_1',
url: 'https://owasp.org/www-chapter-nagoya',
objectID: '539',
is_active: true,
},
],
}
1 change: 1 addition & 0 deletions frontend/__tests__/src/data/mockProjectData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const mockProjectData = {
key: 'project_1',
stars_count: 20,
contributors_count: 5,
is_active: true,
},
],
}
Expand Down
1 change: 1 addition & 0 deletions frontend/__tests__/src/data/mockProjectDetailsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const mockProjectDetailsData = {
forks_count: 20,
stars_count: 100,
issues_count: 10,
is_active: true,
repositories_count: 2,
summary: 'This is a summary of the test project.',
languages: Array.from({ length: 15 }, (_, i) => `Language ${i + 1}`),
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/ChapterDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ChapterDetailsPage = () => {
</div>
)

if (!chapter)
if (!chapter || !chapter.is_active)
return (
<ErrorDisplay
statusCode={404}
Expand Down Expand Up @@ -64,6 +64,7 @@ const ChapterDetailsPage = () => {
topContributors={chapter.top_contributors}
button={SubmitButton}
social={formattedUrls}
isActive={chapter.is_active}
/>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/ProjectDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const ProjectDetailsPage = () => {
<div className="mt-16 min-h-screen bg-white p-8 text-gray-600 dark:bg-[#212529] dark:text-gray-300">
<div className="mx-auto max-w-6xl">
<h1 className="mb-6 mt-4 text-4xl font-bold">{project.name}</h1>
{!project.is_active && (
<span className="ml-2 rounded bg-red-200 px-2 py-1 text-sm text-red-800">Inactive</span>
)}
<p className="mb-6 text-xl">{project.description}</p>
<div className="mb-8 rounded-lg bg-gray-100 p-6 shadow-md dark:bg-gray-800">
<h2 className="mb-4 text-2xl font-semibold">Summary</h2>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const ProjectsPage = () => {
/>
}
>
{projects && projects.map(renderProjectCard)}
{projects && projects.filter((project) => project.is_active).map(renderProjectCard)}
</SearchPageLayout>
)
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export interface CardProps {
projectLink?: string
social?: { title: string; icon: string; url: string }[]
tooltipLabel?: string
isActive?: boolean
}
1 change: 1 addition & 0 deletions frontend/src/types/chapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface ChapterType {
created_at: number
is_active: boolean
key: string
leaders: string[]
name: string
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type project = {
}[]
contributors_count: number
forks_count: number
is_active: boolean
leaders: string[]
level: string
name: string
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/utils/paramsMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const getParamsForIndexName = (indexName: string, distinct = false) => {
return {
attributesToRetrieve: [
'idx_created_at',
'idx_is_active',
'idx_key',
'idx_leaders',
'idx_name',
Expand All @@ -44,6 +45,7 @@ export const getParamsForIndexName = (indexName: string, distinct = false) => {
'idx_forks_count',
'idx_issues',
'idx_issues_count',
'idx_is_active',
'idx_key',
'idx_languages',
'idx_leaders',
Expand Down

0 comments on commit dbd501d

Please sign in to comment.