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

MongoEngine's Django User Auth Model Not Supported #59

Closed
naftulikay opened this issue Oct 14, 2013 · 17 comments
Closed

MongoEngine's Django User Auth Model Not Supported #59

naftulikay opened this issue Oct 14, 2013 · 17 comments

Comments

@naftulikay
Copy link

Due to a limitation in MongoEngine, User objects stored in MongoEngine don't have a user_permissions field, which makes it impossible to log into mongonaut when using MongoEngine's user model replacement:

INSTALLED_APPS = (
    ...
    'django.contrib.auth',
    'mongoengine.django.mongo_auth',
    ...
)

AUTH_USER_MODEL = 'mongo_auth.MongoUser'

Admittedly, this is a bug in MongoEngine, but it'd be awesome to see a workaround in the meantime in mongonaut to enable users to log in until this is fixed upstream.

A patch for this would consist of simply replacing the use of the permissions API with a check to user.is_staff and user.is_active.

@pydanny
Copy link
Member

pydanny commented Oct 14, 2013

Hi @rfkrocktk - Would love to work on this but without a paying client who needs it, I can't justify the time.

OTOH, we do accept contributions. ;-)

@garrypolley
Copy link
Collaborator

@rfkrocktk would subclassing the user model to contain that field like this work for you?

class MyAuthUserModel(mongo_auth.MongoUser):
    """I am a cool subclass of Mongo's user model"""

    @property
    def user_permissions(self):
        ['list', 'of', 'required', 'permissions', 'generated']

Although, I'm confused why this doesn't work:

https://github.com/pydanny/django-mongonaut/blob/master/mongonaut/sites.py#L49

Seems it only checks for is_staff and is_active, which seems to be the desired goal.

@naftulikay
Copy link
Author

Not sure, but even when I'm logged in using Django's auth system (User object replaced with MongoEngine's Django replacement), I get a 403 when trying to access mongonaut.

@garrypolley
Copy link
Collaborator

If you go to a python manage.py shell is your user labeled as staff?

e.g.

from my_app.model import MyCusotmUser

user = MyCustomUser.object.get(username='my-user-name')
user.is_staff == True
user.is_active == True

How would the user have been marked as staff? I had to write a custom command awhile back if I remember to properly add a superuser when I used mongoengine in the past.

@naftulikay
Copy link
Author

Update: I can't even seem to get it working without using MongoEngine as an authentication source.

> from django.contrib.auth.models import User
> admin = User.objects.get(id=1)
> print (admin.is_superuser, admin.is_staff)
(True, True)

Yet, when I try to access mongonaut, I see the following:

a

...and I get a 403. Any ideas?

@garrypolley
Copy link
Collaborator

Without a look at the code giving the 403, I'm not going to be very useful other than my comment above, sorry.

@lafernandez
Copy link

Same problem here:

Django 1.5.1 with MongoEngine 0.8.4 as models backend.

Getting "You do not have permissions to access this content." error trying to access to mongonaut.

'is_active', 'is_staff' and 'is_superuser' of the admin user are set to True.

@naftulikay
Copy link
Author

I think I've tracked down the issue:

mongonaut/mixins.py:35:

if hasattr(self, 'permission') and self.permission not in context:
    return HttpResponseForbidden("You do not have permissions to access this content.")

However, permissions seem to never be added to the context anywhere in the codebase, so how would it ever work? Strange.

@naftulikay
Copy link
Author

Okay, so here's a patch which seems to work:

mongonaut/mixins.py:35:

if hasattr(self, 'permission') and not self.request.user.has_perm(self.permission):
    return HttpResponseForbidden("You do not have permissions to access this content.")

Now I've got a NoReverseMatch at /mongonaut/ error.

@j1z0
Copy link
Contributor

j1z0 commented Dec 9, 2013

@rfkrocktk -- I'm also getting the same NoReverseMatch at /mongonaut/ error using the example application. The detailed error is:

Reverse for '"document_detail_add_form"' with arguments '('articles', 'User')' and keyword arguments '{}' not found

@garrypolley , @pydanny
This is when trying to load /mongonaut. Any ideas?

@naftulikay
Copy link
Author

I worked around it somehow. Can't remember now :-/
On Dec 9, 2013 3:27 AM, "Jeremy Johnson" [email protected] wrote:

@rfkrocktk https://github.com/rfkrocktk -- I'm also getting the same NoReverseMatch
at /mongonaut/ error using the example application. The detailed error is:

Reverse for '"document_detail_add_form"' with arguments '('articles', 'User')' and keyword arguments '{}' not found

This is when trying to load /mongonaut. Any ideas?


Reply to this email directly or view it on GitHubhttps://github.com//issues/59#issuecomment-30124325
.

@j1z0
Copy link
Contributor

j1z0 commented Dec 9, 2013

OK I've got it working now ... it appears to be the version of Django. When I upgrade to Django 1.5 it works. With Django 1.4 (as per examples/requirements.txt) I get the NoReverseMatch error.

@erwinfeser
Copy link

I have the same problem NoReverseMatch at /mongonaut/ in Django 1.6.x

Error during template rendering

In template /home/efeser/.virtualenvs/venv/local/lib/python2.7/site-packages/mongonaut/templates/mongonaut/index.html, error at line 26

@ragingneuron
Copy link

it appears that there is no url import in templates like
{% load url from future %}
I guess one has to override the templates and add this line in order to make it work

@pydanny
Copy link
Member

pydanny commented May 18, 2014

Or... @ashishsingh2205, you could submit a pull request. 😉

@shubhambatra
Copy link

solve This issue 👍

first Login with 127.0.0.1:8000/admin/
In case you dont know the user name and password run : python manage.py createsuperuser

then go to 127.0.0.1:8000/mongonaut/

@garrypolley
Copy link
Collaborator

Given the age and new ticket to upgrade to new Django I'm going to close this ticket: #94

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

No branches or pull requests

8 participants