Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dds 1690 -- New cli command: dds project status extend #661

Merged
merged 36 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b995218
started command
rv0lt Oct 16, 2023
89c7144
second call
rv0lt Oct 16, 2023
0f58043
added tests
rv0lt Oct 17, 2023
363f153
docstring
rv0lt Oct 17, 2023
2e25400
pylint
rv0lt Oct 17, 2023
4a12d23
tests!
rv0lt Oct 17, 2023
9b27bda
missing test
rv0lt Oct 17, 2023
7503833
missing test
rv0lt Oct 17, 2023
baaa98f
sprintlog
rv0lt Oct 17, 2023
ed779e8
prettier
rv0lt Oct 18, 2023
67db194
better coments
rv0lt Oct 18, 2023
b8cc80b
line too long
rv0lt Oct 18, 2023
31fbb36
Merge branch 'dev' into DDS-1690-New-CLI-command-dds-project-status-e…
rv0lt Oct 19, 2023
9167102
prettier
rv0lt Oct 19, 2023
f5829a0
Update SPRINTLOG.md
rv0lt Oct 20, 2023
fd469d7
Update dds_cli/project_status.py
rv0lt Oct 20, 2023
86039bd
Update dds_cli/project_status.py
rv0lt Oct 20, 2023
68d317c
Update dds_cli/project_status.py
rv0lt Oct 20, 2023
f83a1cf
feedback
rv0lt Oct 20, 2023
06949d5
pylint
rv0lt Oct 20, 2023
f047fb0
pylint
rv0lt Oct 20, 2023
3f514d3
pylint
rv0lt Oct 20, 2023
c1206f7
Update dds_cli/__main__.py
rv0lt Oct 20, 2023
42cd8bd
Update dds_cli/project_status.py
rv0lt Oct 20, 2023
ddb2db7
Update dds_cli/project_status.py
rv0lt Oct 20, 2023
12ade91
Update dds_cli/project_status.py
rv0lt Oct 20, 2023
693155a
feedback
rv0lt Oct 23, 2023
59e42f7
Update dds_cli/project_status.py
rv0lt Oct 23, 2023
ff58777
Update dds_cli/project_status.py
rv0lt Oct 23, 2023
d81c251
Update dds_cli/project_status.py
rv0lt Oct 23, 2023
61835ab
Update dds_cli/project_status.py
rv0lt Oct 23, 2023
2f10d1f
feedback
rv0lt Oct 23, 2023
8a20679
Update dds_cli/project_status.py
rv0lt Oct 23, 2023
ea57cef
black
rv0lt Oct 23, 2023
a47159b
Update dds_cli/project_status.py
rv0lt Oct 24, 2023
eaa7e4a
format date
rv0lt Oct 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,5 @@ _Nothing merged in CLI during this sprint_

# 2023-10-16 - 2023-10-27

- Change "Checksum verification successful. File integrity verified." logging level from INFO to DEBUG in order to not print for all files ([#662])(https://github.com/ScilifelabDataCentre/dds_cli/pull/661)
- Change "Checksum verification successful. File integrity verified." logging level from INFO to DEBUG in order to not print for all files ([#662])(https://github.com/ScilifelabDataCentre/dds_cli/pull/662)
- New command `dds project status extend` to allow extension of project deadline ([#661])(https://github.com/ScilifelabDataCentre/dds_cli/pull/661)
34 changes: 34 additions & 0 deletions dds_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,40 @@ def delete_project(click_ctx, project: str):
sys.exit(1)


# -- dds project status extend -- #
@project_status.command(name="extend", no_args_is_help=True)
# Options
@project_option(required=True)
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
@click.option(
"--new-deadline",
required=False,
type=int,
help="Number of days to extend the deadline.",
)
@click.pass_obj
def extend_deadline(click_ctx, project: str, new_deadline: int):
"""Extend a project deadline by an specified number of days.

It consumes one of allowed times to renew data access.
"""
try:
with dds_cli.project_status.ProjectStatusManager(
project=project,
no_prompt=click_ctx.get("NO_PROMPT", False),
token_path=click_ctx.get("TOKEN_PATH"),
) as updater:
updater.extend_deadline(new_deadline=new_deadline)
except (
dds_cli.exceptions.APIError,
dds_cli.exceptions.AuthenticationError,
dds_cli.exceptions.DDSCLIException,
dds_cli.exceptions.ApiResponseError,
dds_cli.exceptions.ApiRequestError,
) as err:
LOG.error(err)
sys.exit(1)


# -- dds project status busy -- #
@project_status.command(name="busy", no_args_is_help=False)
# Flags
Expand Down
112 changes: 112 additions & 0 deletions dds_cli/project_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import typing
import sys
from dateutil.parser import parse

# Installed
import pytz
Expand Down Expand Up @@ -148,6 +149,117 @@ def update_status(self, new_status, deadline=None, is_aborted=False, no_mail=Fal

dds_cli.utils.console.print(f"Project {response_json.get('message')}")

def extend_deadline(self, new_deadline=None):
"""Extend the project deadline."""
# Define initial parameters
extra_params = {"send_email": False}

# Fetch project status and default deadline
response_json, _ = dds_cli.utils.perform_request(
endpoint=DDSEndpoint.UPDATE_PROJ_STATUS,
headers=self.token,
method="patch",
params={"project": self.project},
json=extra_params,
error_message="Failed to extend project deadline",
)

# Structure of the response:
# {
# 'default_unit_days': 30,
# 'project_info': {
# 'Created by': 'First Unit User',
# 'Description': 'This is a test project',
# 'Last updated': 'Wed, 18 Oct 2023 08:40:43 GMT',
# 'PI': '[email protected]',
# 'Project ID': 'project_1',
# 'Size': 0,
# 'Status': 'Available',
# 'Title': 'First Project'
# },
# 'project_status': {
# 'current_deadline': 'Sat, 04 Nov 2023 23:59:59 GMT',
# 'current_status': 'Available'},
# }

# Check that the returned information was ok
keys = ["project_info", "project_status", "default_unit_days"]
(
project_info,
project_status,
default_unit_days,
*_,
) = dds_cli.utils.get_required_in_response(keys=keys, response=response_json)

# Check and extract the required information for the operation
current_status, *_ = dds_cli.utils.get_required_in_response(
keys=["current_status"], response=project_status
)

# if the project is still in progress it won't have a current_deadline parameter
if not current_status == "Available":
raise exceptions.DDSCLIException(
"You can only extend the deadline for a project that has the status 'Available'."
)

current_deadline, *_ = dds_cli.utils.get_required_in_response(
keys=["current_deadline"], response=project_status
)
project_id, *_ = dds_cli.utils.get_required_in_response(
keys=["Project ID"], response=project_info
)

# print information about the project status and table with the project info
print_info = (
f"\nCurrent deadline: [b][green]{current_deadline}[/green][/b]\n"
f"Default deadline extension: [b][green]{default_unit_days}[/green][/b] days\n"
)
table = self.generate_project_table(project_info=project_info)
dds_cli.utils.console.print(table)
dds_cli.utils.console.print(print_info)

# If it wasnt provided during the command click, ask the user for the new deadline
if not new_deadline:
# Question number of days to extend the deadline
prompt_question = (
"How many days would you like to extend the project deadline with? "
"Leave empty in order to choose the default"
)
new_deadline = rich.prompt.IntPrompt.ask(prompt_question, default=default_unit_days)
i-oden marked this conversation as resolved.
Show resolved Hide resolved

# Confirm operation question
new_deadline_date = parse(current_deadline) + datetime.timedelta(days=new_deadline)
new_deadline_date = new_deadline_date.strftime("%d/%m/%Y, %H:%M:%S")
i-oden marked this conversation as resolved.
Show resolved Hide resolved
prompt_question = (
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
f"\nThe new deadline for project {project_id} will be: [b][blue]{new_deadline_date}[/b][/blue]"
"\n\n[b][blue]Are you sure [/b][/blue]you want to perform this operation? "
"\nYou can only extend the data availability a maximum of "
"[b][blue]3 times[/b][/blue], this consumes one of those times."
)

if not rich.prompt.Confirm.ask(prompt_question):
LOG.info("Probably for the best. Exiting.")
sys.exit(0)

# Update parameters for the second request
extra_params = {**extra_params, "confirmed": True, "new_deadline_in": new_deadline}

response_json, _ = dds_cli.utils.perform_request(
endpoint=DDSEndpoint.UPDATE_PROJ_STATUS,
headers=self.token,
method="patch",
params={"project": self.project},
json=extra_params,
rv0lt marked this conversation as resolved.
Show resolved Hide resolved
error_message="Failed to extend project deadline",
)
message = response_json.get("message")
if not message:
raise exceptions.DDSCLIException(
"No message returned from API. Cannot verify extension of project deadline."
)

LOG.info(message)


class ProjectBusyStatusManager(base.DDSBaseClass):
"""Project Busy Status manager class."""
Expand Down
2 changes: 2 additions & 0 deletions dds_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def perform_request(
request_method = requests.post
elif method == "delete":
request_method = requests.delete
elif method == "patch":
request_method = requests.patch

def transform_paths(json_input):
"""Make paths serializable."""
Expand Down
Loading
Loading