-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Don't allow to create a subproject of a project itself #3571
Conversation
@@ -270,6 +270,13 @@ def clean_parent(self): | |||
_('Subproject nesting is not supported')) | |||
return self.project | |||
|
|||
def clean_child(self): | |||
child = self.cleaned_data['child'] | |||
if child == self.project: |
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.
This would not normally happen, unless someone does it manually.
{'child': subproject.pk}, | ||
project=project, | ||
user=user | ||
) |
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 think is_valid
should be called and tested that it return False
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.
@stsewd take a look at this comment.
If you don't calle is_valid
all your validations (clean_
methods) are not called.
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.
This looks good!
Please, take a look at the comments and I think we will be ready to merge after that.
{'child': subproject.pk}, | ||
project=project, | ||
user=user | ||
) |
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.
@stsewd take a look at this comment.
If you don't calle is_valid
all your validations (clean_
methods) are not called.
def test_exclude_self_project_as_subproject(self): | ||
user = fixture.get(User) | ||
project = fixture.get(Project, users=[user]) | ||
subproject = project |
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.
Do not assign this variable. So, in the form initialization it's clear that we are using the same project for both fields.
project=project, | ||
user=user | ||
) | ||
self.assertNotIn( |
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 think this won't be needed once you use is_valid
method.
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.
This is needed for test the query set
@safwanrahman @humitos thanks for the feedback, I update the PR and responded to @humitos comment. |
Closes #3449