Skip to content

Commit

Permalink
Merge pull request #2149 from wiltso/admin-contact-login
Browse files Browse the repository at this point in the history
Admin: contact login & user de- / activation steps
  • Loading branch information
chessbr committed Apr 24, 2020
2 parents 19d53b8 + 4eae7cc commit 6fbecbe
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ List all changes after the last release here (newer on top). Each change on a se

### Added

- Admin: Ability to login as the selected contact if it's a user

### Fixed

- Admin: Now when activating/deactivating user it's contact will also change
- Admin: New notification for when a account get's reactivated

## [1.10.11] - 2020-04-23
Expand Down
20 changes: 10 additions & 10 deletions shuup/admin/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-24 14:35+0000\n"
"POT-Creation-Date: 2020-04-23 21:28+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: en <LL@li.org>\n"
Expand Down Expand Up @@ -351,6 +351,12 @@ msgstr ""
msgid "Actions"
msgstr ""

msgid "Login as User"
msgstr ""

msgid "Login as Staff User"
msgstr ""

msgid "Edit"
msgstr ""

Expand Down Expand Up @@ -382,6 +388,9 @@ msgstr ""
msgid "Company"
msgstr ""

msgid "Staff"
msgstr ""

msgid "Email"
msgstr ""

Expand Down Expand Up @@ -1436,9 +1445,6 @@ msgid ""
"products."
msgstr ""

msgid "Staff"
msgstr ""

msgid "Select staff members for this shop."
msgstr ""

Expand Down Expand Up @@ -1642,12 +1648,6 @@ msgstr ""
msgid "Deactivate User"
msgstr ""

msgid "Login as User"
msgstr ""

msgid "Login as Staff User"
msgstr ""

#, python-format
msgid "User bound to contact %(contact)s."
msgstr ""
Expand Down
28 changes: 28 additions & 0 deletions shuup/admin/modules/contacts/views/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _
from django.views.generic import DetailView
from django.contrib.auth.models import User

from shuup.admin.modules.contacts.utils import (
check_contact_permission, request_limited
Expand All @@ -28,6 +29,7 @@
from shuup.apps.provides import get_provide_objects
from shuup.core.models import CompanyContact, Contact
from shuup.front.apps.registration.signals import company_contact_activated
from shuup.admin.modules.users.views.detail import get_admin_url, get_front_url
from shuup.utils.deprecation import RemovedFromShuupWarning
from shuup.utils.excs import Problem

Expand Down Expand Up @@ -134,6 +136,31 @@ def build_provides_buttons(self):
RemovedFromShuupWarning)
self.append(button(self.contact))

def build_login_as_button(self):
user = self.contact.user if hasattr(self.contact, "user") else None
current_user = self.request.user
if isinstance(user, User):
has_privileges = bool(
getattr(current_user, "is_superuser", False) or
getattr(current_user, "is_staff", False)
)
can_impersonate = bool(
has_privileges and user.is_active and not user.is_superuser
)

if (can_impersonate and get_front_url() and not user.is_staff):
self.append(PostActionButton(
post_url=reverse("shuup_admin:user.login-as", kwargs={"pk": user.pk}),
text=_(u"Login as User"),
extra_css_class="btn-inverse"
))
elif (can_impersonate and get_admin_url() and user.is_staff):
self.append(PostActionButton(
post_url=reverse("shuup_admin:user.login-as-staff", kwargs={"pk": user.pk}),
text=_(u"Login as Staff User"),
extra_css_class="btn-inverse"
))

def build(self):
self.append(URLActionButton(
url=reverse("shuup_admin:contact.edit", kwargs={"pk": self.contact.pk}),
Expand All @@ -146,6 +173,7 @@ def build(self):
self.build_user_button()
self.build_new_order_button()
self.build_provides_buttons()
self.build_login_as_button()


class ContactDetailView(DetailView):
Expand Down
5 changes: 5 additions & 0 deletions shuup/admin/modules/users/views/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ def _handle_set_is_active(self):

self.object.is_active = state
self.object.save(update_fields=("is_active",))

if hasattr(self.object, "contact"):
self.object.contact.is_active = state
self.object.contact.save(update_fields=("is_active",))

messages.success(self.request, _("%(user)s is now %(state)s.") % {
"user": self.object,
"state": _("active") if state else _("inactive")
Expand Down

0 comments on commit 6fbecbe

Please sign in to comment.