adamcharnock / django-su Goto Github PK
View Code? Open in Web Editor NEWLogin as any user from the Django admin interface, then switch back when done
License: MIT License
Login as any user from the Django admin interface, then switch back when done
License: MIT License
Consider changing to simply
from . import views
urlpatterns = patterns("django_su.views",
url(r"^$", views.su_logout, name="su_logout"),
url(r"^login/$", views.su_login, name="su_login"),
url(r"^(?P<user_id>-?[\d]+)/$", views.login_as_user, name="login_as_user"),
)
urlpatterns = patterns("django_su.views",
url(r"^$", "su_logout", name="su_logout"),
url(r"^login/$", "su_login", name="su_login"),
url(r"^(?P<user_id>-?[\d]+)/$", "login_as_user", name="login_as_user"),
)
Adam, thanks for your sweet little app. My use case needs us to restrict su permissions for users based on who they're trying to become. So I'd like the target user passed as a second parameter to the SU_LOGIN function.
I've forked and committed something that's working for me so far. It maintains backwards compatibility by using introspection to discover how many arguments the SU_LOGIN function takes. It only passes the second argument if the function takes two arguments. I wondered what you thought so far, before I issue a pull request.
I'm pretty sure the overly complex importpath
function can be removed in favor of Django's own module loading utils.
This package is great work, thanks !
I've tested it for my app, and because I need any of my staff to login as a user, I added the login callback:
SU_LOGIN_CALLBACK = "example.utils.su_login_callback"
The problem is that now, any staff can login as superuser and edit their own permissions...
How can I restrict the login as to non-staff user only ?
Thanks
New release in pypi. @adamcharnock or @katzj, could you tell me our users in pypi?, And I will add to the manteiners in pypi, and then you will be able to create a new release.
Just thought you may like to know your app is listed externally here:
https://www.djangopackages.com/packages/p/django-su/
However, there appears to be a more appropriate category and when searching for packages that provide similar functionality yours may not get evaluated:
https://www.djangopackages.com/grids/g/user-switching/
Since I already knew about and utilize your app, I thought you should know. It's extremely useful. I would also like to request one feature:
Please allow the ability to enable staff users to impersonate users and/or the ability for a super-user to assign the permission to staff user to impersonate a user.
This happens when we call Django's login()
function, which triggers the user_logged_in
signal. This in turn triggers django's update_last_login()
.
The only obvious way I can see to achieve this is to change the last_login
value back after it has been set, but this does not feel ideal. Better suggestions welcome!
There is warning about future incompatibility with Django 1.10
/home/petr/soubory/programovani/Auto-mat/DPNK/dpnk/env/lib/python3.4/site-packages/django_su/urls.py:12: RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead.
The user selection drop-down in the admin UI shows unordered users, which makes it hard to find the desired user in the list.
Error message:
File "/usr/local/lib/python3.5/dist-packages/django_su/context_processors.py", line 5, in is_su
return {"IS_SU": len(request.session.get("exit_users_pk", default=[]))}
TypeError: get() takes no keyword arguments
It may be a good idea to refactor this line into:
return {"IS_SU": len(request.session.get("exit_users_pk", []))}
See: https://stackoverflow.com/questions/24463202/typeerror-get-takes-no-keyword-arguments
I noticed that your package doesn't have a license... Could you please add one?
I hope you'll select an open-source licence (BSD, MIT, GPL -- in that order), but it's up to you. I can't really use any of your code without a license... :-/
I didn't see this in the documentation but it appears that one needs to add this to the authentication backends for django_su to work:
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin
"django.contrib.auth.backends.ModelBackend",
# Needed for django su to work
"django_su.backends.SuBackend",
)
Please advise.
Django==1.5.2
django-su==0.3.2
I prefer installing from pypi. Version 0.8 does what I need, but I no longer have any django projects that use anything older than Django 1.11. It'd be nice to have a version that explicitly supports 1.11 and pythons newer than 3.4, which is after all end-of-lifed. When 1.11 is eol, another version that officially does not support python 2 would also be appreciated.
I get the following error trying to --update django-su. Any ideas?
Downloading/unpacking django-su==0.3.2 (from -r statuspath/Documentation/requirements.txt (line 30))
Running setup.py egg_info for package django-su
Traceback (most recent call last):
File "", line 16, in
File "/tmp/pip-build/django-su/setup.py", line 6, in
from django_su import version
ImportError: cannot import name version
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 16, in
File "/tmp/pip-build/django-su/setup.py", line 6, in
from django_su import __version__
ImportError: cannot import name version
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build/django-su
Storing complete log in /root/.pip/pip.log
[ec2-user@qa1 ~]$ sudo pip install django-su --upgrade
Downloading/unpacking django-su from https://pypi.python.org/packages/source/d/django-su/django-su-0.3.2.tar.gz#md5=6ce232bb52d0124d3e957e9c634e91de
Running setup.py egg_info for package django-su
Traceback (most recent call last):
File "", line 16, in
File "/tmp/pip-build/django-su/setup.py", line 6, in
from django_su import version
ImportError: cannot import name version
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 16, in
File "/tmp/pip-build/django-su/setup.py", line 6, in
from django_su import __version__
ImportError: cannot import name version
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build/django-su
Hi,
I need a feature like Netflix users management, that one users can impersonate the "children"
Thanks for support!
The "Login as" object tool shows up in Group. I don't see any reason for this. If I'm not mistaken, it would make sense to place the change_form.html in /admin/auth/user/ instead of /admin/auth/
INSTALLED_APPS = (
'django_su',
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.auth',
........
)
The django-su
application doesn't work out of the box. It requires setting of template paths. Please mention this in the README for future developers. My code looks like:
@admin.register(models.UserProfile)
class UserProfileAdmin(UserAdmin):
change_form_template = "admin/auth/user/change_form.html"
change_list_template = "admin/auth/user/change_list.html"
According to logs (running with Django 1.9.4):
django_su/urls.py:10: RemovedInDjango110Warning: Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got su_logout). Pass the callable instead.
Hi!
I want to log user log in date using something like this:
from django.contrib.auth.signals import user_logged_in
def set_last_seen(sender, user, request, **kwargs):
if not len(request.session.get("exit_users_pk", default=[])):
user.profile.last_seen = timezone.now()
user.profile.save()
user_logged_in.connect(set_last_seen)
But looks like exit_users_pk is being populated after the signal is sent, cause it's always empty.
Is there a way we can check in this signal if the login is triggered by django-su?
I am using django-suit.
I made a small change in my base_site.html (extended) file to set the text display otherwise to the accessed user.
The code:
{% block welcome-msg %}
{% if IS_SU %}
<a href="/su/" title="{% trans 'Restabelecer papel original' %}">{% trans 'Você' %}</a>{% trans ' acessou como,' %}
{% else %}
{% trans 'Welcome,' %}
{% endif %}
<strong>
{% filter force_escape %}
{% firstof user.first_name user.username %}
{% endfilter %}
</strong>.
{% endblock %}
Some situation like ANONYMOUS_USER_ID = -1
for django-guardian.
I have setup a fresh Django project in my local with super admin and install the plugin after that I am facing problem. The Dijango landing page is not opening up it say 404 and I am not able to login into other Django admin after using this but if I remove this plugin I am able to login in the Django admin with my existing superuser account . I have followed the step for 1 to 4 written in the description for the plugin. I am very new to Django can anyone help me. If anyone need screenshot or code sample I can give that . Thank You
Make sure example
project works without PYTHONPATH
manipulations
Hello,
When I attempt to use django-su to switch to a different user, I get the error "User not found". Nothing comes back in the output of the built in Django server and that is all that shows. I am using Django 1.5.1 with the latest version of django-su.
Any ideas?
Hello!.
A couple of quick suggestions for the module, hoping you guys like them:
Thank you, and again, great work!
Hi!.
Great work with the plugin, it's really useful.
However, it looks like it doesn't like to work with django-suit. "Login as" works ok in the changelist, but it breaks completely the user form in the admin.
Thanks!
Two deprecations:
url
template tag with unquoted viewsadminmedia
Does django-su support Python 3?
If so, it would be nice to designate that on PyPI using classifiers in setup.py (see https://pypi.python.org/pypi?%3Aaction=list_classifiers).
If not, what does the path forward look like?
Change:
from tz_detect import __version__
to:
from django_su import __version__
Hi, I am trying to use this library but for some reason I cannot get it to work. I have followed all of the instructions but still I am getting an error saying that django_sudjango was not found (although I did not use django_sudjago anywhere as import)
I am pretty sure that I am doing something silly, but I would love to hear back from you.
Couldn't reopen issue #48, so I'll copy and paste here:
Hi, bashu!
Sorry it took me a bit more to test your changes.
User admin page now looks great and works great as well. In the beginning it was deleting my session, but I think it was because I didn't remove 0.5.0 before installing 0.5.1.
However, now selecting a user in the /su/login page gives me a CSRF error. It was working ok with 0.5.0 (which I reinstalled to be sure).
Also, I don't know why, the "Login as another user" button in that page looks different because the anchor tag is inside a List Item. I don't know if there's a way to fix that in the plug-in or if I should retouch the template. Here's a screenshot:
Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.