Skip to content

Commit

Permalink
Syntax revision
Browse files Browse the repository at this point in the history
  • Loading branch information
na-stewart committed Nov 26, 2024
1 parent be1b084 commit 708db40
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion sanic_security/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async def fulfill_second_factor(request: Request) -> AuthenticationSession:
"""
authentication_session = await AuthenticationSession.decode(request)
if not authentication_session.requires_second_factor:
raise SecondFactorFulfilledError()
raise SecondFactorFulfilledError
two_step_session = await TwoStepSession.decode(request)
two_step_session.validate()
await two_step_session.check_code(request.form.get("code"))
Expand Down
4 changes: 2 additions & 2 deletions sanic_security/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def check_permissions(
logger.warning(
f"Client {get_ip(request)} attempted an unauthorized action anonymously."
)
raise AnonymousError()
raise AnonymousError
roles = await authentication_session.bearer.roles.filter(deleted=False).all()
for role in roles:
for required_permission, role_permission in zip(
Expand Down Expand Up @@ -104,7 +104,7 @@ async def check_roles(request: Request, *required_roles: str) -> AuthenticationS
logger.warning(
f"Client {get_ip(request)} attempted an unauthorized action anonymously."
)
raise AnonymousError()
raise AnonymousError
roles = await authentication_session.bearer.roles.filter(deleted=False).all()
for role in roles:
if role.name in required_roles:
Expand Down
22 changes: 11 additions & 11 deletions sanic_security/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def validate(self) -> None:
Raises:
SecurityError
"""
raise NotImplementedError()
raise NotImplementedError

@property
def json(self) -> dict:
Expand All @@ -89,7 +89,7 @@ def json(self):
}
"""
raise NotImplementedError()
raise NotImplementedError

class Meta:
abstract = True
Expand Down Expand Up @@ -148,9 +148,9 @@ def validate(self) -> None:
if self.deleted:
raise DeletedError("Account has been deleted.")
elif not self.verified:
raise UnverifiedError()
raise UnverifiedError
elif self.disabled:
raise DisabledError()
raise DisabledError

async def disable(self):
"""
Expand Down Expand Up @@ -321,12 +321,12 @@ def validate(self) -> None:
if self.deleted:
raise DeletedError("Session has been deleted.")
elif not self.active:
raise DeactivatedError()
raise DeactivatedError
elif (
self.expiration_date
and datetime.datetime.now(datetime.timezone.utc) >= self.expiration_date
):
raise ExpiredError()
raise ExpiredError

async def deactivate(self):
"""
Expand Down Expand Up @@ -416,7 +416,7 @@ async def new(
Returns:
session
"""
raise NotImplementedError()
raise NotImplementedError

@classmethod
async def get_associated(cls, account: Account):
Expand Down Expand Up @@ -525,7 +525,7 @@ async def check_code(self, code: str) -> None:
"Your code does not match verification session code."
)
else:
raise MaxedOutChallengeError()
raise MaxedOutChallengeError
else:
await self.deactivate()

Expand Down Expand Up @@ -621,7 +621,7 @@ def validate(self) -> None:
"""
super().validate()
if self.requires_second_factor:
raise SecondFactorRequiredError()
raise SecondFactorRequiredError

async def refresh(self, request: Request):
"""
Expand All @@ -642,7 +642,7 @@ async def refresh(self, request: Request):
"""
try:
self.validate()
raise NotExpiredError()
raise NotExpiredError
except ExpiredError as e:
if (
self.refresh_expiration_date
Expand Down Expand Up @@ -692,7 +692,7 @@ class Role(BaseModel):
permissions: str = fields.CharField(max_length=255, null=True)

def validate(self) -> None:
raise NotImplementedError()
raise NotImplementedError

@property
def json(self) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion sanic_security/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async def verify_account(request: Request) -> TwoStepSession:
"""
two_step_session = await TwoStepSession.decode(request)
if two_step_session.bearer.verified:
raise VerifiedError()
raise VerifiedError
two_step_session.validate()
try:
await two_step_session.check_code(request.form.get("code"))
Expand Down

0 comments on commit 708db40

Please sign in to comment.