Skip to content

Commit fffe02d

Browse files
committed
Merge branch 'main' of github.com:OWASP/Nest
2 parents e2e09c1 + 1e936b5 commit fffe02d

File tree

11 files changed

+136
-50
lines changed

11 files changed

+136
-50
lines changed

backend/apps/sitemap/views/chapter.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ class ChapterSitemap(BaseSitemap):
1010
change_frequency = "weekly"
1111
prefix = "/chapters"
1212

13-
def items(self):
14-
"""Return list of chapters for sitemap generation."""
13+
def items(self) -> list[Chapter]:
14+
"""Return chapters for sitemap generation.
15+
16+
Returns:
17+
list: List of indexable Chapter objects ordered by update/creation date.
18+
19+
"""
1520
return [
1621
c
1722
for c in Chapter.active_chapters.order_by(

backend/apps/sitemap/views/committee.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ class CommitteeSitemap(BaseSitemap):
1010
change_frequency = "monthly"
1111
prefix = "/committees"
1212

13-
def items(self):
14-
"""Return list of committees for sitemap generation."""
13+
def items(self) -> list[Committee]:
14+
"""Return committees for sitemap generation.
15+
16+
Returns:
17+
list: List of indexable Committee objects ordered by update/creation date.
18+
19+
"""
1520
return [
1621
c
1722
for c in Committee.active_committees.order_by(

backend/apps/sitemap/views/member.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ class MemberSitemap(BaseSitemap):
1010
change_frequency = "daily"
1111
prefix = "/members"
1212

13-
def items(self):
14-
"""Return list of members for sitemap generation."""
15-
return [u for u in User.objects.filter(is_bot=False) if u.is_indexable]
13+
def items(self) -> list[User]:
14+
"""Return members for sitemap generation.
15+
16+
Returns:
17+
list: List of indexable User objects ordered by update/creation date
18+
19+
"""
20+
return [
21+
u
22+
for u in User.objects.filter(
23+
is_bot=False,
24+
).order_by(
25+
"-updated_at",
26+
"-created_at",
27+
)
28+
if u.is_indexable
29+
]

backend/apps/sitemap/views/organization.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ class OrganizationSitemap(BaseSitemap):
1010
change_frequency = "monthly"
1111
prefix = "/organizations"
1212

13-
def items(self):
14-
"""Return a queryset of indexable Organization objects."""
13+
def items(self) -> list[Organization]:
14+
"""Return organizations for sitemap generation.
15+
16+
Returns:
17+
list: List of indexable OWASP-related Organization objects
18+
ordered by update/creation date.
19+
20+
"""
1521
return [
1622
o
17-
for o in Organization.objects.filter(
18-
is_owasp_related_organization=True,
19-
).order_by(
23+
for o in Organization.related_organizations.order_by(
2024
"-updated_at",
2125
"-created_at",
2226
)

backend/apps/sitemap/views/project.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ class ProjectSitemap(BaseSitemap):
1010
change_frequency = "weekly"
1111
prefix = "/projects"
1212

13-
def items(self):
14-
"""Return list of projects for sitemap generation."""
13+
def items(self) -> list[Project]:
14+
"""Return projects for sitemap generation.
15+
16+
Returns:
17+
list: List of indexable Project objects ordered by update/creation date.
18+
19+
"""
1520
return [
1621
p
1722
for p in Project.active_projects.order_by(

backend/apps/sitemap/views/repository.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Repository sitemap."""
22

3-
from django.db.models import QuerySet
4-
53
from apps.github.models.repository import Repository
64
from apps.sitemap.views.base import BaseSitemap
75

@@ -12,17 +10,22 @@ class RepositorySitemap(BaseSitemap):
1210
change_frequency = "weekly"
1311
prefix = "/repositories"
1412

15-
def items(self) -> QuerySet[Repository]:
16-
"""Return list of repositories for sitemap generation."""
17-
return Repository.objects.filter(
18-
is_archived=False,
19-
is_empty=False,
20-
is_template=False,
21-
organization__isnull=False,
22-
).order_by(
23-
"-updated_at",
24-
"-created_at",
25-
)
13+
def items(self) -> list[Repository]:
14+
"""Return repositories for sitemap generation.
15+
16+
Returns:
17+
list[Repository]: List of indexable Repository objects ordered by
18+
update/creation date.
19+
20+
"""
21+
return [
22+
r
23+
for r in Repository.objects.order_by(
24+
"-updated_at",
25+
"-created_at",
26+
)
27+
if r.organization and r.is_indexable
28+
]
2629

2730
def location(self, obj: Repository) -> str:
2831
"""Return the URL path for a repository.

backend/apps/sitemap/views/snapshot.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Snapshot sitemap."""
22

3+
from django.db.models import QuerySet
4+
35
from apps.owasp.models.snapshot import Snapshot
46
from apps.sitemap.views.base import BaseSitemap
57

@@ -10,8 +12,13 @@ class SnapshotSitemap(BaseSitemap):
1012
change_frequency = "monthly"
1113
prefix = "/snapshots"
1214

13-
def items(self):
14-
"""Return queryset of snapshots for sitemap generation."""
15+
def items(self) -> QuerySet[Snapshot]:
16+
"""Return snapshots for sitemap generation.
17+
18+
Returns:
19+
QuerySet: Queryset of completed Snapshot objects ordered by update/creation date.
20+
21+
"""
1522
return Snapshot.objects.filter(
1623
status=Snapshot.Status.COMPLETED,
1724
).order_by(
@@ -20,5 +27,13 @@ def items(self):
2027
)
2128

2229
def location(self, obj):
23-
"""Return the URL path for an object."""
30+
"""Return the URL path for a snapshot.
31+
32+
Args:
33+
obj: Snapshot instance to generate URL for.
34+
35+
Returns:
36+
str: The URL path for the snapshot.
37+
38+
"""
2439
return f"{self.prefix}/{obj.key}"

backend/apps/sitemap/views/static.py

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,50 @@
1616
class StaticSitemap(BaseSitemap):
1717
"""A sitemap for static routes that includes all other dynamic sitemaps."""
1818

19-
def changefreq(self, item):
20-
"""Return the change frequency for a static route item."""
19+
def changefreq(self, item) -> str:
20+
"""Return the change frequency for a static route item.
21+
22+
Args:
23+
item: Dictionary containing static route information.
24+
25+
Returns:
26+
str: Change frequency value for the sitemap entry.
27+
28+
"""
2129
return item["changefreq"]
2230

23-
def location(self, item):
24-
"""Return the URL path for a static route item."""
31+
def location(self, item) -> str:
32+
"""Return the URL path for a static route item.
33+
34+
Args:
35+
item: Dictionary containing static route information.
36+
37+
Returns:
38+
str: The URL path for the static route.
39+
40+
"""
2541
return item["path"]
2642

27-
def items(self):
28-
"""Return list of static routes for sitemap generation."""
43+
def items(self) -> tuple[dict, ...]:
44+
"""Return static routes for sitemap generation.
45+
46+
Returns:
47+
tuple: Tuple of dictionaries containing static route configurations.
48+
49+
"""
2950
return BaseSitemap.STATIC_ROUTES
3051

31-
def lastmod(self, item):
32-
"""Return the last modification date for a static route item."""
52+
def lastmod(self, item: dict) -> datetime:
53+
"""Return the last modification date for a static route item.
54+
55+
Args:
56+
item: Dictionary containing static route information.
57+
58+
Returns:
59+
datetime: Last modification timestamp based on the most recently updated
60+
object of the corresponding model, or current time if no model mapping exists.
61+
62+
"""
3363
path_to_model = {
3464
"/chapters": Chapter,
3565
"/committees": Committee,
@@ -41,11 +71,19 @@ def lastmod(self, item):
4171
}
4272

4373
return (
44-
model.objects.aggregate(latest=Max("updated_at"))["latest"]
74+
model.objects.aggregate(latest=Max("updated_at"))["latest"] # type: ignore[attr-defined]
4575
if (model := path_to_model.get(item["path"]))
4676
else datetime.now(UTC)
4777
)
4878

49-
def priority(self, item):
50-
"""Return the priority score for a static route item."""
79+
def priority(self, item: dict) -> float:
80+
"""Return the priority score for a static route item.
81+
82+
Args:
83+
item: Dictionary containing static route information.
84+
85+
Returns:
86+
float: Priority value for the sitemap entry (0.0 to 1.0).
87+
88+
"""
5189
return item["priority"]

backend/tests/apps/sitemap/views/member_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_inherits_from_base(self):
1616
@patch("apps.sitemap.views.member.User")
1717
def test_items(self, mock_user):
1818
mock_obj = MagicMock(is_indexable=True)
19-
mock_user.objects.filter.return_value = [mock_obj]
19+
mock_user.objects.filter.return_value.order_by.return_value = [mock_obj]
2020
sitemap = MemberSitemap()
2121

2222
assert list(sitemap.items()) == [mock_obj]

backend/tests/apps/sitemap/views/organization_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def test_inherits_from_base(self):
1616
@patch("apps.sitemap.views.organization.Organization")
1717
def test_items(self, mock_organization):
1818
mock_obj = MagicMock(is_indexable=True)
19-
mock_qs = MagicMock()
20-
mock_qs.order_by.return_value = [mock_obj]
21-
mock_organization.objects.filter.return_value = mock_qs
19+
mock_queryset = MagicMock()
20+
mock_queryset.__iter__ = lambda _: iter([mock_obj])
21+
mock_organization.related_organizations.order_by.return_value = mock_queryset
2222
sitemap = OrganizationSitemap()
2323

2424
assert list(sitemap.items()) == [mock_obj]

0 commit comments

Comments
 (0)