Move current user views to the user management app
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -90,6 +90,8 @@
|
||||
* Update authentication function views to use Django's new class
|
||||
based authentication views.
|
||||
* Expose Django's LOGOUT_REDIRECT_URL setting.
|
||||
* Move current user views from the common app to the user
|
||||
management app.
|
||||
|
||||
3.1.11 (2019-04-XX)
|
||||
===================
|
||||
|
||||
@@ -122,6 +122,8 @@ Other changes
|
||||
* Update authentication function views to use Django's new class
|
||||
based authentication views.
|
||||
* Expose Django's LOGOUT_REDIRECT_URL setting.
|
||||
* Move current user views from the common app to the user
|
||||
management app.
|
||||
|
||||
Removals
|
||||
--------
|
||||
|
||||
@@ -25,10 +25,9 @@ from .handlers import (
|
||||
user_locale_profile_session_config, user_locale_profile_create
|
||||
)
|
||||
from .links import (
|
||||
link_about, link_check_version, link_current_user_details,
|
||||
link_current_user_edit, link_current_user_locale_profile_edit,
|
||||
link_about, link_check_version, link_current_user_locale_profile_edit,
|
||||
link_license, link_object_error_list_clear, link_packages_licenses,
|
||||
link_setup, link_tools, separator_user_label, text_user_label
|
||||
link_setup, link_tools
|
||||
)
|
||||
|
||||
from .literals import DELETE_STALE_UPLOADS_INTERVAL, MESSAGE_SQLITE_WARNING
|
||||
@@ -135,10 +134,8 @@ class CommonApp(MayanAppConfig):
|
||||
)
|
||||
menu_user.bind_links(
|
||||
links=(
|
||||
separator_user_label, text_user_label,
|
||||
link_current_user_details, link_current_user_edit,
|
||||
link_current_user_locale_profile_edit,
|
||||
)
|
||||
), position=50
|
||||
)
|
||||
|
||||
menu_about.bind_links(
|
||||
|
||||
@@ -5,7 +5,6 @@ import os
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.contrib.admin.utils import label_for_field
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import FieldDoesNotExist, ImproperlyConfigured
|
||||
from django.db import models
|
||||
from django.utils.module_loading import import_string
|
||||
@@ -303,24 +302,3 @@ class PackagesLicensesForm(FileDisplayForm):
|
||||
self.fields['text'].initial = '\n\n'.join(
|
||||
['{}\n{}'.format(package.label, package.license_text) for package in Package.get_all()]
|
||||
)
|
||||
|
||||
|
||||
class UserForm(forms.ModelForm):
|
||||
"""
|
||||
Form used to edit an user's mininal fields by the user himself
|
||||
"""
|
||||
class Meta:
|
||||
fields = ('username', 'first_name', 'last_name', 'email')
|
||||
model = get_user_model()
|
||||
|
||||
|
||||
class UserForm_view(DetailForm):
|
||||
"""
|
||||
Form used to display an user's public details
|
||||
"""
|
||||
class Meta:
|
||||
fields = (
|
||||
'username', 'first_name', 'last_name', 'email', 'last_login',
|
||||
'date_joined', 'groups'
|
||||
)
|
||||
model = get_user_model()
|
||||
|
||||
@@ -6,8 +6,6 @@ icon_about = Icon(driver_name='fontawesome', symbol='info')
|
||||
icon_assign_remove_add = Icon(driver_name='fontawesome', symbol='plus')
|
||||
icon_assign_remove_remove = Icon(driver_name='fontawesome', symbol='minus')
|
||||
icon_check_version = Icon(driver_name='fontawesome', symbol='sync')
|
||||
icon_current_user_details = Icon(driver_name='fontawesome', symbol='user')
|
||||
icon_current_user_edit = Icon(driver_name='fontawesome', symbol='user')
|
||||
icon_current_user_locale_profile_details = Icon(
|
||||
driver_name='fontawesome', symbol='globe'
|
||||
)
|
||||
|
||||
@@ -4,18 +4,15 @@ from django.apps import apps
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.navigation import Link
|
||||
from mayan.apps.navigation.classes import Separator, Text
|
||||
|
||||
from .icons import (
|
||||
icon_about, icon_check_version, icon_current_user_details,
|
||||
icon_current_user_edit, icon_current_user_locale_profile_details,
|
||||
icon_about, icon_check_version, icon_current_user_locale_profile_details,
|
||||
icon_current_user_locale_profile_edit, icon_documentation,
|
||||
icon_forum, icon_license, icon_object_error_list_with_icon,
|
||||
icon_packages_licenses, icon_setup, icon_source_code, icon_support,
|
||||
icon_tools
|
||||
)
|
||||
from .permissions_runtime import permission_error_log_view
|
||||
from .utils import get_user_label_text
|
||||
|
||||
|
||||
def get_kwargs_factory(variable_name):
|
||||
@@ -43,14 +40,6 @@ link_check_version = Link(
|
||||
icon_class=icon_check_version, text=_('Check for updates'),
|
||||
view='common:check_version_view'
|
||||
)
|
||||
link_current_user_details = Link(
|
||||
icon_class=icon_current_user_details, text=_('User details'),
|
||||
view='common:current_user_details'
|
||||
)
|
||||
link_current_user_edit = Link(
|
||||
icon_class=icon_current_user_edit, text=_('Edit details'),
|
||||
view='common:current_user_edit'
|
||||
)
|
||||
link_current_user_locale_profile_details = Link(
|
||||
icon_class=icon_current_user_locale_profile_details,
|
||||
text=_('Locale profile'),
|
||||
@@ -106,5 +95,3 @@ link_support = Link(
|
||||
link_tools = Link(
|
||||
icon_class=icon_tools, text=_('Tools'), view='common:tools_list'
|
||||
)
|
||||
separator_user_label = Separator()
|
||||
text_user_label = Text(text=get_user_label_text)
|
||||
|
||||
@@ -7,10 +7,9 @@ from .api_views import (
|
||||
APIContentTypeList, APITemplateDetailView, APITemplateListView
|
||||
)
|
||||
from .views import (
|
||||
AboutView, CheckVersionView, CurrentUserDetailsView, CurrentUserEditView,
|
||||
CurrentUserLocaleProfileDetailsView, CurrentUserLocaleProfileEditView,
|
||||
FaviconRedirectView, HomeView, LicenseView,
|
||||
ObjectErrorLogEntryListClearView, ObjectErrorLogEntryListView,
|
||||
AboutView, CheckVersionView, CurrentUserLocaleProfileDetailsView,
|
||||
CurrentUserLocaleProfileEditView, FaviconRedirectView, HomeView,
|
||||
LicenseView, ObjectErrorLogEntryListClearView, ObjectErrorLogEntryListView,
|
||||
PackagesLicensesView, RootView, SetupListView, ToolsListView,
|
||||
multi_object_action_view
|
||||
)
|
||||
@@ -34,14 +33,6 @@ urlpatterns = [
|
||||
),
|
||||
url(regex=r'^setup/$', view=SetupListView.as_view(), name='setup_list'),
|
||||
url(regex=r'^tools/$', view=ToolsListView.as_view(), name='tools_list'),
|
||||
url(
|
||||
regex=r'^user/$', view=CurrentUserDetailsView.as_view(),
|
||||
name='current_user_details'
|
||||
),
|
||||
url(
|
||||
regex=r'^user/edit/$', view=CurrentUserEditView.as_view(),
|
||||
name='current_user_edit'
|
||||
),
|
||||
url(
|
||||
regex=r'^user/locale/$',
|
||||
view=CurrentUserLocaleProfileDetailsView.as_view(),
|
||||
|
||||
@@ -13,7 +13,6 @@ from django.utils.http import (
|
||||
urlencode as django_urlencode, urlquote as django_urlquote
|
||||
)
|
||||
from django.utils.six.moves import reduce as reduce_function, xmlrpc_client
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
import mayan
|
||||
from mayan.apps.common.compat import dict_type, dictionary_type
|
||||
@@ -46,13 +45,6 @@ def encapsulate(function):
|
||||
return lambda: function
|
||||
|
||||
|
||||
def get_user_label_text(context):
|
||||
if not context['request'].user.is_authenticated:
|
||||
return _('Anonymous')
|
||||
else:
|
||||
return context['request'].user.get_full_name() or context['request'].user
|
||||
|
||||
|
||||
def introspect_attribute(attribute_name, obj):
|
||||
"""
|
||||
Resolve the attribute of model. Supports nested reference using dotted
|
||||
|
||||
@@ -19,7 +19,7 @@ from mayan.apps.acls.models import AccessControlList
|
||||
from .exceptions import NotLatestVersion, UnknownLatestVersion
|
||||
from .forms import (
|
||||
LicenseForm, LocaleProfileForm, LocaleProfileForm_view,
|
||||
PackagesLicensesForm, UserForm, UserForm_view
|
||||
PackagesLicensesForm
|
||||
)
|
||||
from .generics import ( # NOQA
|
||||
AssignRemoveView, ConfirmView, FormView, MultiFormView,
|
||||
@@ -66,28 +66,6 @@ class CheckVersionView(SimpleView):
|
||||
}
|
||||
|
||||
|
||||
class CurrentUserDetailsView(SingleObjectDetailView):
|
||||
form_class = UserForm_view
|
||||
|
||||
def get_object(self):
|
||||
return self.request.user
|
||||
|
||||
def get_extra_context(self, **kwargs):
|
||||
return {
|
||||
'object': None,
|
||||
'title': _('Current user details'),
|
||||
}
|
||||
|
||||
|
||||
class CurrentUserEditView(SingleObjectEditView):
|
||||
extra_context = {'object': None, 'title': _('Edit current user details')}
|
||||
form_class = UserForm
|
||||
post_action_redirect = reverse_lazy('common:current_user_details')
|
||||
|
||||
def get_object(self):
|
||||
return self.request.user
|
||||
|
||||
|
||||
class CurrentUserLocaleProfileDetailsView(TemplateView):
|
||||
template_name = 'appearance/generic_form.html'
|
||||
|
||||
@@ -190,7 +168,7 @@ class ObjectErrorLogEntryListClearView(ConfirmView):
|
||||
def view_action(self):
|
||||
self.get_object().error_logs.all().delete()
|
||||
messages.success(
|
||||
message_('Object error log cleared successfully'),
|
||||
message=_('Object error log cleared successfully'),
|
||||
request=self.request
|
||||
)
|
||||
|
||||
|
||||
@@ -96,4 +96,6 @@ class EventsApp(MayanAppConfig):
|
||||
sources=('events:user_notifications_list',)
|
||||
)
|
||||
menu_tools.bind_links(links=(link_events_list,))
|
||||
menu_user.bind_links(links=(link_event_types_subscriptions_list,))
|
||||
menu_user.bind_links(
|
||||
links=(link_event_types_subscriptions_list,), position=50
|
||||
)
|
||||
|
||||
@@ -10,7 +10,7 @@ from mayan.apps.acls.links import link_acl_list
|
||||
from mayan.apps.acls.permissions import permission_acl_edit, permission_acl_view
|
||||
from mayan.apps.common.apps import MayanAppConfig
|
||||
from mayan.apps.common.menus import (
|
||||
menu_multi_item, menu_object, menu_secondary, menu_setup
|
||||
menu_multi_item, menu_object, menu_secondary, menu_setup, menu_user
|
||||
)
|
||||
from mayan.apps.common.widgets import TwoStateWidget
|
||||
from mayan.apps.metadata import MetadataLookup
|
||||
@@ -19,11 +19,13 @@ from mayan.apps.rest_api.fields import DynamicSerializerField
|
||||
|
||||
from .handlers import handler_initialize_new_user_options
|
||||
from .links import (
|
||||
link_group_create, link_group_delete, link_group_edit, link_group_list,
|
||||
link_group_members, link_group_setup, link_user_create, link_user_delete,
|
||||
link_user_edit, link_user_groups, link_user_list,
|
||||
link_user_multiple_delete, link_user_multiple_set_password,
|
||||
link_user_set_options, link_user_set_password, link_user_setup
|
||||
link_current_user_details, link_current_user_edit, link_group_create,
|
||||
link_group_delete, link_group_edit, link_group_list, link_group_members,
|
||||
link_group_setup, link_user_create, link_user_delete, link_user_edit,
|
||||
link_user_groups, link_user_list, link_user_multiple_delete,
|
||||
link_user_multiple_set_password, link_user_set_options,
|
||||
link_user_set_password, link_user_setup, separator_user_label,
|
||||
text_user_label
|
||||
)
|
||||
from .permissions import (
|
||||
permission_group_delete, permission_group_edit,
|
||||
@@ -145,6 +147,12 @@ class UserManagementApp(MayanAppConfig):
|
||||
)
|
||||
)
|
||||
menu_setup.bind_links(links=(link_user_setup, link_group_setup))
|
||||
menu_user.bind_links(
|
||||
links=(
|
||||
text_user_label, separator_user_label,
|
||||
link_current_user_details, link_current_user_edit,
|
||||
), position=0
|
||||
)
|
||||
|
||||
post_save.connect(
|
||||
dispatch_uid='user_management_handler_initialize_new_user_options',
|
||||
|
||||
@@ -5,6 +5,9 @@ from django.contrib.auth import get_user_model
|
||||
|
||||
|
||||
class UserForm(forms.ModelForm):
|
||||
"""
|
||||
Form used to edit an user's mininal fields by the user himself
|
||||
"""
|
||||
class Meta:
|
||||
fields = (
|
||||
'username', 'first_name', 'last_name', 'email', 'is_active',
|
||||
|
||||
@@ -2,6 +2,8 @@ from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from mayan.apps.appearance.classes import Icon
|
||||
|
||||
icon_current_user_details = Icon(driver_name='fontawesome', symbol='user')
|
||||
icon_current_user_edit = Icon(driver_name='fontawesome', symbol='user')
|
||||
icon_group_create = Icon(driver_name='fontawesome', symbol='plus')
|
||||
icon_group_setup = Icon(driver_name='fontawesome', symbol='users')
|
||||
icon_user_create = Icon(driver_name='fontawesome', symbol='plus')
|
||||
|
||||
@@ -2,17 +2,27 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.navigation import Link
|
||||
from mayan.apps.navigation.classes import Link, Separator, Text
|
||||
|
||||
from .icons import (
|
||||
icon_group_create, icon_group_setup, icon_user_create, icon_user_setup
|
||||
icon_current_user_details, icon_current_user_edit, icon_group_create,
|
||||
icon_group_setup, icon_user_create, icon_user_setup
|
||||
)
|
||||
from .permissions import (
|
||||
permission_group_create, permission_group_delete, permission_group_edit,
|
||||
permission_group_view, permission_user_create, permission_user_delete,
|
||||
permission_user_edit, permission_user_view
|
||||
)
|
||||
from .utils import get_user_label_text
|
||||
|
||||
link_current_user_details = Link(
|
||||
icon_class=icon_current_user_details, text=_('User details'),
|
||||
view='user_management:current_user_details'
|
||||
)
|
||||
link_current_user_edit = Link(
|
||||
icon_class=icon_current_user_edit, text=_('Edit details'),
|
||||
view='user_management:current_user_edit'
|
||||
)
|
||||
link_group_create = Link(
|
||||
icon_class=icon_group_create, permissions=(permission_group_create,),
|
||||
text=_('Create new group'), view='user_management:group_create'
|
||||
@@ -77,3 +87,5 @@ link_user_setup = Link(
|
||||
icon_class=icon_user_setup, permissions=(permission_user_view,),
|
||||
text=_('Users'), view='user_management:user_list'
|
||||
)
|
||||
separator_user_label = Separator()
|
||||
text_user_label = Text(text=get_user_label_text)
|
||||
|
||||
@@ -7,12 +7,24 @@ from .api_views import (
|
||||
APIUserListView, APIUserView
|
||||
)
|
||||
from .views import (
|
||||
GroupCreateView, GroupDeleteView, GroupEditView, GroupListView,
|
||||
GroupMembersView, UserCreateView, UserDeleteView, UserEditView,
|
||||
UserGroupsView, UserListView, UserOptionsEditView, UserSetPasswordView
|
||||
CurrentUserDetailsView, CurrentUserEditView, GroupCreateView,
|
||||
GroupDeleteView, GroupEditView, GroupListView, GroupMembersView,
|
||||
UserCreateView, UserDeleteView, UserEditView, UserGroupsView, UserListView,
|
||||
UserOptionsEditView, UserSetPasswordView
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
urlpatterns_current_user = [
|
||||
url(
|
||||
regex=r'^user/$', view=CurrentUserDetailsView.as_view(),
|
||||
name='current_user_details'
|
||||
),
|
||||
url(
|
||||
regex=r'^user/edit/$', view=CurrentUserEditView.as_view(),
|
||||
name='current_user_edit'
|
||||
)
|
||||
]
|
||||
|
||||
urlpatterns_groups = [
|
||||
url(
|
||||
regex=r'^group/list/$', view=GroupListView.as_view(), name='group_list'
|
||||
),
|
||||
@@ -31,43 +43,50 @@ urlpatterns = [
|
||||
url(
|
||||
regex=r'^group/(?P<pk>\d+)/members/$', view=GroupMembersView.as_view(),
|
||||
name='group_members'
|
||||
),
|
||||
)
|
||||
]
|
||||
|
||||
url(regex=r'^user/list/$', view=UserListView.as_view(), name='user_list'),
|
||||
urlpatterns_users = [
|
||||
url(regex=r'^users/$', view=UserListView.as_view(), name='user_list'),
|
||||
url(
|
||||
regex=r'^user/create/$', view=UserCreateView.as_view(),
|
||||
regex=r'^users/create/$', view=UserCreateView.as_view(),
|
||||
name='user_create'
|
||||
),
|
||||
url(
|
||||
regex=r'^user/(?P<pk>\d+)/edit/$', view=UserEditView.as_view(),
|
||||
regex=r'^users/(?P<pk>\d+)/edit/$', view=UserEditView.as_view(),
|
||||
name='user_edit'
|
||||
),
|
||||
url(
|
||||
regex=r'^user/(?P<pk>\d+)/delete/$', view=UserDeleteView.as_view(),
|
||||
regex=r'^users/(?P<pk>\d+)/delete/$', view=UserDeleteView.as_view(),
|
||||
name='user_delete'
|
||||
),
|
||||
url(
|
||||
regex=r'^user/multiple/delete/$', view=UserDeleteView.as_view(),
|
||||
regex=r'^users/multiple/delete/$', view=UserDeleteView.as_view(),
|
||||
name='user_multiple_delete'
|
||||
),
|
||||
url(
|
||||
regex=r'^user/(?P<pk>\d+)/set_password/$',
|
||||
regex=r'^users/(?P<pk>\d+)/set_password/$',
|
||||
view=UserSetPasswordView.as_view(), name='user_set_password'
|
||||
),
|
||||
url(
|
||||
regex=r'^user/multiple/set_password/$',
|
||||
regex=r'^users/multiple/set_password/$',
|
||||
view=UserSetPasswordView.as_view(), name='user_multiple_set_password'
|
||||
),
|
||||
url(
|
||||
regex=r'^user/(?P<pk>\d+)/groups/$', view=UserGroupsView.as_view(),
|
||||
regex=r'^users/(?P<pk>\d+)/groups/$', view=UserGroupsView.as_view(),
|
||||
name='user_groups'
|
||||
),
|
||||
url(
|
||||
regex=r'^user/(?P<pk>\d+)/options/$',
|
||||
regex=r'^users/(?P<pk>\d+)/options/$',
|
||||
view=UserOptionsEditView.as_view(), name='user_options'
|
||||
),
|
||||
]
|
||||
|
||||
urlpatterns = []
|
||||
urlpatterns.extend(urlpatterns_groups)
|
||||
urlpatterns.extend(urlpatterns_current_user)
|
||||
urlpatterns.extend(urlpatterns_users)
|
||||
|
||||
api_urls = [
|
||||
url(regex=r'^groups/$', view=APIGroupListView.as_view(), name='group-list'),
|
||||
url(
|
||||
|
||||
10
mayan/apps/user_management/utils.py
Normal file
10
mayan/apps/user_management/utils.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
def get_user_label_text(context):
|
||||
if not context['request'].user.is_authenticated:
|
||||
return _('Anonymous')
|
||||
else:
|
||||
return context['request'].user.get_full_name() or context['request'].user
|
||||
@@ -16,7 +16,8 @@ from mayan.apps.acls.models import AccessControlList
|
||||
from mayan.apps.common.views import (
|
||||
AssignRemoveView, MultipleObjectConfirmActionView,
|
||||
MultipleObjectFormActionView, SingleObjectCreateView,
|
||||
SingleObjectDeleteView, SingleObjectEditView, SingleObjectListView
|
||||
SingleObjectDeleteView, SingleObjectDetailView, SingleObjectEditView,
|
||||
SingleObjectListView
|
||||
)
|
||||
|
||||
from .forms import UserForm
|
||||
@@ -29,6 +30,33 @@ from .permissions import (
|
||||
)
|
||||
|
||||
|
||||
class CurrentUserDetailsView(SingleObjectDetailView):
|
||||
fields = (
|
||||
'username', 'first_name', 'last_name', 'email', 'last_login',
|
||||
'date_joined', 'groups'
|
||||
)
|
||||
|
||||
def get_object(self):
|
||||
return self.request.user
|
||||
|
||||
def get_extra_context(self, **kwargs):
|
||||
return {
|
||||
'object': None,
|
||||
'title': _('Current user details'),
|
||||
}
|
||||
|
||||
|
||||
class CurrentUserEditView(SingleObjectEditView):
|
||||
extra_context = {'object': None, 'title': _('Edit current user details')}
|
||||
form_class = UserForm
|
||||
post_action_redirect = reverse_lazy(
|
||||
viewname='user_management:current_user_details'
|
||||
)
|
||||
|
||||
def get_object(self):
|
||||
return self.request.user
|
||||
|
||||
|
||||
class GroupCreateView(SingleObjectCreateView):
|
||||
extra_context = {'title': _('Create new group')}
|
||||
fields = ('name',)
|
||||
@@ -166,8 +194,9 @@ class UserCreateView(SingleObjectCreateView):
|
||||
return HttpResponseRedirect(
|
||||
reverse(
|
||||
viewname='user_management:user_set_password', kwargs={
|
||||
'pk': user.pk}
|
||||
)
|
||||
'pk': user.pk
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user