-
-
Notifications
You must be signed in to change notification settings - Fork 630
Added sponsor support #4511
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:main
Choose a base branch
from
anurag2787:sponser-page
base: main
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
Added sponsor support #4511
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3f1e8e8
Added Sponsor page
anurag2787 8449e13
fixed sonarqube warning
anurag2787 b2e8715
fixed review
anurag2787 1becfb7
fixed sonarqube issue
anurag2787 a98322f
Merge branch 'main' into sponser-page
anurag2787 b2e5325
revert changes
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
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| """OWASP GraphQL mutations.""" | ||
|
|
||
| from .sponsor import SponsorMutations | ||
|
|
||
|
|
||
| class OwaspMutations(SponsorMutations): | ||
| """OWASP mutations.""" |
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,124 @@ | ||
| """OWASP sponsors GraphQL mutations.""" | ||
|
|
||
| import logging | ||
|
|
||
| import strawberry | ||
| from django.core.exceptions import ValidationError | ||
| from django.db.utils import IntegrityError | ||
|
|
||
| from apps.common.utils import slugify | ||
| from apps.owasp.api.internal.nodes.sponsor import SponsorNode | ||
| from apps.owasp.models.sponsor import Sponsor | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @strawberry.type | ||
| class CreateSponsorApplicationResult: | ||
| """Result of creating a sponsor application.""" | ||
|
|
||
| ok: bool | ||
| sponsor: SponsorNode | None = None | ||
| code: str | None = None | ||
| message: str | None = None | ||
|
|
||
|
|
||
| @strawberry.type | ||
| class SponsorMutations: | ||
| """Sponsor mutations.""" | ||
|
|
||
| @strawberry.mutation | ||
| def create_sponsor_application( | ||
| self, | ||
| name: str, | ||
| contact_email: str, | ||
| sponsorship_interest: str, | ||
| website: str | None = None, | ||
| ) -> CreateSponsorApplicationResult: | ||
| """Create a sponsor application. | ||
|
|
||
| Args: | ||
| name: Organization name | ||
| contact_email: Contact email address | ||
| sponsorship_interest: Message about sponsorship interest | ||
| website: Organization website (optional) | ||
|
|
||
| Returns: | ||
| CreateSponsorApplicationResult with sponsor application status | ||
|
|
||
| """ | ||
| if not name or not name.strip(): | ||
| return CreateSponsorApplicationResult( | ||
| ok=False, | ||
| code="INVALID_NAME", | ||
| message="Organization name is required", | ||
| ) | ||
|
|
||
| if not contact_email or not contact_email.strip(): | ||
| return CreateSponsorApplicationResult( | ||
| ok=False, | ||
| code="INVALID_EMAIL", | ||
| message="Contact email is required", | ||
| ) | ||
|
|
||
| if not sponsorship_interest or not sponsorship_interest.strip(): | ||
| return CreateSponsorApplicationResult( | ||
| ok=False, | ||
| code="INVALID_INTEREST", | ||
| message="Sponsorship interest message is required", | ||
| ) | ||
|
|
||
| try: | ||
| name_clean = name.strip() | ||
| email_clean = contact_email.strip() | ||
| interest_clean = sponsorship_interest.strip() | ||
| url_clean = website.strip() if website else "" | ||
| key = slugify(name_clean) | ||
|
|
||
| # Validate before get_or_create to avoid saving invalid sponsor | ||
| temp_sponsor = Sponsor( | ||
| name=name_clean, | ||
| contact_email=email_clean, | ||
| url=url_clean, | ||
| description=interest_clean, | ||
| status=Sponsor.Status.DRAFT, | ||
| sort_name=name_clean, | ||
| key=key, | ||
| ) | ||
| temp_sponsor.full_clean(validate_unique=False) | ||
|
|
||
| sponsor, created = Sponsor.objects.get_or_create( | ||
|
anurag2787 marked this conversation as resolved.
|
||
| key=key, | ||
| defaults={ | ||
| "name": name_clean, | ||
| "contact_email": email_clean, | ||
| "url": url_clean, | ||
| "description": interest_clean, | ||
| "status": Sponsor.Status.DRAFT, | ||
| "sort_name": name_clean, | ||
| }, | ||
| ) | ||
|
|
||
| if not created: | ||
| return CreateSponsorApplicationResult( | ||
| ok=False, | ||
| code="DUPLICATE", | ||
| message="A sponsor with this organization name already exists", | ||
| ) | ||
|
|
||
| logger.info("Sponsor application created: %s - %s", sponsor.id, sponsor.name) | ||
|
|
||
| return CreateSponsorApplicationResult( | ||
| ok=True, | ||
| sponsor=sponsor, | ||
| code="SUCCESS", | ||
| message="Sponsor application submitted successfully", | ||
| ) | ||
|
|
||
| except (ValidationError, IntegrityError) as err: | ||
| logger.warning("Error creating sponsor application: %s", err) | ||
| return CreateSponsorApplicationResult( | ||
| ok=False, | ||
| code="ERROR", | ||
| message="Error submitting sponsor application", | ||
| ) | ||
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
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.