Skip to content

Commit 995f67a

Browse files
committed
Merge branch 'main' of github.com:OWASP/Nest into pr/Piyushrathoree/2273
2 parents 848ae72 + 8c30dd4 commit 995f67a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1554
-1221
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Check PR linked issue and assignee
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
9+
permissions:
10+
contents: read
11+
issues: write
12+
pull-requests: write
13+
14+
jobs:
15+
check-pr-issue:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v5
20+
21+
- name: Check PR linked issue and assignee
22+
uses: arkid15r/check-pr-issue-action@a3635191c798f111aae577759b579dc37bb13e02
23+
with:
24+
close_pr_on_failure: 'false'
25+
github_token: ${{ secrets.GITHUB_TOKEN }}
26+
no_assignee_message: 'Test: The linked issue must be assigned to the PR author.'
27+
no_issue_message: 'Test: This PR must be linked to an issue.'
28+
require_assignee: 'true'

.github/workflows/run-ci-cd.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
7272

7373
- name: Install pnpm
74-
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda
74+
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061
7575
with:
7676
version: 10
7777
run_install: true
@@ -557,7 +557,7 @@ jobs:
557557
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
558558

559559
- name: Install pnpm
560-
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda
560+
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061
561561
with:
562562
run_install: true
563563
version: 10

.github/workflows/run-code-ql.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
languages: ${{ matrix.language }}
3737

3838
- name: Install pnpm
39-
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda
39+
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061
4040
with:
4141
version: 10
4242
run_install: false

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ repos:
8383
exclude: pnpm-lock.yaml
8484

8585
- repo: https://github.com/tox-dev/pyproject-fmt
86-
rev: v2.7.0
86+
rev: v2.10.0
8787
hooks:
8888
- id: pyproject-fmt

LEARN.md

Lines changed: 0 additions & 73 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# [OWASP Nest](https://nest.owasp.org/)
99

10-
[![OWASP](https://img.shields.io/badge/OWASP-Incubator-blue?style=for-the-badge)](https://owasp.org/www-project-nest/) [![OWASP](https://img.shields.io/badge/OWASP-Code-blue?style=for-the-badge)](https://owasp.org/www-project-nest/) [![project-nest](https://img.shields.io/badge/OWASP-%23project--nest-blue?logo=slack&logoColor=white&style=for-the-badge)](https://owasp.slack.com/messages/project-nest)
10+
[![OWASP](https://img.shields.io/badge/Lab-blue?&label=owasp%20level&style=for-the-badge)](https://owasp.org/www-project-nest/) [![OWASP](https://img.shields.io/badge/Code-blue?label=OWASP%20Type&style=for-the-badge)](https://owasp.org/www-project-nest/) [![project-nest](https://img.shields.io/badge/%23project--nest-blue?label=OWASP%20Slack&logoColor=white&style=for-the-badge)](https://owasp.slack.com/messages/project-nest)
1111

1212
[![License](https://img.shields.io/github/license/owasp/nest?color=blue&label=License&style=for-the-badge)](https://github.com/OWASP/Nest/blob/main/LICENSE) [![Last Commit](https://img.shields.io/github/last-commit/owasp/nest/main?color=blue&style=for-the-badge&label=Last%20commit)](https://github.com/OWASP/Nest/commits/main/) [![Contributors](https://img.shields.io/github/contributors/owasp/nest?style=for-the-badge&label=Contributors&color=blue)](https://github.com/OWASP/Nest/graphs/contributors)
1313

backend/apps/api/decorators/__init__.py

Whitespace-only changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Decorator for API Cache."""
2+
3+
from functools import wraps
4+
from http import HTTPStatus
5+
6+
from django.conf import settings
7+
from django.core.cache import cache
8+
from django.http import HttpRequest
9+
10+
11+
def generate_key(
12+
request: HttpRequest,
13+
prefix: str,
14+
):
15+
"""Generate a cache key for a request."""
16+
return f"{prefix}:{request.get_full_path()}"
17+
18+
19+
def cache_response(
20+
ttl: int | None = None,
21+
prefix: str | None = None,
22+
):
23+
"""Cache API responses for GET and HEAD requests.
24+
25+
Args:
26+
ttl (int): The time-to-live for the cache entry in seconds.
27+
prefix (str): A prefix for the cache key.
28+
29+
"""
30+
if ttl is None:
31+
ttl = settings.API_CACHE_TIME_SECONDS
32+
33+
if prefix is None:
34+
prefix = settings.API_CACHE_PREFIX
35+
36+
def decorator(view_func):
37+
@wraps(view_func)
38+
def _wrapper(request, *args, **kwargs):
39+
if request.method not in ("GET", "HEAD"):
40+
return view_func(request, *args, **kwargs)
41+
42+
cache_key = generate_key(
43+
request=request,
44+
prefix=prefix,
45+
)
46+
if response := cache.get(cache_key):
47+
return response
48+
49+
response = view_func(request, *args, **kwargs)
50+
if response.status_code == HTTPStatus.OK:
51+
cache.set(cache_key, response, timeout=ttl)
52+
return response
53+
54+
return _wrapper
55+
56+
return decorator

backend/apps/api/rest/v0/chapter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
from http import HTTPStatus
55
from typing import Literal
66

7-
from django.conf import settings
87
from django.http import HttpRequest
9-
from django.views.decorators.cache import cache_page
108
from ninja import Field, FilterSchema, Path, Query, Schema
119
from ninja.decorators import decorate_view
1210
from ninja.pagination import RouterPaginated
1311
from ninja.responses import Response
1412

13+
from apps.api.decorators.cache import cache_response
1514
from apps.owasp.models.chapter import Chapter as ChapterModel
1615

1716
router = RouterPaginated(tags=["Chapters"])
@@ -61,7 +60,7 @@ class ChapterFilter(FilterSchema):
6160
response=list[Chapter],
6261
summary="List chapters",
6362
)
64-
@decorate_view(cache_page(settings.API_CACHE_TIME_SECONDS))
63+
@decorate_view(cache_response())
6564
def list_chapters(
6665
request: HttpRequest,
6766
filters: ChapterFilter = Query(...),
@@ -84,6 +83,7 @@ def list_chapters(
8483
},
8584
summary="Get chapter",
8685
)
86+
@decorate_view(cache_response())
8787
def get_chapter(
8888
request: HttpRequest,
8989
chapter_id: str = Path(example="London"),

backend/apps/api/rest/v0/committee.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
from http import HTTPStatus
55
from typing import Literal
66

7-
from django.conf import settings
87
from django.http import HttpRequest
9-
from django.views.decorators.cache import cache_page
108
from ninja import Path, Query, Schema
119
from ninja.decorators import decorate_view
1210
from ninja.pagination import RouterPaginated
1311
from ninja.responses import Response
1412

13+
from apps.api.decorators.cache import cache_response
1514
from apps.owasp.models.committee import Committee as CommitteeModel
1615

1716
router = RouterPaginated(tags=["Committees"])
@@ -54,7 +53,7 @@ class CommitteeError(Schema):
5453
response=list[Committee],
5554
summary="List committees",
5655
)
57-
@decorate_view(cache_page(settings.API_CACHE_TIME_SECONDS))
56+
@decorate_view(cache_response())
5857
def list_committees(
5958
request: HttpRequest,
6059
ordering: Literal["created_at", "-created_at", "updated_at", "-updated_at"] | None = Query(
@@ -76,6 +75,7 @@ def list_committees(
7675
},
7776
summary="Get committee",
7877
)
78+
@decorate_view(cache_response())
7979
def get_chapter(
8080
request: HttpRequest,
8181
committee_id: str = Path(example="project"),

0 commit comments

Comments
 (0)