-
-
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
Create subproject relationship via APIv3 endpoint #6176
Create subproject relationship via APIv3 endpoint #6176
Conversation
`self` is either ChildRelatedProjectQuerySet or ParentRelatedProjectQuerySet. None of these one has a `project` field. Because of this, we need to use `self.project_field` for lookup.
…om:readthedocs/readthedocs.org into humitos/subproject-api-projectrelationship
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 you are missing some more checks:
- Adding the project as subproject of itself
- Nesting subprojects: adding as subproject a project that already has subprojects.
- Unique alias across subprojects of project
readthedocs.org/readthedocs/projects/forms.py
Lines 362 to 388 in 044f200
def clean_parent(self): | |
if self.project.superprojects.exists(): | |
# This validation error is mostly for testing, users shouldn't see | |
# this in normal circumstances | |
raise forms.ValidationError( | |
_('Subproject nesting is not supported'), | |
) | |
return self.project | |
def clean_child(self): | |
child = self.cleaned_data['child'] | |
if child == self.project: | |
raise forms.ValidationError( | |
_('A project can not be a subproject of itself'), | |
) | |
return child | |
def clean_alias(self): | |
alias = self.cleaned_data['alias'] | |
subproject = self.project.subprojects.filter( | |
alias=alias).exclude(id=self.instance.pk) | |
if subproject.exists(): | |
raise forms.ValidationError( | |
_('A subproject with this alias already exists'), | |
) | |
return alias |
I think 1 and 3 should be done at the db level.
Also, do we allow to add translations? There are some similar checks to be done too.
Would it also make sense to prevent project deletion if a project has one or more subprojects? I'm not sure if I think having to delete each subproject first would be terribly cumbersome or not, but it may be a good safeguard to have. |
@dwt2 currently if a project (main project) has submodules, and it is deleted, all its subprojects become normal projects. |
Hmm, I think I would be easier on users to have the current default as an option, but also the option to pass a param to delete all subprojects with the top-level project too. Let's say I intentionally want to delete a project and its 100 subprojects. With the current default I then have to do 100 more API operations to delete each (new) top-level project. Doable, but tedious. |
…humitos/subproject-api-projectrelationship
- Adding the project as subproject of itself - Nesting subprojects is not supported - Unique alias across subprojects of project
I added these checks and tests for them as well. Please, review the PR when you have some time.
Currently, no. We are only listing translations under |
…project-api-projectrelationship
@humitos can you resolve the conflicts before review? |
…adthedocs/readthedocs.org into humitos/subproject-api-projectrelationship
@stsewd done! |
For GET it returns a serializer with many fields and on POST, | ||
it return a serializer to validate just a few fields. | ||
""" | ||
if self.action == 'create': |
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.
aren't these constants somewhere?
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've never seen them used as constants. I did a quick grep on their source code and I found that they use just the strings as well :'( : https://github.com/encode/django-rest-framework/blob/e57c1505fc4ed957332ae547a35c8713acfdf30c/rest_framework/schemas/coreapi.py#L37
hmm, why wasn't this merged to master but |
Merge #6176 to master Co-authored-by: Manuel Kaufmann <[email protected]>
The main goal of this PR is to add the ability to create a subproject relationship between two
Project
objects.This PR is based on #5952 (https://github.com/readthedocs/readthedocs.org/tree/humitos/apiv3/project-update-endpoint) because it needs the "per object permissions check" changes that PR contains.
There are some things to note about this PR:
/api/v3/projects/pip/subprojects/
has changed its response. It was returning a list ofProject
but we found it was not 100% accurate and it was better to return a list ofProjectRelationship
objects that includes thealias
and thechild
(Project
) rendered itself.As a side note, while working on the tests for this PR, I found a but in the
RelatedProjectQuerySetBase
(see commit 0d42c1b).Closes #6157