Skip to content

Commit

Permalink
Merge branch 'dev' into DDS-1680-endpoint-for-failed-add-to-db-files
Browse files Browse the repository at this point in the history
  • Loading branch information
i-oden authored Oct 30, 2023
2 parents ec3ac7f + f32c284 commit 6eb946e
Show file tree
Hide file tree
Showing 8 changed files with 551 additions and 9 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
==========

.. _2.5.2:

2.5.2 - 2023-10-25
~~~~~~~~~~~~~~~~~~~~~

- Users can revoke project access given to unaccepted invites (e.g. after a mistake).
- Email layout changed. When project is released, important information is now highlighted, and the Project Title is displayed along with the DDS project ID.
- New endpoint `ProjectStatus.patch`: Unit Admins / Personnel can extend the project deadline.

.. _2.5.1:

2.5.1 - 2023-09-27
Expand Down
9 changes: 7 additions & 2 deletions SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,23 @@ _Nothing merged in CLI during this sprint_
- Dependency: Bump `MariaDB` to LTS version 10.11.5 ([#1465](https://github.com/ScilifelabDataCentre/dds_web/pull/1465))
- Bug fixed: Row in `ProjectUsers` should also be added if it doesn't exist when giving Researcher access to a specific project ([#1464](https://github.com/ScilifelabDataCentre/dds_web/pull/1464))
- Workflow: Update PR template and clarify sections ([#1467](https://github.com/ScilifelabDataCentre/dds_web/pull/1467))
- Revoke project access for unaccepted invites ([#1192])(https://scilifelab.atlassian.net/jira/software/projects/DDS/boards/13/backlog?epics=visible&selectedIssue=DDS-1192)

# 2023-09-18 - 2023-09-29

- Column `sto4_start_time` is automatically set when the create-unit command is run ([#1668])(https://scilifelab.atlassian.net/jira/software/projects/DDS/boards/13?selectedIssue=DDS-1668)
- Column `sto4_start_time` is automatically set when the create-unit command is run ([#1469](https://github.com/ScilifelabDataCentre/dds_web/pull/1469))
- Replace expired invites when there's a new invitation attempt ([#1466](https://github.com/ScilifelabDataCentre/dds_web/pull/1466))
- New version: 2.5.1 ([#1471](https://github.com/ScilifelabDataCentre/dds_web/pull/1471))
- Revoke project access for unaccepted invites ([#1468](https://github.com/ScilifelabDataCentre/dds_web/pull/1468))

# 2023-10-02 - 2023-10-13

- Project title displayed along with the internal project ID email sent when a project is released ([#1475](https://github.com/ScilifelabDataCentre/dds_web/pull/1475))
- Use full DDS name in MOTD email subject ([#1477](https://github.com/ScilifelabDataCentre/dds_web/pull/1477))
- Add flag --verify-checksum to the comand in email template ([#1478])(https://github.com/ScilifelabDataCentre/dds_web/pull/1478)
- Improved email layout; Highlighted information and commands when project is released ([#1479])(https://github.com/ScilifelabDataCentre/dds_web/pull/1479)

# 2023-10-16 - 2023-11-03 (Longer sprint due to OKR prep and höstlov)

- Added new API endpoint ProjectStatus.patch to extend the deadline ([#1480])(https://github.com/ScilifelabDataCentre/dds_web/pull/1480)
- New version: 2.5.2 ([#1482](https://github.com/ScilifelabDataCentre/dds_web/pull/1482))
- New endpoint `AddFailedFiles` for adding failed files to database ([#1472])(https://github.com/ScilifelabDataCentre/dds_web/pull/1472)
129 changes: 129 additions & 0 deletions dds_web/api/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,135 @@ def post(self):

return {"message": return_message}

@auth.login_required(role=["Unit Admin", "Unit Personnel"])
@logging_bind_request
@json_required
@handle_validation_errors
@handle_db_error
def patch(self):
"""Partially update a the project status"""
# Get project ID, project and verify access
project_id = dds_web.utils.get_required_item(obj=flask.request.args, req="project")
project = dds_web.utils.collect_project(project_id=project_id)
dds_web.utils.verify_project_access(project=project)

# Get json input from request
json_input = flask.request.get_json(silent=True) # Already checked by json_required

# the status has changed at least two times,
# next time the project expires it wont change again -> error
if project.times_expired >= 2:
raise DDSArgumentError(
"Project availability limit: The maximum number of changes in data availability has been reached."
)

# Operation must be confirmed by the user - False by default
confirmed_operation = json_input.get("confirmed", False)
if not isinstance(confirmed_operation, bool):
raise DDSArgumentError(message="`confirmed` is a boolean value: True or False.")
if not confirmed_operation:
warning_message = "Operation must be confirmed before proceding."
# When not confirmed, return information about the project
project_info = ProjectInfo().get()
project_status = self.get()
json_returned = {
**project_info,
"project_status": project_status,
"warning": warning_message,
"default_unit_days": project.responsible_unit.days_in_available,
}
return json_returned

# Cannot change project status if project is busy
if project.busy:
raise ProjectBusyError(
message=(
f"The deadline for the project '{project_id}' is already in the process of being changed. "
"Please try again later. \n\nIf you know that the project is not busy, contact support."
)
)

self.set_busy(project=project, busy=True)

# Extend deadline
try:
new_deadline_in = json_input.get(
"new_deadline_in", None
) # if not provided --> is None -> deadline is not updated

# some variable definition
send_email = False
default_unit_days = project.responsible_unit.days_in_available

# Update the deadline functionality
if new_deadline_in:
# deadline can only be extended from Available
if not project.current_status == "Available":
raise DDSArgumentError(
"You can only extend the deadline for a project that has the status 'Available'."
)

if type(new_deadline_in) is not int:
raise DDSArgumentError(
message="The deadline attribute passed should be of type Int (i.e a number)."
)

# New deadline shouldnt surpass the default unit days
if new_deadline_in > default_unit_days:
raise DDSArgumentError(
message=f"You requested the deadline to be extended {new_deadline_in} days. The number of days has to be lower than the default deadline extension number of {default_unit_days} days"
)

# the new deadline + days left shouldnt surpass 90 days
curr_date = dds_web.utils.current_time()
current_deadline = (project.current_deadline - curr_date).days
if new_deadline_in + current_deadline > 90:
raise DDSArgumentError(
message=f"You requested the deadline to be extended with {new_deadline_in} days (from {current_deadline}), giving a new total deadline of {new_deadline_in + current_deadline} days. The new deadline needs to be less than (or equal to) 90 days."
)
try:
# add a fake expire status to mimick a re-release in order to have an udpated deadline
curr_date = (
dds_web.utils.current_time()
) # call current_time before each call so it is stored with different timestamps
new_status_row = self.expire_project(
project=project,
current_time=curr_date,
deadline_in=1, # some dummy deadline bc it will re-release now again
)
project.project_statuses.append(new_status_row)

curr_date = (
dds_web.utils.current_time()
) # call current_time before each call so it is stored with different timestamps
new_status_row = self.release_project(
project=project,
current_time=curr_date,
deadline_in=new_deadline_in + current_deadline,
)
project.project_statuses.append(new_status_row)

project.busy = False # return to not busy
db.session.commit()

except (sqlalchemy.exc.OperationalError, sqlalchemy.exc.SQLAlchemyError) as err:
flask.current_app.logger.exception("Failed to extend deadline")
db.session.rollback()
raise

return_message = (
f"The project '{project.public_id}' has been given a new deadline. "
f"An e-mail notification has{' not ' if not send_email else ' '}been sent."
)
else:
# leave it for future new functionality of updating the status
return_message = "Nothing to update."
except:
self.set_busy(project=project, busy=False)
raise

return {"message": return_message}

@staticmethod
@dbsession
def set_busy(project: models.Project, busy: bool) -> None:
Expand Down
2 changes: 1 addition & 1 deletion dds_web/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.5.1"
__version__ = "2.5.2"
10 changes: 5 additions & 5 deletions doc/procedures/new_release.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# How to create a new release

1. Create a PR from `dev` to `master`: "New release"
2. Confirm that the development instance works and that the newest changes have been deployed
2. Confirm that the development instance works and that the newest changes have been deployed. If not, make a new redeployment of dds-dev (via argocd).

1. _In general_, e.g. that it's up and running
2. _Specific feature has been added or changed:_ Confirm that it also works in the development instance
3. _The change is in the API:_ Confirm that the development instance works together with the CLI

3. Fork a new branch from `dev`
4. Update the version [changelog](../../CHANGELOG.rst)
3. Fork a new branch from `dev` (locally)
4. Update the version [changelog](../../CHANGELOG.rst), located at `dds_web/CHANGELOG.rst`

**Tip:** Use the PR to `master` to see all changes since last release.

Expand All @@ -20,12 +20,12 @@

- _Minor changes, e.g. bug fix_: Minor version upgrade, e.g. `1.0.1 --> 1.0.2`
- _Small changes, e.g. new feature_: Mid version upgrade, e.g. `1.1.0 --> 1.2.0`
- _Breaking changes or large new feature(s)_: Major version upgrade, e.g. `1.0.0 --> 2.0.0`
- _Breaking changes or large new feature(s)_: Major version upgrade, e.g. `1.0.0 --> 2.0.0` _AVOID THIS -- NEED TO INFORM USERS WELL IN ADVANCE IN THAT CASE SINCE IT WILL BLOCK THE USERS FROM USING ANY OLDER VERSIONS_

> Will break if CLI version not bumped as well
6. Push version change to branch
7. Create a new PR from `<your-branch>` to `dev`
7. Create a new PR from `<your-branch>` to `dev`: "New version & changelog"

Wait for approval and merge by Product Owner or admin.

Expand Down
25 changes: 25 additions & 0 deletions doc/status_codes_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,31 @@
- `archive_project`
- Database or S3 issues

#### `patch`

- [Authentication errors](#authentication)
- `400 Bad Request`
- Decorators
- Json required but not provided
- Validation error
- Schemas
- Project does not exist
- Project is busy
- `extend_deadline`
- Invalid deadline
- No deadline provided
- Project is not in Available state
- Max number of times available reached
- `403 Forbidden`
- Schemas
- User does not have access to project
- `500 Internal Server Error`
- Database errors
- `delete_project`
- Database or S3 issues
- `archive_project`
- Database or S3 issues

### GetPublic

- [Authentication errors](#authentication)
Expand Down
Loading

0 comments on commit 6eb946e

Please sign in to comment.