Skip to content
This repository has been archived by the owner on Sep 26, 2018. It is now read-only.

Guardian permissions #45

Open
wants to merge 157 commits into
base: master
Choose a base branch
from

Conversation

sharma-sagar
Copy link

Guardian Permission Implementation.
This commit is on top of sprint_1 (user management and subscriber management).

Also:
Added user management where user wasn't able to see any same level user to block/unblock or delete.
Added Role in subscriber management.

Please review
Thanks

piyush and others added 30 commits April 5, 2017 15:23
Simplify management of CCM repo on GitHub.
This reverts commit 06c22aa.
Fix: Cloud Admin was available to Network Admin and Cloud Admin
Fix: Username replaced with Email
Fix for user role permissions
Code added to ajax request to get permission depending on role
@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact [email protected] if you have any questions.

Copy link
Contributor

@kkroo kkroo left a comment

Choose a reason for hiding this comment

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

Permission checks should be against a particular network instance as apposed to get_all_permissions for a user. Also I am not sure why we are rendering a permission denied message in the templates. This should be handled by the view to ensure it applies to both GET/POST. Some questions about permission_required selection for user management

self.helper.form_action = '/dashboard/user/management/blocking'
else:
self.helper.form_action = '/dashboard/user/management/delete'
# self.helper.form_class = 'form-vertical'
Copy link
Contributor

Choose a reason for hiding this comment

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

deaddcode

@@ -26,7 +26,7 @@
<h3>Network Activity</h3>
</div>
</div>

{% if 'endagaweb.view_usage' in user_permission %}
Copy link
Contributor

Choose a reason for hiding this comment

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

this check should be against the network object

@@ -146,6 +146,7 @@
</div>
</div>

{% if 'endagaweb.download_usage' in user_permission %}
Copy link
Contributor

Choose a reason for hiding this comment

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

for these permissions to work with guardian they need to be a part of the Network model and you can then use Guardian to check this permission against this object

@@ -34,6 +34,7 @@
</div>
</div>

{% if 'endagaweb.view_graph' in user_permission %}
Copy link
Contributor

Choose a reason for hiding this comment

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

this permission is global to all networks per user

<link href="/static/css/dashboard.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css">
<link href="/static/css/dashboard.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

if you use the CDN delete the file from static

Copy link
Author

Choose a reason for hiding this comment

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

accidental change

<div class="input-group col-xs-8">
<select name='network' id="network" class="form-control" multiple="multiple" size="5"
required="required">
{% for network in networks %}
Copy link
Contributor

Choose a reason for hiding this comment

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

this may need to be thought over since if I don't have a particular permission on a network, I shouldnt be able to grant it to someone else

</body>
</div>
</form>
{% else %}
Copy link
Contributor

Choose a reason for hiding this comment

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

post? the check needs to happen in the view

@@ -122,7 +151,9 @@ def dashboard_view(request):
network_has_activity = UsageEvent.objects.filter(
network=network).exists()
context = {
'networks': get_objects_for_user(request.user, 'view_network', klass=Network),
'user_permission': request.user.get_all_permissions(),
Copy link
Contributor

Choose a reason for hiding this comment

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

the user_permission should contain the context of the selected network



class TowerList(drf_views.APIView):
class TowerList(PermissionRequiredMixin, drf_views.APIView):
Copy link
Contributor

Choose a reason for hiding this comment

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

should check against the network instance:

If a get_object() method is defined either manually or by including another mixin (for example SingleObjectMixin) or self.object is defined then the permission will be tested against that specific instance, alternatively you can specify get_permission_object() method if self.object or get_object() does not return the object against you want to test permission

http://django-guardian.readthedocs.io/en/stable/api/guardian.mixins.html#guardian.mixins.PermissionRequiredMixin



class UserBlockUnblock(ProtectedView):
permission_required = 'endagaweb.view_user'
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be the block_user permission

@9muir
Copy link
Contributor

9muir commented Jun 15, 2017

Just a process point: this PR is 'on top' of the original Sprint 1 PR #33, do you intend to close the original one and instead have us focus our attention on this one, or address them separately? At this point I recommend the former, as we don't want to merge the permission changes without Guardian incorporated.

Once you have addressed @kkroo's comments we can review this again. Just one additional minor request that will eliminate numerous lint errors that get flagged by our internal build system: please make sure EVERY file ends with a newline, but that the last line of the file does not contain any other whitespace. And remove any code that is currently commented out.

Thanks

@facebook-github-bot
Copy link

@sagarsharma-aricent updated the pull request - view changes

@facebook-github-bot
Copy link

@sagarsharma-aricent updated the pull request - view changes

@facebook-github-bot
Copy link

@sagarsharma-aricent updated the pull request - view changes

Copy link
Contributor

@kkroo kkroo left a comment

Choose a reason for hiding this comment

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

very close! minor changes requested. thanks for all the hard work

$.each(imsi_list, function(key, val){
imsi_val[i++]=val.value;
});
console.log(imsi_val)
Copy link
Contributor

Choose a reason for hiding this comment

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

debug

Copy link
Author

Choose a reason for hiding this comment

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

removed

console.log("done");
window.location = "/dashboard/subscriber_management/subscriber";
}).fail(function(response) {
console.log(response);
Copy link
Contributor

Choose a reason for hiding this comment

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

debug

Copy link
Author

Choose a reason for hiding this comment

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

removed

</div>
</div><!--Email Ends-->

<!--Password-->
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we don't require a password? password reset is sent anyhow. what about existing users?

Copy link
Author

Choose a reason for hiding this comment

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

Password is kept temporarily for testing purpose.
If we mention existing user in email field , an edit option will be shown just below email for editing the user.
Please find attached snapshots
editscreen
existinguser

<div class="input-group-addon">
<i class="glyphicon glyphicon-signal"></i>
</div>
<input type="hidden" name="network_id" id="network_id" value="{{ network.id }}"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

lets get rid of this? there is only one option here can be implicit

Copy link
Author

Choose a reason for hiding this comment

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

done

$.ajax({
url: "/dashboard/user/management/checkuser?email=" + $('#email').val(),
//beforeSend: function(xhr) {
// xhr.setRequestHeader("X-CSRFToken", '{{ csrf_token }}');
Copy link
Contributor

Choose a reason for hiding this comment

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

CSRF should be required. I think it gets switched on for POST by default so you can change the request type for this endpoint

Copy link
Author

Choose a reason for hiding this comment

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

its a GET request

</div>
</div><!--Email Ends-->

<!--Network-->
Copy link
Contributor

Choose a reason for hiding this comment

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

this is implicit in the current selected network

Copy link
Author

Choose a reason for hiding this comment

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

updated now

@@ -0,0 +1,259 @@
{% extends "dashboard/layout.html" %}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why this file was added

Copy link
Author

@sharma-sagar sharma-sagar Jul 13, 2017

Choose a reason for hiding this comment

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

Wrongly added, now removed

network = user_profile.network
user = User.objects.get(id=user_profile.user_id)
available_permissions = get_perms(request.user, network)
print network.id
Copy link
Contributor

Choose a reason for hiding this comment

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

debug

Copy link
Author

Choose a reason for hiding this comment

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

removed

user_profile = UserProfile.objects.create(user=user)
user_network = Network.objects.get(id=networks)
# Add the permissions
for permission_id in permissions:
Copy link
Contributor

Choose a reason for hiding this comment

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

needs validation that its only from the list of available permissions

Copy link
Author

Choose a reason for hiding this comment

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

added check to validate assigned permission against available permissions


def _send_reset_link(self, request):
return password_reset(request,
# email_template_name='dashboard/user_management/reset_email.html',
Copy link
Contributor

Choose a reason for hiding this comment

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

debug

Copy link
Author

Choose a reason for hiding this comment

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

removed

@facebook-github-bot
Copy link

@sagarsharma-aricent updated the pull request - view changes

@sharma-sagar
Copy link
Author

All the changes are incorporated as requested.
Thanks
Sagar Sharma

@sharma-sagar sharma-sagar changed the title Guardian permissions (**do not merge) Guardian permissions Jul 13, 2017
@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@facebook-github-bot
Copy link

@sharma-sagar updated the pull request - view changes

@sharma-sagar
Copy link
Author

sharma-sagar commented Aug 4, 2017

Hello,
Please review 3ed0bf7 on top of this with all changes incorporated and added redesign which includes
This include:
create
user_mgmt

Add/Edit/Block/Delete User
Assign permission on multiple networks
Guardian permissions
Attached are the snapshots for user management

this commit is on top of this pr ( #45 )
closing #75 as this commit is same.

@facebook-github-bot
Copy link

@sharma-sagar updated the pull request - view changes

@facebook-github-bot
Copy link

@sharma-sagar updated the pull request - view changes

@facebook-github-bot
Copy link

@kkroo has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants