-
Notifications
You must be signed in to change notification settings - Fork 336
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
Feature/ENG-6134 #10951
Feature/ENG-6134 #10951
Conversation
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.
Very good tests and diligent work, I have one suggestion about class inheritance, but otherwise good.
Also I see some unit test failures. Fix those before putting it back in review.
api/nodes/views.py
Outdated
@@ -361,6 +361,19 @@ def perform_destroy(self, instance): | |||
raise PermissionDenied(str(err)) | |||
|
|||
|
|||
class NodeContributorRemoveMixin: |
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.
Don't add this add a Mixin just over write for the classes you want individually.
api/nodes/views.py
Outdated
def perform_destroy(self, instance): | ||
node = self.get_resource() | ||
auth = get_user_auth(self.request) | ||
if len(node.visible_contributors) == 1 and instance.visible: |
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.
use node.visible_contributors.count()
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.
yeah, just copied this block from another place ;)
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.
It is okay to copy, I copy a lot, but only from good developers! :)
@@ -521,16 +534,6 @@ class NodeContributorDetail(BaseContributorDetail, generics.RetrieveUpdateDestro | |||
def get_resource(self): | |||
return self.get_node() | |||
|
|||
# overrides DestroyAPIView | |||
def perform_destroy(self, instance): |
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.
As I said above don't bother using a mixin, it's okay to repeat yourself a little across views. It's just easier to see new behavior when you have a small number of methods for a view.
} | ||
} | ||
} | ||
payload = {'data': {'attributes': attrs, 'relationships': relationships, 'type': 'contributors'}} |
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.
just a small thing but I would like everything to be indented like the relationships
dictionary.
@@ -267,7 +268,7 @@ def get_serializer_context(self): | |||
return context | |||
|
|||
|
|||
class RegistrationContributorsList(BaseContributorList, RegistrationMixin, UserMixin): | |||
class RegistrationContributorsList(BaseContributorList, mixins.CreateModelMixin, RegistrationMixin, UserMixin): |
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 a good use of mixin. this class looks correct.
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.
Just a couple of things from me, plus handle the failing tests please.
creator=self.user, project=self.project) | ||
|
||
self.public_project = ProjectFactory(is_public=True, creator=self.user) | ||
self.public_registration_project = RegistrationFactory( |
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.
Minor: I would call this public_registration
instead of public_registration_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.
yeah, agree, just copied from another place
Fixed flake8 related errors and will fix others as you review it again because some of them don't fail locally. I assume most of the errors are related to the functionality that was prohibited (e.g. title was unchangable, impossible to update contributors of the registrations, etc) but now is allowed |
@ihorsokhanexoft Looks like you still have a Flake8 problem, and at least one more failing test. |
…ializer_context, fixed flake and tests where title is not writable
@brianjgeiger pushed the last fix. Review please and I'll check the result of tests |
@ihorsokhanexoft Looks like we're getting about 75 failing tests with a 400 response rather than successful responses. Hopefully there's just a small change to fix all those. |
If the failing tests are because we're requiring the Title field, then I may have been wrong about that and we can make it not required again. |
@brianjgeiger Yeah, it's because this field is required now. Reverted this change |
@brianjgeiger 1 test failed because it expected title shouldn't be updated. fixed it |
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.
One more bit of functionalist that appears to be missing. Almost there.
url = f'/{API_BASE}registrations/{self.public_registration._id}/contributors/{contributor._id}/' | ||
return self.app.delete_json_api(url, auth=auth_user.auth, expect_errors=expect_errors) | ||
|
||
def update_attribute_request(self, auth_user, expect_errors=True, **attributes): |
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.
Sorry I missed this before. Admins should also be able to modify the contributors permissions and bibliographic status with this PR.
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 see, it means we need to add patch method to RegistrationContributorDetail view
…sions for registration
@brianjgeiger @Johnetordoff I've found |
Looks like there's at least one problem that needs fixing from CI: |
Yeah, it's quite bad that I can't check the errors before your review. Fixed |
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 one last thing, to DRY up the update method.
api/registrations/serializers.py
Outdated
index = None | ||
if '_order' in validated_data: | ||
index = validated_data.pop('_order') | ||
|
||
auth = Auth(self.context['request'].user) | ||
node = self.context['resource'] | ||
|
||
if 'bibliographic' in validated_data: | ||
bibliographic = validated_data.get('bibliographic') | ||
else: | ||
bibliographic = node.get_visible(instance.user) | ||
permission = validated_data.get('permission') or instance.permission | ||
try: | ||
if index is not None: | ||
node.move_contributor(instance.user, auth, index, save=True) | ||
node.update_contributor(instance.user, permission, bibliographic, auth, save=True) | ||
except node.state_error as e: | ||
raise exceptions.ValidationError(detail=str(e)) | ||
except ValueError as e: | ||
raise exceptions.ValidationError(detail=str(e)) | ||
instance.refresh_from_db() | ||
return instance |
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.
Could you extract this into a helper function and call that function from both places it's used? It's significant enough functionality that it would be nice to have it DRY. Maybe put it in api/base/utils.py
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.
Agree. Followed John's recommendations it's not always required to follow DRY and no need to create a separate mixin
Looks like you're missing some commas according to the pre-commit hook.
It might be worth automatically getting pre-commit hooks running for you locally. |
Yes, I have installed it, but it doesn't show any warnings, all checks are passed even if I run it manually |
d370e2b
into
CenterForOpenScience:feature/b-and-i-25-01
Purpose
Contributors added to a registration should be able to edit title. Admins should be able to edit contributors on registration page
Changes
Notes:
Ticket
https://openscience.atlassian.net/jira/software/c/projects/ENG/boards/145?assignee=712020%3A7c7368dc-40cb-475f-bae8-b07a8bd2dd6c&selectedIssue=ENG-6134