-
-
Notifications
You must be signed in to change notification settings - Fork 661
Updated crp-model to include default certificate #5420
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
Open
anurag2787
wants to merge
6
commits into
OWASP:feature/contributor-recognition-program
Choose a base branch
from
anurag2787:crp-model-update
base: feature/contributor-recognition-program
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8271ab7
Updated crp-model to include deafult certificate
anurag2787 d9e205d
address review
anurag2787 2b46bcf
Address review
anurag2787 9a7060c
Updated order
anurag2787 e47a422
fixed link display
anurag2787 a205c2c
Merge branch 'feature/contributor-recognition-program' into crp-model…
anurag2787 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,66 @@ | ||
| """OWASP Certificate GraphQL node.""" | ||
|
|
||
| from typing import TYPE_CHECKING, Annotated | ||
|
|
||
| import strawberry | ||
| import strawberry_django | ||
|
|
||
| from apps.github.api.internal.nodes.user import UserNode | ||
| from apps.owasp.models.crp.certificate import Certificate | ||
|
|
||
| if TYPE_CHECKING: | ||
| from apps.owasp.api.internal.nodes.chapter import ChapterNode | ||
| from apps.owasp.api.internal.nodes.project import ProjectNode | ||
|
|
||
|
|
||
| @strawberry_django.type( | ||
| Certificate, | ||
| fields=[ | ||
| "id", | ||
| "issued_at", | ||
| "message", | ||
| "score", | ||
| "title", | ||
| ], | ||
| ) | ||
| class CertificateNode: | ||
| """Certificate node.""" | ||
|
|
||
| @strawberry_django.field | ||
| def tier(self, root: Certificate) -> str: | ||
| """Resolve the human-readable tier level (e.g. 'Level 1').""" | ||
| return root.get_tier_display() | ||
| @strawberry_django.field(select_related=["recipient"]) | ||
| def recipient(self, root: Certificate) -> UserNode: | ||
| """Resolve the recipient user.""" | ||
| return root.recipient | ||
|
|
||
| @strawberry_django.field(select_related=["recipient"]) | ||
| def github_user(self, root: Certificate) -> UserNode: | ||
| """Resolve the associated GitHub user (alias for recipient).""" | ||
| return root.recipient | ||
|
|
||
| @strawberry_django.field(select_related=["issuer"]) | ||
| def issuer(self, root: Certificate) -> UserNode | None: | ||
| """Resolve the issuer user.""" | ||
| return root.issuer | ||
|
|
||
| @strawberry_django.field(select_related=["project"]) | ||
| def project( | ||
| self, root: Certificate | ||
| ) -> Annotated["ProjectNode", strawberry.lazy("apps.owasp.api.internal.nodes.project")] | None: | ||
| """Resolve associated project.""" | ||
| return root.project | ||
|
|
||
| @strawberry_django.field(select_related=["chapter"]) | ||
| def chapter( | ||
| self, root: Certificate | ||
| ) -> Annotated["ChapterNode", strawberry.lazy("apps.owasp.api.internal.nodes.chapter")] | None: | ||
| """Resolve associated chapter.""" | ||
| return root.chapter | ||
|
|
||
| @strawberry_django.field | ||
| def is_verified(self, root: Certificate) -> bool: | ||
| """Resolve whether the certificate is active/verified.""" | ||
| return not root.is_revoked | ||
| return root.is_verified | ||
|
|
||
| @strawberry_django.field(select_related=["github_user"]) | ||
| def github_user(self, root: Certificate) -> UserNode: | ||
| """Resolve the associated GitHub user.""" | ||
| return root.github_user | ||
| @strawberry_django.field | ||
| def tier(self, root: Certificate) -> str | None: | ||
| """Resolve the human-readable tier level (e.g. 'Level 1').""" | ||
| return root.get_tier_display() if root.tier else None | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...src/apps/owasp/migrations/0076_remove_certificate_unique_active_cert_per_tier_and_more.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| # Generated by Django 6.0.8 on 2026-08-13 09:03 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("github", "0044_user_indexes"), | ||
| ("owasp", "0075_alter_certificate_id"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RemoveConstraint( | ||
| model_name="certificate", | ||
| name="unique_active_cert_per_tier", | ||
| ), | ||
| migrations.AddField( | ||
| model_name="certificate", | ||
| name="chapter", | ||
| field=models.ForeignKey( | ||
| blank=True, | ||
| help_text="Associated chapter", | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="certificates", | ||
| to="owasp.chapter", | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="certificate", | ||
| name="issuer", | ||
| field=models.ForeignKey( | ||
| blank=True, | ||
| help_text="Issuer GitHub user (for generic certificates)", | ||
| null=True, | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="issued_certificates", | ||
| to="github.user", | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="certificate", | ||
| name="message", | ||
| field=models.TextField( | ||
| blank=True, | ||
| default="", | ||
| help_text="Customizable certificate message", | ||
| verbose_name="Message", | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="certificate", | ||
| name="project", | ||
| field=models.ForeignKey( | ||
| blank=True, | ||
| help_text="Associated project", | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="certificates", | ||
| to="owasp.project", | ||
| ), | ||
| ), | ||
| migrations.RenameField( | ||
| model_name="certificate", | ||
| old_name="github_user", | ||
| new_name="recipient", | ||
| ), | ||
| migrations.AddField( | ||
| model_name="certificate", | ||
| name="title", | ||
| field=models.CharField( | ||
| blank=True, | ||
| default="", | ||
| help_text="Certificate title", | ||
| max_length=255, | ||
| verbose_name="Title", | ||
| ), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name="certificate", | ||
| name="score", | ||
| field=models.PositiveIntegerField( | ||
| blank=True, | ||
| help_text="The contributor's score when the certificate was issued", | ||
| null=True, | ||
| verbose_name="Score", | ||
| ), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name="certificate", | ||
| name="tier", | ||
| field=models.CharField( | ||
| blank=True, | ||
| choices=[ | ||
| ("level_1", "Level 1"), | ||
| ("level_2", "Level 2"), | ||
| ("level_3", "Level 3"), | ||
| ("level_4", "Level 4"), | ||
| ], | ||
| default="", | ||
| help_text="The tier at which the certificate was issued", | ||
| max_length=20, | ||
| verbose_name="Tier", | ||
| ), | ||
| ), | ||
| migrations.AddConstraint( | ||
| model_name="certificate", | ||
| constraint=models.UniqueConstraint( | ||
| condition=models.Q(("is_revoked", False), models.Q(("tier", ""), _negated=True)), | ||
| fields=("recipient", "tier"), | ||
| name="unique_active_cert_per_tier", | ||
| violation_error_message="Cannot have multiple active certificates for same tier", | ||
| ), | ||
| ), | ||
| ] | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.