-
Notifications
You must be signed in to change notification settings - Fork 1
SS-1112 Enforce unique project names by owner #251
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
SS-1112 Enforce unique project names by owner #251
Conversation
| # 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 | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # 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() |
There was a problem hiding this comment.
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.
projects/views.py
Outdated
| arr = ProjectTemplate.objects.filter(name=pre_selected_template) | ||
| template = arr[0] if len(arr) > 0 else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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() |
There was a problem hiding this comment.
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.
alfredeen
left a comment
There was a problem hiding this 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.
We have this planned in a separate PR. |
Thanks a lot. I will write it in the near future. |
|
SS-1112 Enforce unique project names by owner For details: https://scilifelab.atlassian.net/browse/SS-1112 |
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.
Further comments
Anything else you think we should know before merging your code!