Skip to content

Commit

Permalink
Merge pull request #548 from hbcarlos/tos
Browse files Browse the repository at this point in the history
Adds a new endpoint to check if the user already signed the TOS
  • Loading branch information
wolfv authored Jul 26, 2022
2 parents da363d5 + c28b131 commit d703fac
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies:
- s3fs
- gcsfs >=2022.03
- sphinx
- sphinx-book-theme
- sphinx-book-theme>=0.3
- tenacity
- xattr
- aiofiles
Expand Down
32 changes: 32 additions & 0 deletions plugins/quetz_tos/quetz_tos/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,38 @@ def get_current_tos(db: Session = Depends(get_db)):
)


@router.get("/api/tos/status", status_code=201, tags=['Terms of Service'])
def get_current_tos_status(
db: Session = Depends(get_db),
dao: dao.Dao = Depends(get_dao),
auth: authorization.Rules = Depends(get_rules),
):
user_id = auth.assert_user()
current_tos = (
db.query(TermsOfService).order_by(TermsOfService.time_created.desc()).first()
)
if current_tos:
signature = (
db.query(TermsOfServiceSignatures)
.filter(TermsOfServiceSignatures.user_id == user_id)
.filter(TermsOfServiceSignatures.tos_id == current_tos.id)
.one_or_none()
)
if signature:
return {
"tos_id": str(uuid.UUID(bytes=signature.tos_id)),
"user_id": str(uuid.UUID(bytes=signature.user_id)),
"time_created": signature.time_created,
}
else:
return None
else:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="terms of service file not found",
)


@router.post("/api/tos/sign", status_code=201, tags=['Terms of Service'])
def sign_current_tos(
tos_id: str = "",
Expand Down
6 changes: 4 additions & 2 deletions quetz/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,13 @@ def test_create_exists_errors(cli_args):
"""Create command raises if deployment exists and not force deleted."""
with mock.patch("quetz.cli._is_deployment", lambda x: True):
res = runner.invoke(cli.app, cli_args)
print(res.output)
assert res.exit_code == 1
assert (
res.output == "Use the start command to start a deployment "
"or specify --delete with --copy-conf or --create-conf.\nAborted!\n"
"Use the start command to start a deployment or specify"
" --delete with --copy-conf or --create-conf." in res.output
)
assert "Aborted" in res.output


@pytest.fixture()
Expand Down

0 comments on commit d703fac

Please sign in to comment.