Skip to content

Commit

Permalink
Merge pull request #134 from cznethub/submission-delete
Browse files Browse the repository at this point in the history
Submission delete
  • Loading branch information
sblack-usu authored Sep 27, 2022
2 parents 8be2df2 + 90a2e46 commit 7eff226
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
11 changes: 9 additions & 2 deletions dspback/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,24 @@ async def get_current_user(
payload = jwt.decode(token, settings.jwt_secret_key, algorithms=[settings.jwt_algorithm])
token_data = TokenData(**payload)
if token_data.orcid is None:
credentials_exception.detail = "Token is missing the orcid"
raise credentials_exception
if token_data.expiration < datetime.utcnow().timestamp():
# TODO register token in db for requested expiration
credentials_exception.detail = "Token is expired"
raise credentials_exception
except JWTError:
except JWTError as e:
credentials_exception.detail = f"Exception occurred while decoding token [{str(e)}]"
raise credentials_exception
user: UserTable = get_user_table(db, orcid=token_data.orcid)
if user is None:
credentials_exception.detail = f"No user found for orcid {token_data.orcid}"
raise credentials_exception
if not user.access_token or user.access_token != token:
if not user.access_token:
credentials_exception.detail = "Access token is missing"
raise credentials_exception
if user.access_token != token:
credentials_exception.detail = "Access token is invalid"
raise credentials_exception
return user

Expand Down
6 changes: 3 additions & 3 deletions dspback/routers/earthchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ async def get_metadata_repository(self, request: Request, identifier) -> respons
description="Deletes the EarthChem record along with the submission record.",
)
async def delete_metadata_repository(self, request: Request, identifier):
delete_submission(self.db, self.repository_type, identifier, self.user)

access_token = await self.access_token(request)
response = requests.delete(
self.delete_url % str(identifier),
headers={"accept": "application/json", "Authorization": "Bearer " + str(access_token)},
)
if response.status_code == 403:
if response.status_code >= 300:
raise RepositoryException(status_code=response.status_code, detail=response.text)

delete_submission(self.db, self.repository_type, identifier, self.user)

@router.put(
'/submit/earthchem/{identifier}',
name="submit",
Expand Down
6 changes: 3 additions & 3 deletions dspback/routers/hydroshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ async def get_metadata_repository(self, request: Request, identifier):
description="Deletes the HydroShare resource along with the submission record.",
)
async def delete_metadata_repository(self, request: Request, identifier):
delete_submission(self.db, self.repository_type, identifier, self.user)

access_token = await self.access_token(request)
response = requests.delete(self.delete_url % identifier, params={"access_token": access_token})

if response.status_code == 403:
if response.status_code >= 300:
raise RepositoryException(status_code=response.status_code, detail=response.text)

delete_submission(self.db, self.repository_type, identifier, self.user)

@router.put(
'/submit/hydroshare/{identifier}',
name="submit",
Expand Down
6 changes: 3 additions & 3 deletions dspback/routers/zenodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ async def get_metadata_repository(self, request: Request, identifier):
description="Deletes the Zenodo record along with the submission record.",
)
async def delete_metadata_repository(self, request: Request, identifier):
delete_submission(self.db, self.repository_type, identifier, self.user)

access_token = await self.access_token(request)
response = requests.delete(self.delete_url % identifier, params={"access_token": access_token})
if response.status_code == 403:
if response.status_code >= 300:
raise RepositoryException(status_code=response.status_code, detail=response.text)

delete_submission(self.db, self.repository_type, identifier, self.user)

@router.put(
'/submit/zenodo/{identifier}',
name="submit",
Expand Down

0 comments on commit 7eff226

Please sign in to comment.