Skip to content

Conversation

@anondo1969
Copy link
Member

@anondo1969 anondo1969 commented Nov 4, 2024

Description

Source: https://scilifelab.atlassian.net/browse/SS-1112

The users should only be able to have a single project with a particular name. This should not be applied to admins.

Checklist

If you're unsure about any of the items below, don't hesitate to ask. We're here to help!
This is simply a reminder of what we are going to look for before merging your code.

  • This pull request is against develop branch (not applicable for hotfixes)
  • I have included a link to the issue on GitHub or JIRA (if any)
  • I have included migration files (if there are changes to the model classes)
  • I have included, reviewed and executed tests (unit and end2end) to complement my changes
  • I have updated the related documentation (if necessary)
  • I have added a reviewer for this pull request
  • I have added myself as an author for this pull request
  • In the case I have modified settings.py, then I have also updated the studio-settings-configmap.yaml file in serve-charts

Further comments

Anything else you think we should know before merging your code!

@anondo1969 anondo1969 self-assigned this Nov 4, 2024
@anondo1969 anondo1969 requested a review from akochari November 11, 2024 13:33
@anondo1969 anondo1969 marked this pull request as ready for review November 11, 2024 13:33
Comment on lines 413 to 419
# Ensure no duplicate project name for the common user
current_user_previous_project_names = list(Project.objects.filter(owner=request.user).values("name", "status"))

project_name_already_exists = any(
current_user_project["name"] == name and current_user_project["status"] != "deleted"
for current_user_project in current_user_previous_project_names
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Ensure no duplicate project name for the common user
current_user_previous_project_names = list(Project.objects.filter(owner=request.user).values("name", "status"))
project_name_already_exists = any(
current_user_project["name"] == name and current_user_project["status"] != "deleted"
for current_user_project in current_user_previous_project_names
)
# Ensure no duplicate project name for the common user
project_name_already_exists = Project.objects.filter(
owner=request.user,
name=name,
).exclude(status="deleted").exists()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. changed the code according to the suggestion.

Comment on lines 422 to 423
arr = ProjectTemplate.objects.filter(name=pre_selected_template)
template = arr[0] if len(arr) > 0 else None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
arr = ProjectTemplate.objects.filter(name=pre_selected_template)
template = arr[0] if len(arr) > 0 else None
template = ProjectTemplate.objects.filter(name=pre_selected_template).first()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. changed the code according to the suggestion.

Copy link
Member

@alfredeen alfredeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it and it works fine. It would be nice to add some end2end tests for this as well.

@akochari
Copy link
Collaborator

I tested it and it works fine. It would be nice to add some end2end tests for this as well.

We have this planned in a separate PR.

@anondo1969
Copy link
Member Author

I tested it and it works fine. It would be nice to add some end2end tests for this as well.

Thanks a lot. I will write it in the near future.

@anondo1969
Copy link
Member Author

SS-1112 Enforce unique project names by owner

For details: https://scilifelab.atlassian.net/browse/SS-1112

@anondo1969 anondo1969 merged commit 7e859e3 into develop Nov 20, 2024
2 of 3 checks passed
@anondo1969 anondo1969 deleted the ss-1112-Enforce-unique-project-names-by-owner branch November 20, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants