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

New release #1481

Merged
merged 174 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
5f97e93
Revoke project access for invited email
rv0lt Sep 14, 2023
aef7c3d
Revoke project access for invited email
rv0lt Sep 14, 2023
9039db0
started testing
rv0lt Sep 15, 2023
05ed50b
tests
rv0lt Sep 18, 2023
d3bfbde
Merge branch 'dev' into DDS-1192-Revoke-project-access-for-invited-email
rv0lt Sep 18, 2023
a0d4aaa
sprintlog and prettier
rv0lt Sep 18, 2023
eb0edf9
testing msg fixed
rv0lt Sep 18, 2023
1a69114
Update test_project_access.py
rv0lt Sep 18, 2023
9e68768
testing
rv0lt Sep 18, 2023
7d55d52
Merge branch 'DDS-1192-Revoke-project-access-for-invited-email' of gi…
rv0lt Sep 18, 2023
53c56dd
improved tests
rv0lt Sep 18, 2023
52b962d
black
rv0lt Sep 18, 2023
bff698e
Added more comments
rv0lt Sep 19, 2023
20fcf2e
black
rv0lt Sep 19, 2023
a1f9a76
checks that it wasn't the only invite
rv0lt Sep 19, 2023
ac7e825
checks that it wasn't the only invite
rv0lt Sep 19, 2023
01f6309
Update dds_web/api/user.py
rv0lt Sep 20, 2023
8577bc7
Update dds_web/api/user.py
rv0lt Sep 20, 2023
4e0aa63
Update dds_web/api/user.py
rv0lt Sep 20, 2023
988597c
refactoring
rv0lt Sep 21, 2023
6f7d890
added logic for hierarchy
rv0lt Sep 21, 2023
c83e6f3
hierarchy functionaly logic added, todo to implement
rv0lt Sep 21, 2023
7f43395
hierarchy
rv0lt Sep 22, 2023
8e4b175
black
rv0lt Sep 22, 2023
24285a8
Merge branch 'dev' into DDS-1192-Revoke-project-access-for-invited-email
rv0lt Sep 22, 2023
e9f1e0a
added
rv0lt Sep 22, 2023
3472457
Merge branch 'DDS-1192-Revoke-project-access-for-invited-email' of gi…
rv0lt Sep 22, 2023
3cb1d28
more tests and removed unnecesary code
rv0lt Sep 25, 2023
4f26365
more tests and removed unnecesary code
rv0lt Sep 25, 2023
7e437c2
forgot to change testfile
rv0lt Sep 25, 2023
c7a3577
checks for unanswered invites of personel
rv0lt Sep 25, 2023
5bb88f5
black
rv0lt Sep 25, 2023
f9fe644
Merge branch 'dev' into DDS-1192-Revoke-project-access-for-invited-email
rv0lt Sep 25, 2023
94bc466
black
rv0lt Sep 25, 2023
c0ecaae
more explicate error message
rv0lt Sep 25, 2023
91159fe
more explicate error message
rv0lt Sep 25, 2023
84a92c5
better coments
rv0lt Sep 25, 2023
bd6dcd0
Update dds_web/api/user.py
rv0lt Sep 25, 2023
f95bc06
Update dds_web/api/user.py
rv0lt Sep 25, 2023
95a36e8
Update dds_web/api/user.py
rv0lt Sep 25, 2023
ffd00cb
Update dds_web/api/user.py
rv0lt Sep 25, 2023
6d96fb1
Update dds_web/api/user.py
rv0lt Sep 25, 2023
822b080
Update dds_web/api/user.py
rv0lt Sep 25, 2023
dced7de
Update dds_web/api/user.py
rv0lt Sep 25, 2023
c4821dc
Update dds_web/api/user.py
rv0lt Sep 25, 2023
ebf8ff0
black
rv0lt Sep 25, 2023
cf97483
new test comment
rv0lt Sep 25, 2023
0a3a35a
fixed strings
rv0lt Sep 26, 2023
f952f30
refactoring test
rv0lt Sep 26, 2023
8f8001f
refactoring more test
rv0lt Sep 26, 2023
f70f5ba
Update SPRINTLOG.md
rv0lt Sep 27, 2023
e90f7cb
Update dds_web/api/user.py
rv0lt Sep 27, 2023
1c49497
Update tests/test_project_access.py
rv0lt Sep 27, 2023
4c09789
Update tests/test_project_access.py
rv0lt Sep 27, 2023
1c3bab6
Update tests/test_project_access.py
rv0lt Sep 27, 2023
241647b
black and comments
rv0lt Sep 27, 2023
cd891b2
moved tests
rv0lt Sep 27, 2023
8685e4a
updated tes
rv0lt Sep 27, 2023
4b6c102
Update tests/api/test_user.py
rv0lt Sep 27, 2023
26a88f1
Update tests/api/test_user.py
rv0lt Sep 27, 2023
6a28cae
Update tests/api/test_user.py
rv0lt Sep 27, 2023
daaeeed
Update tests/test_user_remove_association.py
rv0lt Sep 27, 2023
38d4268
Update tests/test_project_access.py
rv0lt Sep 27, 2023
e5bfb52
Update tests/api/test_user.py
rv0lt Sep 27, 2023
2a1b178
Merge pull request #1468 from ScilifelabDataCentre/DDS-1192-Revoke-pr…
rv0lt Sep 27, 2023
88254d2
comment about whitelisted IPs
i-oden Sep 28, 2023
e8688e3
Merge pull request #1474 from ScilifelabDataCentre/add-comment-about-…
i-oden Sep 28, 2023
70e5d60
new info
rv0lt Oct 3, 2023
30465f2
txt templatw
rv0lt Oct 3, 2023
2364ced
test email
rv0lt Oct 4, 2023
c837830
changed client
rv0lt Oct 4, 2023
c45a2e5
added tests
rv0lt Oct 4, 2023
1528839
Merge branch 'dev' into DDS-1537-Add-title-to-the-autogenerated-email…
rv0lt Oct 4, 2023
5279325
Merge branch 'DDS-1537-Add-title-to-the-autogenerated-email-sent-to-u…
rv0lt Oct 5, 2023
e5bbc5d
tryit
rv0lt Oct 5, 2023
353ad73
black
rv0lt Oct 5, 2023
9ee7ae2
changes to module client
rv0lt Oct 5, 2023
dd394b7
completed test
rv0lt Oct 5, 2023
7ba7703
black
rv0lt Oct 5, 2023
4eee28e
files
rv0lt Oct 5, 2023
5527e12
sprintlog and change int
rv0lt Oct 5, 2023
f7a770b
black
rv0lt Oct 5, 2023
caba690
sprintlog and move test
rv0lt Oct 5, 2023
9eb94c5
last test
rv0lt Oct 5, 2023
2038b39
refactoring
rv0lt Oct 5, 2023
55727c5
Update SPRINTLOG.md
rv0lt Oct 5, 2023
ca812f3
Update dds_web/templates/mail/project_release.html
rv0lt Oct 5, 2023
264fbe2
Update dds_web/templates/mail/project_release.html
rv0lt Oct 5, 2023
7894f51
Update SPRINTLOG.md
rv0lt Oct 5, 2023
c615136
Update tests/api/test_superadmin_only.py
rv0lt Oct 5, 2023
bbb498f
Merge pull request #1475 from ScilifelabDataCentre/DDS-1537-Add-title…
rv0lt Oct 6, 2023
ecd0864
Merge branch 'dev' into DDS-1422-Change-email-message-to-Important-in…
rv0lt Oct 6, 2023
fbd6efe
Update SPRINTLOG.md
rv0lt Oct 6, 2023
b14b1cf
Merge pull request #1477 from ScilifelabDataCentre/DDS-1422-Change-em…
rv0lt Oct 6, 2023
bc389e9
new templates
rv0lt Oct 6, 2023
972f9d7
springlog
rv0lt Oct 6, 2023
2bdd4ce
correct sprintlog
rv0lt Oct 6, 2023
fe4d13d
Merge pull request #1478 from ScilifelabDataCentre/DDS-1409-Add-verif…
rv0lt Oct 6, 2023
e986301
modified files for functionality
rv0lt Oct 9, 2023
720e504
new tests
rv0lt Oct 9, 2023
43c45e2
test
rv0lt Oct 9, 2023
c49699b
springlog
rv0lt Oct 9, 2023
724322d
new functionality
rv0lt Oct 9, 2023
ef340d2
started tests
rv0lt Oct 9, 2023
ffa340b
status code
rv0lt Oct 10, 2023
096ba14
Update SPRINTLOG.md
rv0lt Oct 10, 2023
44bdf81
Update dds_web/templates/mail/project_release.html
rv0lt Oct 10, 2023
492b790
added feedback
rv0lt Oct 10, 2023
700f8c1
feedback
rv0lt Oct 10, 2023
5df28d6
finalized tests
rv0lt Oct 10, 2023
a4c0885
Update dds_web/templates/mail/project_release.html
rv0lt Oct 10, 2023
138fd01
feedback
rv0lt Oct 10, 2023
33c3cbb
Update dds_web/templates/mail/project_release.html
rv0lt Oct 10, 2023
ddc25b7
Update dds_web/templates/mail/project_release.html
rv0lt Oct 10, 2023
fc6efa4
feedback
rv0lt Oct 10, 2023
294d9b7
fix test
rv0lt Oct 10, 2023
739bbb4
Update dds_web/templates/mail/project_release.html
rv0lt Oct 10, 2023
3db8026
Update dds_web/templates/mail/project_release.html
rv0lt Oct 10, 2023
ca1fd42
updated txt
rv0lt Oct 10, 2023
fdca870
Update test_project.py
rv0lt Oct 10, 2023
9c3805a
change fixture
rv0lt Oct 10, 2023
e9a0d1d
Merge pull request #1479 from ScilifelabDataCentre/DDS-1338-Improve-o…
rv0lt Oct 10, 2023
996cc08
go back to first approach of test
rv0lt Oct 10, 2023
c410d46
improved
rv0lt Oct 11, 2023
52e8e5c
Merge branch 'dev' into DDS-1691-New-API-endpoint-ProjectStatus.put
rv0lt Oct 11, 2023
0ad3d5d
better comments
rv0lt Oct 11, 2023
c7976cb
more coverage
rv0lt Oct 12, 2023
19ec5e2
coverage
rv0lt Oct 12, 2023
fa4c46c
sprintlog
rv0lt Oct 13, 2023
261fbcf
Update dds_web/api/project.py
rv0lt Oct 13, 2023
0b531b5
Update dds_web/api/project.py
rv0lt Oct 13, 2023
5cca377
Update dds_web/api/project.py
rv0lt Oct 13, 2023
a8efc2e
Update dds_web/api/project.py
rv0lt Oct 13, 2023
7cb1d43
modified test according to comments
rv0lt Oct 13, 2023
a393914
modified test according to comments
rv0lt Oct 13, 2023
125e665
Update dds_web/api/project.py
rv0lt Oct 13, 2023
96e7368
Update dds_web/api/project.py
rv0lt Oct 13, 2023
55d40a9
Update dds_web/api/project.py
rv0lt Oct 13, 2023
4f26b2d
modified acording to comments
rv0lt Oct 13, 2023
4141b12
small fix
rv0lt Oct 13, 2023
1d0478c
black
rv0lt Oct 13, 2023
0f0bb1f
unconfirmed returns project info
rv0lt Oct 16, 2023
0cab328
changelog
i-oden Oct 17, 2023
ee23e09
update release info
i-oden Oct 17, 2023
40696ed
version
i-oden Oct 17, 2023
e042eca
sprintlog
i-oden Oct 17, 2023
5df20c9
Update dds_web/api/project.py
rv0lt Oct 17, 2023
69693d5
Update dds_web/api/project.py
rv0lt Oct 17, 2023
470b3a1
moved set busy
rv0lt Oct 17, 2023
29d8eda
rollout
rv0lt Oct 19, 2023
4f4ff91
Update SPRINTLOG.md
rv0lt Oct 20, 2023
ca97094
new exceptions
rv0lt Oct 23, 2023
7cc7b17
new exceptions
rv0lt Oct 23, 2023
806e12c
default unti days
rv0lt Oct 23, 2023
181ebbc
Update dds_web/api/project.py
rv0lt Oct 23, 2023
681b4af
Update dds_web/api/project.py
rv0lt Oct 23, 2023
de4b7c5
Update dds_web/api/project.py
rv0lt Oct 23, 2023
1cc9c4d
test to match changes
rv0lt Oct 23, 2023
a4fb0f5
Update tests/api/test_project.py
rv0lt Oct 23, 2023
703fa91
feedback
rv0lt Oct 23, 2023
b3f478b
more explicative error
rv0lt Oct 23, 2023
75987af
move check for data availability
rv0lt Oct 23, 2023
bbffbd5
typo
rv0lt Oct 23, 2023
118708c
Update dds_web/api/project.py
rv0lt Oct 23, 2023
a5ab01a
Update dds_web/api/project.py
rv0lt Oct 24, 2023
78f7418
Update dds_web/api/project.py
rv0lt Oct 24, 2023
dd50770
Update dds_web/api/project.py
rv0lt Oct 24, 2023
33e78ef
fix tests
rv0lt Oct 24, 2023
494b7bc
feedback
rv0lt Oct 24, 2023
de6e3fb
Merge pull request #1480 from ScilifelabDataCentre/DDS-1691-New-API-e…
rv0lt Oct 24, 2023
4c7113f
Merge branch 'dev' into DDS-1700-new-release-for-api
i-oden Oct 24, 2023
59e44d5
changelog
i-oden Oct 24, 2023
615997f
Merge pull request #1482 from ScilifelabDataCentre/DDS-1700-new-relea…
i-oden Oct 24, 2023
f32c284
Merge branch 'master' into dev
i-oden 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
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
15 changes: 14 additions & 1 deletion SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,19 @@ _Nothing merged in CLI during this sprint_

# 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-10-27

- 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))
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/api/superadmin_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def post(self):

# Create email content
# put motd_obj.message etc in there etc
subject: str = "DDS Important Information"
subject: str = "Important Information: Data Delivery System"
body: str = flask.render_template(f"mail/motd.txt", motd=motd_obj.message)
html = flask.render_template(f"mail/motd.html", motd=motd_obj.message)

Expand Down
101 changes: 73 additions & 28 deletions dds_web/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def compose_and_send_email_to_user(userobj, mail_type, link=None, project=None):

unit_email = None
project_id = None
project_title = None
deadline = None

# Don't display unit admins or personnels name
Expand All @@ -440,6 +441,7 @@ def compose_and_send_email_to_user(userobj, mail_type, link=None, project=None):
elif mail_type == "project_release":
subject = f"Project made available by {displayed_sender} in the SciLifeLab Data Delivery System"
project_id = project.public_id
project_title = project.title
deadline = project.current_deadline.astimezone(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S %Z"
)
Expand Down Expand Up @@ -470,6 +472,7 @@ def compose_and_send_email_to_user(userobj, mail_type, link=None, project=None):
displayed_sender=displayed_sender,
unit_email=unit_email,
project_id=project_id,
project_title=project_title,
deadline=deadline,
)
msg.html = flask.render_template(
Expand All @@ -478,6 +481,7 @@ def compose_and_send_email_to_user(userobj, mail_type, link=None, project=None):
displayed_sender=displayed_sender,
unit_email=unit_email,
project_id=project_id,
project_title=project_title,
deadline=deadline,
)

Expand Down Expand Up @@ -864,7 +868,7 @@ def delete_invite(email):


class RemoveUserAssociation(flask_restful.Resource):
@auth.login_required(role=["Unit Admin", "Unit Personnel", "Project Owner", "Researcher"])
@auth.login_required(role=["Unit Admin", "Unit Personnel", "Project Owner"])
@logging_bind_request
@json_required
@handle_validation_errors
Expand All @@ -876,34 +880,81 @@ def post(self):
if not (user_email := json_input.get("email")):
raise ddserr.DDSArgumentError(message="User email missing.")

# Check if email is registered to a user
# Check if the user exists or has a pending invite
try:
existing_user = user_schemas.UserSchema().load({"email": user_email})
unanswered_invite = user_schemas.UnansweredInvite().load({"email": user_email})
except sqlalchemy.exc.OperationalError as err:
raise ddserr.DatabaseError(message=str(err), alt_message="Unexpected database error.")

if not existing_user:
# If the user doesn't exist and doesn't have a pending invite
if not existing_user and not unanswered_invite:
raise ddserr.NoSuchUserError(
f"The user with email '{user_email}' does not have access to the specified project."
" Cannot remove non-existent project access."
f"The user / invite with email '{user_email}' does not have access to the specified project. "
"Cannot remove non-existent project access."
)

user_in_project = False
for user_association in project.researchusers:
if user_association.user_id == existing_user.username:
user_in_project = True
db.session.delete(user_association)
project_user_key = models.ProjectUserKeys.query.filter_by(
project_id=project.id, user_id=existing_user.username
).first()
if project_user_key:
db.session.delete(project_user_key)

if not user_in_project:
raise ddserr.NoSuchUserError(
f"The user with email '{user_email}' does not have access to the specified project."
" Cannot remove non-existent project access."
)
if unanswered_invite:
# If there is a unit_id value, it means the invite was associated to a unit
# i.e The invite is for a Unit Personel which shouldn't be removed from individual projects
if unanswered_invite.unit_id:
raise ddserr.UserDeletionError(
"Cannot remove a Unit Admin / Unit Personnel from individual projects."
)

invite_id = unanswered_invite.id

# Check if the unanswered invite is associated with the project
project_invite_key = models.ProjectInviteKeys.query.filter_by(
invite_id=invite_id, project_id=project.id
).one_or_none()

if project_invite_key:
msg = (
f"Invited user is no longer associated with the project '{project.public_id}'."
)
# Remove the association if it exists
db.session.delete(project_invite_key)

# Check if the invite is associated with only one project, if it is -> delete the invite
project_invite_key = models.ProjectInviteKeys.query.filter_by(
invite_id=invite_id
).one_or_none()

if not project_invite_key:
db.session.delete(unanswered_invite)
else:
# The unanswered invite is not associated with the project
raise ddserr.NoSuchUserError(
f"The invite with email '{user_email}' does not have access to the specified project. "
"Cannot remove non-existent project access."
)

else:
if auth.current_user().username == existing_user.username:
raise ddserr.AccessDeniedError(message="You cannot revoke your own access.")

# Search the user in the project, when found delete from the database all references to them
user_in_project = False
for (
user_association
) in project.researchusers: # TODO Possible optimization -> comprehesion list
if user_association.user_id == existing_user.username:
user_in_project = True
db.session.delete(user_association)
project_user_key = models.ProjectUserKeys.query.filter_by(
project_id=project.id, user_id=existing_user.username
).first()
if project_user_key:
db.session.delete(project_user_key)
break

if not user_in_project:
raise ddserr.NoSuchUserError(
f"The user with email '{user_email}' does not have access to the specified project. "
"Cannot remove non-existent project access."
)
msg = f"User with email {user_email} no longer associated with {project.public_id}."

try:
db.session.commit()
Expand All @@ -924,13 +975,7 @@ def post(self):
),
) from err

flask.current_app.logger.debug(
f"User {existing_user.username} no longer associated with project {project.public_id}."
)

return {
"message": f"User with email {user_email} no longer associated with {project.public_id}."
}
return {"message": msg}


class EncryptedToken(flask_restful.Resource):
Expand Down
2 changes: 1 addition & 1 deletion dds_web/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class Unit(db.Model):
sto2_access = db.Column(db.String(255), unique=False, nullable=True) # unique=True later
sto2_secret = db.Column(db.String(255), unique=False, nullable=True) # unique=True later

# New safespring storage
# New safespring storage - NOTE: MAKE SURE IPS ARE WHITELISTED ON UPPMAX AND OTHER SERVERS
sto4_start_time = db.Column(db.DateTime(), nullable=True)
sto4_endpoint = db.Column(db.String(255), unique=False, nullable=True) # unique=True later
sto4_name = db.Column(db.String(255), unique=False, nullable=True) # unique=True later
Expand Down
23 changes: 22 additions & 1 deletion dds_web/templates/mail/mail_base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
<!doctype html>
<html>

<script>
function copyTextProjectRelease(copyOption) {
// Get the text field
let copyText;
if (copyOption == 1){
copyText = document.getElementById("ProjectListing").innerHTML;
}
else if (copyOption == 2){
copyText = document.getElementById("ProjectDownload").innerHTML;
}
// Copy the text inside the text field
navigator.clipboard.writeText(copyText);

// Alert the copied text
alert("Copied the text: " + copyText);
}
</script>

<head>
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Expand Down Expand Up @@ -122,6 +139,10 @@
border-color: #a00202 !important;
}
}
code {
background-color: pink;
color: black;
}
</style>
</head>

Expand Down
Loading
Loading