mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-17 11:10:23 +00:00
users: Make UI close to rest of the apps
- Provide an app title, description and link to manual page. - Use AppView and app.html to present most of the elements. - Remove tabs and turn create user into a button. Tested by running: py.test-3 --include-functional -k users-groups Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
03f5ca0b05
commit
ad0552adf6
@ -24,7 +24,8 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from plinth import action_utils, actions
|
||||
from plinth import app as app_module
|
||||
from plinth import menu
|
||||
from plinth import cfg, menu
|
||||
from plinth.utils import format_lazy
|
||||
|
||||
version = 2
|
||||
|
||||
@ -45,6 +46,20 @@ first_boot_steps = [
|
||||
|
||||
name = _('Users and Groups')
|
||||
|
||||
description = [
|
||||
_('Create and managed user accounts. These accounts serve as centralized '
|
||||
'authentication mechanism for most apps. Some apps further require a '
|
||||
'user account to be part of a group to authorize the user to access the '
|
||||
'app.'),
|
||||
format_lazy(
|
||||
_('Any user may login to {box_name} web interface to see a list of '
|
||||
'apps relevant to them in the home page. However, only users of '
|
||||
'the <em>admin</em> group may alter apps or system settings.'),
|
||||
box_name=_(cfg.box_name))
|
||||
]
|
||||
|
||||
manual_page = 'Users'
|
||||
|
||||
# All FreedomBox user groups
|
||||
groups = dict()
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
{% extends "base.html" %}
|
||||
{% extends "app.html" %}
|
||||
{% comment %}
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
@ -33,7 +33,17 @@
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% block status %}
|
||||
<a href="{% url 'users:create' %}" class="btn btn-primary"
|
||||
role="button" title="{% trans 'Create User' %}">
|
||||
<span class="fa fa-plus" aria-hidden="true"></span>
|
||||
{% trans 'Create User' %}
|
||||
</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block configuration %}
|
||||
|
||||
<h3>{% trans "Users" %}</h3>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
@ -64,7 +74,6 @@
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% include "diagnostics_button.html" with module="users" enabled=True %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -29,29 +29,21 @@ from django.views.generic.edit import (CreateView, DeleteView, FormView,
|
||||
|
||||
from plinth import actions
|
||||
from plinth.errors import ActionError
|
||||
from plinth.modules import first_boot
|
||||
from plinth.modules import first_boot, users
|
||||
from plinth.utils import is_user_admin
|
||||
from plinth.views import AppView
|
||||
|
||||
from . import get_last_admin_user
|
||||
from .forms import (CreateUserForm, FirstBootForm, UserChangePasswordForm,
|
||||
UserUpdateForm)
|
||||
|
||||
subsubmenu = [{
|
||||
'url': reverse_lazy('users:index'),
|
||||
'text': ugettext_lazy('Users')
|
||||
}, {
|
||||
'url': reverse_lazy('users:create'),
|
||||
'text': ugettext_lazy('Create User')
|
||||
}]
|
||||
|
||||
|
||||
class ContextMixin(object):
|
||||
"""Mixin to add 'subsubmenu' and 'title' to the context."""
|
||||
"""Mixin to add 'title' to the template context."""
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Use self.title and the module-level subsubmenu"""
|
||||
"""Add self.title to template context."""
|
||||
context = super(ContextMixin, self).get_context_data(**kwargs)
|
||||
context['subsubmenu'] = subsubmenu
|
||||
context['title'] = getattr(self, 'title', '')
|
||||
return context
|
||||
|
||||
@ -76,11 +68,17 @@ class UserCreate(ContextMixin, SuccessMessageMixin, CreateView):
|
||||
return reverse('users:index')
|
||||
|
||||
|
||||
class UserList(ContextMixin, django.views.generic.ListView):
|
||||
class UserList(AppView, ContextMixin, django.views.generic.ListView):
|
||||
"""View to list users."""
|
||||
model = User
|
||||
template_name = 'users_list.html'
|
||||
title = ugettext_lazy('Users')
|
||||
name = users.name
|
||||
description = users.description
|
||||
app_id = 'users'
|
||||
show_status_block = False
|
||||
diagnostics_module_name = 'users'
|
||||
manual_page = users.manual_page
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
context = super(UserList, self).get_context_data(*args, **kwargs)
|
||||
@ -129,13 +127,6 @@ class UserUpdate(ContextMixin, SuccessMessageMixin, UpdateView):
|
||||
"""Return the URL to redirect to in case of successful updation."""
|
||||
return reverse('users:edit', kwargs={'slug': self.object.username})
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Use self.title and the module-level subsubmenu"""
|
||||
context = super(UserUpdate, self).get_context_data(**kwargs)
|
||||
if not is_user_admin(self.request):
|
||||
del context['subsubmenu']
|
||||
return context
|
||||
|
||||
|
||||
class UserDelete(ContextMixin, DeleteView):
|
||||
"""Handle deleting users, showing a confirmation dialog first.
|
||||
@ -207,13 +198,6 @@ class UserChangePassword(ContextMixin, SuccessMessageMixin, FormView):
|
||||
update_session_auth_hash(self.request, form.user)
|
||||
return super(UserChangePassword, self).form_valid(form)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Remove subsubmenu for non-admin users."""
|
||||
context = super(UserChangePassword, self).get_context_data(**kwargs)
|
||||
if not is_user_admin(self.request):
|
||||
del context['subsubmenu']
|
||||
return context
|
||||
|
||||
|
||||
class FirstBootView(django.views.generic.CreateView):
|
||||
"""Create user account and log the user in."""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user