Skip to content

Commit

Permalink
Merge pull request #539 from biocore/csymons_perks_20230928
Browse files Browse the repository at this point in the history
Add Perk Fulfillment Toggle to Admin UI
  • Loading branch information
cassidysymons authored Sep 29, 2023
2 parents 1b4f817 + 9bd2bf9 commit eea1212
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 3 deletions.
18 changes: 18 additions & 0 deletions microsetta_private_api/admin/admin_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,3 +917,21 @@ def get_vioscreen_sample_to_user(token_info):
st_repo = SurveyTemplateRepo(t)
data = st_repo.get_vioscreen_sample_to_user()
return jsonify(data), 200


def get_perk_fulfillment_state(token_info):
validate_admin_access(token_info)
with Transaction() as t:
admin_repo = AdminRepo(t)
pf_state = admin_repo.get_perk_fulfillment_state()
return jsonify({"pf_state": pf_state}), 200


def update_perk_fulfillment_state(token_info, perk_fulfillment_state):
validate_admin_access(token_info)
with Transaction() as t:
admin_repo = AdminRepo(t)
admin_repo.update_perk_fulfillment_state(perk_fulfillment_state)
pf_state = admin_repo.get_perk_fulfillment_state()
t.commit()
return jsonify({"pf_state": pf_state}), 200
40 changes: 40 additions & 0 deletions microsetta_private_api/admin/tests/test_admin_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,3 +1344,43 @@ def test_create_ffq_code(self):
)
row = cur.fetchone()
self.assertEqual(row['registration_code_used'], None)

def test_get_perk_fulfillment_state(self):
with Transaction() as t:
admin_repo = AdminRepo(t)
with t.cursor() as cur:
cur.execute(
"UPDATE ag.settings "
"SET perk_fulfillment_active = TRUE"
)

obs = admin_repo.get_perk_fulfillment_state()
self.assertTrue(obs)

cur.execute(
"UPDATE ag.settings "
"SET perk_fulfillment_active = False"
)

obs = admin_repo.get_perk_fulfillment_state()
self.assertFalse(obs)

def test_update_perk_fulfillment_state(self):
with Transaction() as t:
with t.cursor() as cur:
admin_repo = AdminRepo(t)
admin_repo.update_perk_fulfillment_state(True)
cur.execute(
"SELECT perk_fulfillment_active "
"FROM ag.settings"
)
obs = cur.fetchone()
self.assertTrue(obs[0])

admin_repo.update_perk_fulfillment_state(False)
cur.execute(
"SELECT perk_fulfillment_active "
"FROM ag.settings"
)
obs = cur.fetchone()
self.assertFalse(obs[0])
46 changes: 45 additions & 1 deletion microsetta_private_api/api/microsetta_private_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,40 @@ paths:
'404':
$ref: '#/components/responses/404NotFound'

'/admin/perk_fulfillment_state':
get:
operationId: microsetta_private_api.admin.admin_impl.get_perk_fulfillment_state
tags:
- Admin
summary: Get the current state of whether perk fulfillment tasks are running
description: Get the current state of whether perk fulfillment tasks are running
responses:
'200':
description: Object containing state of perk fulfillment
content:
application/json:
schema:
type: object
'401':
$ref: '#/components/responses/401Unauthorized'
put:
operationId: microsetta_private_api.admin.admin_impl.update_perk_fulfillment_state
tags:
- Admin
summary: Update the state of whether perk fulfillment tasks are running
description: Update the state of whether perk fulfillment tasks are running
parameters:
- $ref: '#/components/parameters/perk_fulfillment_state'
responses:
'200':
description: Object containing state of perk fulfillment
content:
application/json:
schema:
type: object
'401':
$ref: '#/components/responses/401Unauthorized'

'/admin/verify_address':
get:
operationId: microsetta_private_api.admin.admin_impl.address_verification
Expand Down Expand Up @@ -3088,7 +3122,6 @@ components:
schema:
$ref: '#/components/schemas/creation_time'
required: False

source_type:
name: source_type
in: query
Expand Down Expand Up @@ -3119,6 +3152,12 @@ components:
description: FFQ Code
schema:
$ref: '#/components/schemas/ffq_code'
perk_fulfillment_state:
name: perk_fulfillment_state
in: query
description: Boolean representing whether perk fulfillment tasks are running
schema:
$ref: '#/components/schemas/perk_fulfillment_state'

responses:
401Unauthorized: # Can be referenced as '#/components/responses/401Unauthorized'
Expand Down Expand Up @@ -3147,6 +3186,11 @@ components:
$ref: '#/components/schemas/Error'

schemas:
# settings section
perk_fulfillment_state:
type: boolean
example: True

# account section
account_id:
type: string
Expand Down
17 changes: 17 additions & 0 deletions microsetta_private_api/repo/admin_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1390,3 +1390,20 @@ def create_ffq_code(self):
(code,)
)
return code

def get_perk_fulfillment_state(self):
with self._transaction.cursor() as cur:
cur.execute(
"SELECT perk_fulfillment_active "
"FROM ag.settings"
)
row = cur.fetchone()
return row[0]

def update_perk_fulfillment_state(self, new_state):
with self._transaction.cursor() as cur:
cur.execute(
"UPDATE ag.settings "
"SET perk_fulfillment_active = %s",
(new_state, )
)
4 changes: 2 additions & 2 deletions microsetta_private_api/repo/perk_fulfillment_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from microsetta_private_api.admin.admin_impl import\
create_daklapack_order_internal
from microsetta_private_api.model.daklapack_order import FEDEX_PROVIDER,\
FEDEX_GROUND_SHIPPING
FEDEX_2DAY_SHIPPING
from microsetta_private_api.model.activation_code import ActivationCode
from microsetta_private_api.tasks import send_email
from microsetta_private_api.localization import EN_US
Expand Down Expand Up @@ -429,7 +429,7 @@ def _fulfill_kit(self, row, quantity, subscription_id):
"address": address_dict,
"quantity": quantity,
"shipping_provider": FEDEX_PROVIDER,
"shipping_type": FEDEX_GROUND_SHIPPING
"shipping_type": FEDEX_2DAY_SHIPPING
}
result = create_daklapack_order_internal(daklapack_order)
if not result['order_success']:
Expand Down

0 comments on commit eea1212

Please sign in to comment.