diff --git a/microsetta_private_api/admin/admin_impl.py b/microsetta_private_api/admin/admin_impl.py index 44e25c08b..ff4d2d80c 100644 --- a/microsetta_private_api/admin/admin_impl.py +++ b/microsetta_private_api/admin/admin_impl.py @@ -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 diff --git a/microsetta_private_api/admin/tests/test_admin_repo.py b/microsetta_private_api/admin/tests/test_admin_repo.py index cb3c4ff76..d106e0cff 100644 --- a/microsetta_private_api/admin/tests/test_admin_repo.py +++ b/microsetta_private_api/admin/tests/test_admin_repo.py @@ -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]) diff --git a/microsetta_private_api/api/microsetta_private_api.yaml b/microsetta_private_api/api/microsetta_private_api.yaml index ca68ff46d..16ccba4ec 100644 --- a/microsetta_private_api/api/microsetta_private_api.yaml +++ b/microsetta_private_api/api/microsetta_private_api.yaml @@ -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 @@ -3088,7 +3122,6 @@ components: schema: $ref: '#/components/schemas/creation_time' required: False - source_type: name: source_type in: query @@ -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' @@ -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 diff --git a/microsetta_private_api/repo/admin_repo.py b/microsetta_private_api/repo/admin_repo.py index 5257796ce..d3a56f0c9 100644 --- a/microsetta_private_api/repo/admin_repo.py +++ b/microsetta_private_api/repo/admin_repo.py @@ -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, ) + ) diff --git a/microsetta_private_api/repo/perk_fulfillment_repo.py b/microsetta_private_api/repo/perk_fulfillment_repo.py index a9996e6d3..2511c0e4f 100644 --- a/microsetta_private_api/repo/perk_fulfillment_repo.py +++ b/microsetta_private_api/repo/perk_fulfillment_repo.py @@ -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 @@ -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']: