Skip to content

Commit

Permalink
fix(cgrants): added missing subscription and contribution fields
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianHymer committed Jul 14, 2023
1 parent 28e75e2 commit d2521be
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 17 deletions.
57 changes: 55 additions & 2 deletions .github/workflows/api-promote-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
default: ""
required: true
type: string
inputs:
push_to_prod_ecr:
description: "Push docker image to production ECR?"
type: boolean
workflow_call:
inputs:
commit:
Expand Down Expand Up @@ -104,6 +108,7 @@ jobs:
outputs:
dockerTag: ${{ steps.vars.outputs.sha_short }}
registry: ${{ steps.login-ecr.outputs.registry }}

build-verifier:
environment: Staging
Expand Down Expand Up @@ -147,10 +152,11 @@ jobs:
outputs:
dockerTag: ${{ steps.vars.outputs.sha_short }}
registry: ${{ steps.login-ecr.outputs.registry }}

deploy-staging:
dockerize:
environment: Staging
needs: [test, build-api, build-verifier]
needs: [build-api, build-verifier]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -187,6 +193,10 @@ jobs:
env:
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
deploy-staging:
environment: Staging
needs: [dockerize, build-api, build-verifier]
runs-on: ubuntu-latest
- uses: pulumi/actions@v3
id: pulumi
with:
Expand All @@ -209,3 +219,46 @@ jobs:
DB_USER: ${{ secrets.DB_USER_STAGING }}
DB_NAME: ${{ secrets.DB_NAME_STAGING }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD_STAGING }}

push-docker-to-prod:
if: ${{ inputs.push_to_prod_ecr }}
environment: Staging
needs: [dockerize, build-api, build-verifier]
runs-on: ubuntu-latest
steps:
- name: Configure Production AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR Production
id: login-ecr-production
uses: aws-actions/amazon-ecr-login@v1
with:
registry-type: public

- name: Tag and push verifier image to Production Amazon ECR
env:
ECR_REGISTRY_STAGING: ${{ needs.build-verifier.outputs.registry }}
ECR_REGISTRY_PRODUCTION: ${{ steps.login-ecr-production.outputs.registry }}
ECR_REGISTRY_ALIAS_STAGING: t1g3k9q8
ECR_REGISTRY_ALIAS_PRODUCTION: c8n6v8e9
ECR_REPOSITORY: passport-verifier
IMAGE_TAG: ${{ needs.build-verifier.outputs.dockerTag }}
run: |
docker tag $ECR_REGISTRY_STAGING/$ECR_REGISTRY_ALIAS_STAGING/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY_PRODUCTION/$ECR_REGISTRY_ALIAS_PRODUCTION/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY_PRODUCTION/$ECR_REGISTRY_ALIAS_PRODUCTION/$ECR_REPOSITORY:$IMAGE_TAG
- name: Tag and push api image to Production Amazon ECR
env:
ECR_REGISTRY_STAGING: ${{ needs.build-api.outputs.registry }}
ECR_REGISTRY_PRODUCTION: ${{ steps.login-ecr-production.outputs.registry }}
ECR_REGISTRY_ALIAS_STAGING: t1g3k9q8
ECR_REGISTRY_ALIAS_PRODUCTION: c8n6v8e9
ECR_REPOSITORY: passport-scorer
IMAGE_TAG: ${{ needs.build-api.outputs.dockerTag }}
run: |
docker tag $ECR_REGISTRY_STAGING/$ECR_REGISTRY_ALIAS_STAGING/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY_PRODUCTION/$ECR_REGISTRY_ALIAS_PRODUCTION/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY_PRODUCTION/$ECR_REGISTRY_ALIAS_PRODUCTION/$ECR_REPOSITORY:$IMAGE_TAG
6 changes: 3 additions & 3 deletions api/cgrants/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from django.conf import settings
from django.db.models import Sum
from django.http import JsonResponse
from ninja.security import APIKeyHeader
from ninja_extra import NinjaExtraAPI
from ninja_schema import Schema
from ninja.security import APIKeyHeader

from .models import Contribution, Grant, GrantContributionIndex, SquelchProfile

Expand Down Expand Up @@ -136,7 +136,7 @@ def grantee_statistics(request):
num_grant_contributors = (
Contribution.objects.filter(
success=True,
subscription__network="mainnet",
subscription__is_mainnet=True,
subscription__grant__hidden=False,
subscription__grant__active=True,
subscription__grant__is_clr_eligible=True,
Expand All @@ -153,7 +153,7 @@ def grantee_statistics(request):
total_contribution_amount = (
Contribution.objects.filter(
success=True,
subscription__network="mainnet",
subscription__is_mainnet=True,
subscription__grant__hidden=False,
subscription__grant__active=True,
subscription__grant__is_clr_eligible=True,
Expand Down
19 changes: 19 additions & 0 deletions api/cgrants/migrations/0002_subscription_is_mainnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.2 on 2023-07-13 19:55

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("cgrants", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="subscription",
name="is_mainnet",
field=models.BooleanField(
default=False, help_text="Is the network for this subscription mainnet?"
),
),
]
17 changes: 17 additions & 0 deletions api/cgrants/migrations/0003_contribution_success.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.2 on 2023-07-13 22:15

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("cgrants", "0002_subscription_is_mainnet"),
]

operations = [
migrations.AddField(
model_name="contribution",
name="success",
field=models.BooleanField(default=False),
),
]
22 changes: 22 additions & 0 deletions api/cgrants/migrations/0004_contribution_amount_per_period_usdt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.2 on 2023-07-14 16:58

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("cgrants", "0003_contribution_success"),
]

operations = [
migrations.AddField(
model_name="contribution",
name="amount_per_period_usdt",
field=models.DecimalField(
decimal_places=18,
default=0,
help_text="The amount per contribution period in USDT",
max_digits=64,
),
),
]
16 changes: 16 additions & 0 deletions api/cgrants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class Subscription(models.Model):
null=True,
help_text=_("The Subscription contributor's Profile."),
)

is_mainnet = models.BooleanField(
help_text=_("Is the network for this subscription mainnet?"),
default=False,
)
data = models.JSONField(
help_text=_("Original subscription data in JSON format"), default=dict
)
Expand All @@ -75,6 +80,17 @@ class Contribution(models.Model):
Subscription,
on_delete=models.CASCADE,
)
success = models.BooleanField(
default=False,
)

amount_per_period_usdt = models.DecimalField(
default=0,
decimal_places=18,
max_digits=64,
help_text=_("The amount per contribution period in USDT"),
)

data = models.JSONField(
help_text=_("Original contribution data in JSON format"), default=dict
)
Expand Down
26 changes: 14 additions & 12 deletions api/cgrants/test/test_cgrants_api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from django.test import TestCase, Client
from django.conf import settings
from django.urls import reverse
from cgrants.models import (
Profile,
Contribution,
Grant,
GrantContributionIndex,
Contribution,
Subscription,
Profile,
SquelchProfile,
Subscription,
)
from django.conf import settings
from django.test import Client, TestCase
from django.urls import reverse


class CgrantsTest(TestCase):
Expand All @@ -20,15 +20,18 @@ def setUp(self):
self.profile1 = Profile.objects.create(handle="user1")
self.profile2 = Profile.objects.create(handle="user2")
self.profile3 = Profile.objects.create(handle="user3")
self.profile4 = Profile.objects.create(handle="user4")

self.grant1 = Grant.objects.create(
admin_profile=self.profile1, hidden=False, active=True, is_clr_eligible=True
)

self.subscription1 = Subscription.objects.create(
grant=self.grant1, contributor_profile=self.profile1
self.subscription = Subscription.objects.create(
grant=self.grant1, contributor_profile=self.profile4, is_mainnet=True
)
Contribution.objects.create(
subscription=self.subscription, success=True, amount_per_period_usdt="100"
)
Contribution.objects.create(subscription=self.subscription1)

# create test grant contribution indexes
GrantContributionIndex.objects.create(
Expand Down Expand Up @@ -73,8 +76,7 @@ def test_contributor_statistics_no_contributions(self):
},
)

def test_grantee_statistics_standard(self):
# Standard case
def test_grantee_statistics(self):
response = self.client.get(
reverse("cgrants:grantee_statistics"),
{"handle": "user1"},
Expand All @@ -87,7 +89,7 @@ def test_grantee_statistics_standard(self):
"num_owned_grants": 1,
"num_grant_contributors": 1,
"num_grants_in_eco_and_cause_rounds": 0,
"total_contribution_amount": 0,
"total_contribution_amount": "100.000000000000000000",
},
)

Expand Down

0 comments on commit d2521be

Please sign in to comment.