Skip to content
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

Jkmarx/add group member api #3309

Merged
merged 33 commits into from Apr 4, 2019
Merged

Jkmarx/add group member api #3309

merged 33 commits into from Apr 4, 2019

Conversation

jkmarx
Copy link
Member

@jkmarx jkmarx commented Apr 3, 2019

Ref #2618

  • Add groupMember resource to promote/demote/remove users
  • Add unit tests

jkmarx and others added 28 commits March 26, 2019 11:29
* Refactor other view sets to use helper.

* Fix typo.

* Jkmarx/update client edit perms (#3287)

* Update client to use new group api.

* Update unit tests.

* Remove unused service.

* Add other unit tests.

* Remove dataSetResource (#3288)

* Remove dataSetResource

* Remove unused shareable api resource and unused helpers. (#3289)

* Remove unused shareable api resource and unused helpers.

* Remove helper tests.
@jkmarx jkmarx self-assigned this Apr 3, 2019
@jkmarx jkmarx added this to the Release 1.6.9 milestone Apr 3, 2019
@jkmarx jkmarx requested a review from hackdna April 3, 2019 13:39
@codecov
Copy link

codecov bot commented Apr 3, 2019

Codecov Report

Merging #3309 into develop will decrease coverage by 0.46%.
The diff coverage is 90.9%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3309      +/-   ##
===========================================
- Coverage    67.33%   66.86%   -0.47%     
===========================================
  Files          375      375              
  Lines        25420    24659     -761     
  Branches       939      939              
===========================================
- Hits         17116    16488     -628     
+ Misses        8304     8171     -133
Impacted Files Coverage Δ
...nery/ui/source/js/commons/services/group-member.js 100% <ø> (ø) ⬆️
refinery/core/urls.py 100% <ø> (ø) ⬆️
...e/js/commons/ctrls/group-member-edit-modal-ctrl.js 43.63% <ø> (ø) ⬆️
...i/source/js/commons/ctrls/group-edit-modal-ctrl.js 55.17% <ø> (ø) ⬆️
refinery/core/models.py 81.26% <100%> (-0.59%) ⬇️
refinery/core/test_views.py 100% <100%> (ø) ⬆️
refinery/core/serializers.py 87.42% <100%> (-4.17%) ⬇️
refinery/core/test_models.py 99.85% <100%> (-0.03%) ⬇️
refinery/core/api.py 39.13% <100%> (+11.11%) ⬆️
refinery/core/views.py 60.63% <70%> (-2.36%) ⬇️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e9ec411...be9d803. Read the comment docs.

@@ -1863,6 +1863,12 @@ def get_managed_group(self):
except:
return None

def is_user_a_group_manager(self, user):
Copy link
Member

Choose a reason for hiding this comment

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

Sounds like it should be a method on the User model.

@@ -128,6 +129,11 @@ class ExtendedGroupSerializer(serializers.ModelSerializer):
validators=[UniqueValidator(queryset=ExtendedGroup.objects.all())]
)

def get_manager_group_uuid(self, group):
Copy link
Member

Choose a reason for hiding this comment

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

Seems redundant. Doesn't appear to be used anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a field the client expects.

return Response(uuid)
return HttpResponseBadRequest(content="No users left in group.")

def is_user_authorized_to_edit(self, group, request_user, edit_user):
Copy link
Member

Choose a reason for hiding this comment

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

Sounds like it should be a method either on the Group or the User model. This would help with reuse and simplify the function signature.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's only used for this delete request which is dependent on both the member and request user. I don't imagine it being used anywhere else, so it's fine here.

logger.error(e)
raise APIException("Multiple groups returned for this request.")

def get_user(self, id):
Copy link
Member

Choose a reason for hiding this comment

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

Why use Django internal ID instead of UUID like everywhere else?

Copy link
Member Author

Choose a reason for hiding this comment

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

Legacy of previous api. url /group/:uuid/member/:id
I can update it to both use uuid after merging the other two branches into here.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it would be great to fix this.

Copy link
Member Author

Choose a reason for hiding this comment

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

@hackdna Users don't have UUID. User profiles have UUIDs. Simplicity wise, it would make sense to use IDs verses having to grab users through their profiles.

Copy link
Member

Choose a reason for hiding this comment

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

I see. It would be great to switch to a custom User model as Two Scoops and Django docs suggest but it's out of the scope of this PR.

group = self.get_object(uuid)
edit_user = self.get_user(id)
if self.is_user_authorized_to_edit(group, request.user, edit_user):
return Response(uuid, status=status.HTTP_403_FORBIDDEN)
Copy link
Member

Choose a reason for hiding this comment

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

If user is authorized to edit then return HTTP 403?

Copy link
Member Author

Choose a reason for hiding this comment

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

Forgot the un, will update the method name.

Copy link
Member

Choose a reason for hiding this comment

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

I'd rather keep the name and simplify the logic.

jkmarx and others added 2 commits April 3, 2019 13:14
* Update client to group memebers api v2.

* Rename for clarity.

* Remove unused group api v1 resource. (#3311)
@jkmarx jkmarx merged commit 690342f into develop Apr 4, 2019
@jkmarx jkmarx deleted the jkmarx/add-group-member-api branch April 4, 2019 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants