Skip to content

Commit

Permalink
updated user password reset, added starter documentation reads
Browse files Browse the repository at this point in the history
  • Loading branch information
aurthurm committed Dec 30, 2023
1 parent cfdfc24 commit 5edeb38
Show file tree
Hide file tree
Showing 166 changed files with 9,843 additions and 3,633 deletions.
200 changes: 166 additions & 34 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file removed Maturity Framework – Global Laboratory eTools.pdf
Binary file not shown.
8 changes: 6 additions & 2 deletions felicity/api/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ async def _get_user(token: str):
return await models.User.get(uid=token_data.sub)


async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]) -> models.User | None:
async def get_current_user(
token: Annotated[str, Depends(oauth2_scheme)]
) -> models.User | None:
return await _get_user(token)


async def get_current_active_user(token: Annotated[str, Depends(oauth2_scheme)]) -> models.User | None:
async def get_current_active_user(
token: Annotated[str, Depends(oauth2_scheme)]
) -> models.User | None:
current_user = await _get_user(token)
if not current_user or not current_user.is_active:
return None
Expand Down
2 changes: 1 addition & 1 deletion felicity/api/gql/analysis/mutations/analysis_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def create_profile(info, payload: ProfileInputType) -> AnalysisProfileResp
)

await utils.billing_setup_profiles([profile.uid])

profile = await analysis_models.Profile.get(uid=profile.uid)
return a_types.ProfileType(**profile.marshal_simple())

Expand Down
10 changes: 5 additions & 5 deletions felicity/api/gql/analysis/mutations/analysis_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AnalysisRequestInputType:

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def create_analysis_request(
info, payload: AnalysisRequestInputType
info, payload: AnalysisRequestInputType
) -> AnalysisRequestResponse:
logger.info("Received request to create analysis request")

Expand Down Expand Up @@ -234,7 +234,7 @@ async def create_analysis_request(
update={
"analysis_uid": _service.uid,
"due_date": datetime.now()
+ timedelta(minutes=_service.tat_length_minutes)
+ timedelta(minutes=_service.tat_length_minutes)
if _service.tat_length_minutes
else None,
}
Expand All @@ -253,7 +253,7 @@ async def create_analysis_request(
uid=analysis_request.uid, related=["samples"]
)

#
#
await bill_order(analysis_request, auto_bill=True)

return a_types.AnalysisRequestWithSamples(**analysis_request.marshal_simple())
Expand Down Expand Up @@ -413,7 +413,7 @@ async def verify_samples(info, samples: List[str]) -> SampleActionResponse:

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def reject_samples(
info, samples: List[SampleRejectInputType]
info, samples: List[SampleRejectInputType]
) -> SampleActionResponse:
is_authenticated, felicity_user = await auth_from_info(info)
verify_user_auth(
Expand Down Expand Up @@ -456,7 +456,7 @@ async def reject_samples(

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def publish_samples(
info, samples: List[SamplePublishInputType]
info, samples: List[SamplePublishInputType]
) -> SuccessErrorResponse:
is_authenticated, felicity_user = await auth_from_info(info)
verify_user_auth(
Expand Down
16 changes: 10 additions & 6 deletions felicity/api/gql/analysis/mutations/analysis_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,17 @@ async def create_analysis(info, payload: AnalysisInputType) -> ProfilesServiceRe

analysis = await analysis_models.Analysis.get(uid=analysis.uid)
profiles = await analysis_models.Profile.get_all(analyses___uid=analysis.uid)

await utils.billing_setup_analysis([analysis.uid])

return a_types.AnalysisWithProfiles(**{**analysis.marshal_simple(), "profiles": profiles})
return a_types.AnalysisWithProfiles(
**{**analysis.marshal_simple(), "profiles": profiles}
)


@strawberry.mutation(permission_classes=[IsAuthenticated])
async def update_analysis(
info, uid: str, payload: AnalysisInputType
info, uid: str, payload: AnalysisInputType
) -> ProfilesServiceResponse:
is_authenticated, felicity_user = await auth_from_info(info)
verify_user_auth(
Expand Down Expand Up @@ -156,12 +158,14 @@ async def update_analysis(

profiles = analysis_models.Profile.get_all(analyses___uid=analysis.uid)

return a_types.AnalysisWithProfiles(**{**analysis.marshal_simple(), "profiles": profiles})
return a_types.AnalysisWithProfiles(
**{**analysis.marshal_simple(), "profiles": profiles}
)


@strawberry.mutation(permission_classes=[IsAuthenticated])
async def create_analysis_mapping(
info, payload: AnalysisMappingInputType
info, payload: AnalysisMappingInputType
) -> AnalysisMappingResponse:
is_authenticated, felicity_user = await auth_from_info(info)
verify_user_auth(
Expand Down Expand Up @@ -190,7 +194,7 @@ async def create_analysis_mapping(

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def update_analysis_mapping(
info, uid: str, payload: AnalysisMappingInputType
info, uid: str, payload: AnalysisMappingInputType
) -> AnalysisMappingResponse:
is_authenticated, felicity_user = await auth_from_info(info)
verify_user_auth(
Expand Down
2 changes: 1 addition & 1 deletion felicity/api/gql/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def auth_from_info(info) -> Tuple[bool, Optional[User]]:


def verify_user_auth(
is_auth: bool = False, user=None, err_msg: str = None
is_auth: bool = False, user=None, err_msg: str = None
) -> Tuple[bool, Optional[OperationError]]:
if not is_auth:
return False, OperationError(
Expand Down
5 changes: 1 addition & 4 deletions felicity/api/gql/billing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
TestBillEdge,
TestBillCursorPage,
TestBillTransactionType,
TestBillInvoiceType
TestBillInvoiceType,
)

billing_types = [
Expand All @@ -27,6 +27,3 @@
TestBillTransactionType,
TestBillInvoiceType,
]



76 changes: 47 additions & 29 deletions felicity/api/gql/billing/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

from api.gql.auth import auth_from_info, verify_user_auth
from api.gql.billing.types import (
ProfilePriceType, ProfileDiscountType,
AnalysisPriceType, AnalysisDiscountType,
VoucherType, VoucherCodeType,
TestBillTransactionType, TestBillType
ProfilePriceType,
ProfileDiscountType,
AnalysisPriceType,
AnalysisDiscountType,
VoucherType,
VoucherCodeType,
TestBillTransactionType,
TestBillType,
)
from api.gql.permissions import IsAuthenticated
from api.gql.types import OperationError
Expand All @@ -29,11 +33,15 @@
)

ProfileDiscountResponse = strawberry.union(
"ProfileDiscountResponse", (ProfileDiscountType, OperationError), description="" # noqa
"ProfileDiscountResponse",
(ProfileDiscountType, OperationError),
description="", # noqa
)

AnalysisDiscountResponse = strawberry.union(
"AnalysisDiscountResponse", (AnalysisDiscountType, OperationError), description="" #
"AnalysisDiscountResponse",
(AnalysisDiscountType, OperationError),
description="", #
)

VoucherResponse = strawberry.union(
Expand All @@ -45,7 +53,9 @@
)

TestBillTransactionResponse = strawberry.union(
"TestBillTransactionResponse", (TestBillTransactionType, OperationError), description="" #
"TestBillTransactionResponse",
(TestBillTransactionType, OperationError),
description="", #
)

TestBillResponse = strawberry.union(
Expand Down Expand Up @@ -107,7 +117,9 @@ class ApplyVoucherInput:
@strawberry.type
class BillingMutations:
@strawberry.mutation(permission_classes=[IsAuthenticated])
async def update_profile_price(self, info: Info, uid: str, payload: PriceInput) -> ProfilePriceResponse:
async def update_profile_price(
self, info: Info, uid: str, payload: PriceInput
) -> ProfilePriceResponse:
_, felicity_user = await auth_from_info(info)

profile_price = await models.ProfilePrice.get(uid=uid)
Expand All @@ -122,7 +134,9 @@ async def update_profile_price(self, info: Info, uid: str, payload: PriceInput)
return ProfilePriceType(**profile_price.marshal_simple())

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def update_analysis_price(self, info: Info, uid: str, payload: PriceInput) -> AnalysisPriceResponse:
async def update_analysis_price(
self, info: Info, uid: str, payload: PriceInput
) -> AnalysisPriceResponse:
_, felicity_user = await auth_from_info(info)

analysis_price = await models.AnalysisPrice.get(uid=uid)
Expand All @@ -138,7 +152,7 @@ async def update_analysis_price(self, info: Info, uid: str, payload: PriceInput)

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def update_profile_discount(
self, info, uid: str, payload: PriceDiscountInput
self, info, uid: str, payload: PriceDiscountInput
) -> ProfileDiscountResponse:
_, felicity_user = await auth_from_info(info)

Expand Down Expand Up @@ -168,13 +182,17 @@ async def update_profile_discount(
"updated_by_uid": felicity_user.uid,
}

obj_in = schemas.ProfileDiscountUpdate(**{**profile_discount.to_dict(), **update_in})
obj_in = schemas.ProfileDiscountUpdate(
**{**profile_discount.to_dict(), **update_in}
)
profile_discount = await profile_discount.update(obj_in)
return ProfileDiscountType(**profile_discount.marshal_simple(), )
return ProfileDiscountType(
**profile_discount.marshal_simple(),
)

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def update_analysis_discount(
self, info, uid: str, payload: PriceDiscountInput
self, info, uid: str, payload: PriceDiscountInput
) -> AnalysisDiscountResponse:
_, felicity_user = await auth_from_info(info)

Expand All @@ -199,13 +217,15 @@ async def update_analysis_discount(
"created_by_uid": felicity_user.uid,
"updated_by_uid": felicity_user.uid,
}
obj_in = schemas.AnalysisDiscountUpdate(**{**analysis_discount.to_dict(), **update_in})
obj_in = schemas.AnalysisDiscountUpdate(
**{**analysis_discount.to_dict(), **update_in}
)
analysis_discount = await analysis_discount.update(obj_in)
return AnalysisDiscountType(**analysis_discount.marshal_simple())

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def create_voucher(
self, info: Info, payload: VoucherInput
self, info: Info, payload: VoucherInput
) -> VoucherResponse:

is_authenticated, felicity_user = await auth_from_info(info)
Expand All @@ -219,9 +239,7 @@ async def create_voucher(

exists = await models.Voucher.get(name=payload.name)
if exists:
return OperationError(
error=f"Voucher {payload.name} already exists"
)
return OperationError(error=f"Voucher {payload.name} already exists")

incoming: dict = {
"created_by_uid": felicity_user.uid,
Expand All @@ -236,7 +254,7 @@ async def create_voucher(

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def update_voucher(
self, info, uid: str, payload: VoucherInput
self, info, uid: str, payload: VoucherInput
) -> VoucherResponse:

is_authenticated, felicity_user = await auth_from_info(info)
Expand Down Expand Up @@ -268,7 +286,7 @@ async def update_voucher(

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def create_voucher_code(
self, info: Info, payload: VoucherCodeInput
self, info: Info, payload: VoucherCodeInput
) -> VoucherCodeResponse:

is_authenticated, felicity_user = await auth_from_info(info)
Expand All @@ -282,9 +300,7 @@ async def create_voucher_code(

exists = await models.VoucherCode.get(code=payload.code)
if exists:
return OperationError(
error=f"Voucher Code {payload.code} already exists"
)
return OperationError(error=f"Voucher Code {payload.code} already exists")

incoming: dict = {
"created_by_uid": felicity_user.uid,
Expand All @@ -299,7 +315,7 @@ async def create_voucher_code(

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def update_voucher_code(
self, info, uid: str, payload: VoucherCodeInput
self, info, uid: str, payload: VoucherCodeInput
) -> VoucherCodeResponse:

is_authenticated, felicity_user = await auth_from_info(info)
Expand Down Expand Up @@ -331,7 +347,7 @@ async def update_voucher_code(

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def create_test_bill_transaction(
self, info, payload: BillTransactionInput
self, info, payload: BillTransactionInput
) -> TestBillTransactionResponse:

is_authenticated, felicity_user = await auth_from_info(info)
Expand All @@ -343,7 +359,7 @@ async def create_test_bill_transaction(
if payload.amount <= 0:
return OperationError(
error="Invalid transaction Amount.",
suggestion="Transaction amount must be greater than 0"
suggestion="Transaction amount must be greater than 0",
)

test_bill = await models.TestBill.get(uid=payload.test_bill_uid)
Expand All @@ -362,7 +378,7 @@ async def create_test_bill_transaction(

test_bill_update = {
"total_paid": test_bill.total_paid + tbt.amount,
"partial": True
"partial": True,
}
if test_bill_update["total_paid"] >= test_bill.total_charged:
test_bill_update["partial"] = False
Expand All @@ -383,7 +399,7 @@ async def create_test_bill_transaction(

@strawberry.mutation(permission_classes=[IsAuthenticated])
async def apply_voucher(
self, info, payload: ApplyVoucherInput
self, info, payload: ApplyVoucherInput
) -> TestBillTransactionResponse:

is_authenticated, felicity_user = await auth_from_info(info)
Expand All @@ -392,5 +408,7 @@ async def apply_voucher(
felicity_user,
"Only Authenticated user can add test bill transactions",
)
bill = await utils.apply_voucher(payload.voucher_code, payload.test_bill_uid, payload.customer_uid)
bill = await utils.apply_voucher(
payload.voucher_code, payload.test_bill_uid, payload.customer_uid
)
return TestBillType(**bill.marshal_simple(exclude=["orders"]))
Loading

0 comments on commit 5edeb38

Please sign in to comment.