2018-08-09 09:15:40 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
2017-01-15 23:01:18 +00:00
|
|
|
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
|
|
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
|
|
# quelques clics.
|
|
|
|
#
|
2020-04-17 14:48:27 +00:00
|
|
|
# Copyright © 2017-2020 Gabriel Détraz
|
|
|
|
# Copyright © 2017-2020 Lara Kermarec
|
|
|
|
# Copyright © 2017-2020 Augustin Lemesle
|
|
|
|
# Copyright © 2017-2020 Hugo Levy--Falk
|
|
|
|
# Copyright © 2017-2020 Jean-Romain Garnier
|
2017-01-15 23:01:18 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
2016-06-30 18:18:06 +00:00
|
|
|
# App de gestion des users pour re2o
|
2019-09-29 14:02:28 +00:00
|
|
|
# Lara Kermarec, Gabriel Détraz, Lemesle Augustin
|
2016-06-30 18:18:06 +00:00
|
|
|
# Gplv2
|
2017-10-14 20:10:07 +00:00
|
|
|
"""
|
2020-06-01 15:28:48 +00:00
|
|
|
Django users views module.
|
|
|
|
|
|
|
|
Here are defined all functions of views, for the users re2o application. This views
|
|
|
|
allow both edition, creation, deletion and diplay of users objects.
|
|
|
|
Here are view that allow the addition/deletion/edition of:
|
|
|
|
* Users (Club/Adherent) and derived settings like EmailSettings of users
|
|
|
|
* School
|
|
|
|
* Bans
|
|
|
|
* Whitelist
|
|
|
|
* Shell
|
|
|
|
* ServiceUser
|
|
|
|
|
|
|
|
Also add extra views for :
|
|
|
|
* Ask for reset password by email
|
|
|
|
* Ask for new email for email confirmation
|
|
|
|
* Register room and interface on user account with switch web redirection.
|
|
|
|
|
|
|
|
All the view must be as simple as possible, with returning the correct form to user during
|
|
|
|
get, and during post, performing change in database with simple ".save()" function.
|
|
|
|
|
|
|
|
The aim is to put all "intelligent" functions in both forms and models functions. In fact, this
|
|
|
|
will allow to user other frontend (like REST api) to perform editions, creations, etc on database,
|
|
|
|
without code duplication.
|
2017-10-14 20:10:07 +00:00
|
|
|
|
|
|
|
"""
|
2017-09-10 23:29:24 +00:00
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-10-26 15:58:41 +00:00
|
|
|
from django.urls import reverse
|
2016-12-12 12:32:18 +00:00
|
|
|
from django.shortcuts import get_object_or_404, render, redirect
|
2016-07-01 20:47:08 +00:00
|
|
|
from django.contrib import messages
|
2016-07-09 02:12:09 +00:00
|
|
|
from django.contrib.auth.decorators import login_required, permission_required
|
2018-06-27 19:37:13 +00:00
|
|
|
from django.db.models import ProtectedError, Count, Max
|
2016-07-03 00:15:17 +00:00
|
|
|
from django.utils import timezone
|
2016-07-21 14:58:12 +00:00
|
|
|
from django.db import transaction
|
2017-09-10 18:44:09 +00:00
|
|
|
from django.http import HttpResponse
|
2018-03-24 18:06:49 +00:00
|
|
|
from django.http import HttpResponseRedirect
|
2017-09-10 18:44:09 +00:00
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
2018-08-15 17:15:26 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2019-07-25 14:44:40 +00:00
|
|
|
from django.template import loader
|
2017-09-10 18:44:09 +00:00
|
|
|
|
|
|
|
from rest_framework.renderers import JSONRenderer
|
2018-04-14 23:16:49 +00:00
|
|
|
from reversion import revisions as reversion
|
2017-09-10 18:44:09 +00:00
|
|
|
|
2018-07-03 17:30:31 +00:00
|
|
|
from cotisations.models import Facture, Paiement
|
2018-04-14 23:16:49 +00:00
|
|
|
from machines.models import Machine
|
2019-07-10 09:16:37 +00:00
|
|
|
|
2018-07-10 21:36:01 +00:00
|
|
|
from preferences.models import OptionalUser, GeneralOption, AssoOption
|
2019-07-25 14:44:40 +00:00
|
|
|
from importlib import import_module
|
2020-05-18 14:52:53 +00:00
|
|
|
from django.conf import settings
|
2019-08-11 19:51:31 +00:00
|
|
|
from re2o.settings_local import OPTIONNAL_APPS_RE2O
|
2018-04-14 23:16:49 +00:00
|
|
|
from re2o.views import form
|
2020-04-21 15:37:17 +00:00
|
|
|
from re2o.utils import all_has_access, permission_tree
|
2019-11-04 16:55:03 +00:00
|
|
|
from re2o.base import re2o_paginator, SortTable
|
2018-04-14 23:16:49 +00:00
|
|
|
from re2o.acl import (
|
|
|
|
can_create,
|
|
|
|
can_edit,
|
|
|
|
can_delete_set,
|
|
|
|
can_delete,
|
|
|
|
can_view,
|
|
|
|
can_view_all,
|
2019-11-04 16:55:03 +00:00
|
|
|
can_change,
|
2018-04-14 23:16:49 +00:00
|
|
|
)
|
2018-07-16 18:14:26 +00:00
|
|
|
from cotisations.utils import find_payment_method
|
2018-10-03 00:58:55 +00:00
|
|
|
from topologie.models import Port
|
2018-04-14 23:16:49 +00:00
|
|
|
from .models import (
|
2017-11-20 03:41:29 +00:00
|
|
|
User,
|
|
|
|
Ban,
|
|
|
|
Whitelist,
|
|
|
|
School,
|
|
|
|
ListRight,
|
|
|
|
Request,
|
|
|
|
ServiceUser,
|
|
|
|
Adherent,
|
2017-11-28 18:41:14 +00:00
|
|
|
Club,
|
2018-03-24 18:06:49 +00:00
|
|
|
ListShell,
|
2018-08-01 11:06:25 +00:00
|
|
|
EMailAddress,
|
2017-11-20 03:41:29 +00:00
|
|
|
)
|
2018-04-14 23:16:49 +00:00
|
|
|
from .forms import (
|
2017-11-20 03:41:29 +00:00
|
|
|
BanForm,
|
|
|
|
WhitelistForm,
|
2018-08-01 11:06:25 +00:00
|
|
|
EMailAddressForm,
|
2018-07-30 15:00:41 +00:00
|
|
|
EmailSettingsForm,
|
2017-11-20 03:41:29 +00:00
|
|
|
DelSchoolForm,
|
|
|
|
DelListRightForm,
|
|
|
|
NewListRightForm,
|
|
|
|
StateForm,
|
|
|
|
SchoolForm,
|
2018-03-24 18:06:49 +00:00
|
|
|
ShellForm,
|
2017-11-20 03:41:29 +00:00
|
|
|
EditServiceUserForm,
|
|
|
|
ServiceUserForm,
|
|
|
|
ListRightForm,
|
2018-09-19 13:40:53 +00:00
|
|
|
AdherentCreationForm,
|
2018-09-20 06:39:48 +00:00
|
|
|
AdherentEditForm,
|
2017-11-20 03:41:29 +00:00
|
|
|
ClubForm,
|
|
|
|
MassArchiveForm,
|
|
|
|
PassForm,
|
|
|
|
ResetPasswordForm,
|
2017-12-31 16:11:19 +00:00
|
|
|
ClubAdminandMembersForm,
|
2018-08-28 18:18:09 +00:00
|
|
|
GroupForm,
|
2019-11-04 16:55:03 +00:00
|
|
|
InitialRegisterForm,
|
2017-11-20 03:41:29 +00:00
|
|
|
)
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2020-05-17 16:01:22 +00:00
|
|
|
import os
|
2018-04-14 01:25:05 +00:00
|
|
|
|
2017-11-28 21:54:13 +00:00
|
|
|
@can_create(Adherent)
|
2016-06-30 18:18:06 +00:00
|
|
|
def new_user(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for new Adherent/User form creation.
|
|
|
|
Then, send an email to the new user, and also if needed to
|
|
|
|
set its password.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User form.
|
|
|
|
|
|
|
|
"""
|
2020-05-17 10:51:05 +00:00
|
|
|
user = AdherentCreationForm(request.POST or None, request.FILES or None, user=request.user)
|
2020-04-19 18:06:34 +00:00
|
|
|
user.request = request
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
GTU_sum_up = GeneralOption.get_cached_value("GTU_sum_up")
|
|
|
|
GTU = GeneralOption.get_cached_value("GTU")
|
2020-04-21 15:37:17 +00:00
|
|
|
is_set_password_allowed = OptionalUser.get_cached_value(
|
|
|
|
"allow_set_password_during_user_creation"
|
|
|
|
)
|
2020-04-16 16:58:20 +00:00
|
|
|
|
2016-07-02 00:42:04 +00:00
|
|
|
if user.is_valid():
|
2020-04-17 18:53:10 +00:00
|
|
|
user = user.save()
|
|
|
|
|
2020-04-17 20:08:40 +00:00
|
|
|
if user.password:
|
2020-04-17 18:23:28 +00:00
|
|
|
user.send_confirm_email_if_necessary(request)
|
2020-04-16 16:58:20 +00:00
|
|
|
messages.success(
|
|
|
|
request,
|
2020-04-17 14:03:37 +00:00
|
|
|
_("The user %s was created, a confirmation email was sent.")
|
2020-04-16 16:58:20 +00:00
|
|
|
% user.pseudo,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
user.reset_passwd_mail(request)
|
|
|
|
messages.success(
|
|
|
|
request,
|
|
|
|
_("The user %s was created, an email to set the password was sent.")
|
|
|
|
% user.pseudo,
|
|
|
|
)
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": str(user.id)}))
|
2020-04-16 16:58:20 +00:00
|
|
|
|
|
|
|
# Anonymous users are allowed to create new accounts
|
|
|
|
# but they should be treated differently
|
|
|
|
params = {
|
2020-04-16 17:16:33 +00:00
|
|
|
"userform": user,
|
|
|
|
"GTU_sum_up": GTU_sum_up,
|
|
|
|
"GTU": GTU,
|
|
|
|
"showCGU": True,
|
|
|
|
"action_name": _("Commit"),
|
|
|
|
}
|
|
|
|
|
|
|
|
if is_set_password_allowed:
|
2020-04-16 16:58:20 +00:00
|
|
|
params["load_js_file"] = "/static/js/toggle_password_fields.js"
|
|
|
|
|
|
|
|
return form(params, "users/user.html", request)
|
2016-07-01 16:22:52 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2017-10-23 03:02:55 +00:00
|
|
|
@login_required
|
2017-11-28 21:54:13 +00:00
|
|
|
@can_create(Club)
|
2017-10-23 03:02:55 +00:00
|
|
|
def new_club(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for new Club/User form creation.
|
|
|
|
Then, send an email to the new user, and also if needed to
|
|
|
|
set its password.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User form.
|
|
|
|
|
|
|
|
"""
|
2020-05-17 10:51:05 +00:00
|
|
|
club = ClubForm(request.POST or None, request.FILES or None, user=request.user)
|
2020-04-19 18:06:34 +00:00
|
|
|
club.request = request
|
|
|
|
|
2017-10-23 03:02:55 +00:00
|
|
|
if club.is_valid():
|
|
|
|
club = club.save(commit=False)
|
2018-03-31 15:18:39 +00:00
|
|
|
club.save()
|
2017-10-23 03:02:55 +00:00
|
|
|
club.reset_passwd_mail(request)
|
2019-11-04 16:55:03 +00:00
|
|
|
messages.success(
|
|
|
|
request,
|
2019-11-20 00:52:11 +00:00
|
|
|
_("The club %s was created, an email to set the password was sent.")
|
2019-11-04 16:55:03 +00:00
|
|
|
% club.pseudo,
|
|
|
|
)
|
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": str(club.id)}))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"userform": club, "showCGU": False, "action_name": _("Create a club")},
|
|
|
|
"users/user.html",
|
|
|
|
request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2017-10-23 03:02:55 +00:00
|
|
|
|
|
|
|
|
2017-11-20 03:41:29 +00:00
|
|
|
@login_required
|
2017-12-08 20:59:21 +00:00
|
|
|
@can_edit(Club)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_club_admin_members(request, club_instance, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing clubs and administrators.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
club_instance: Club instance to edit
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User form.
|
|
|
|
|
|
|
|
"""
|
2020-05-17 10:51:05 +00:00
|
|
|
club = ClubAdminandMembersForm(request.POST or None, request.FILES or None, instance=club_instance)
|
2017-11-20 03:41:29 +00:00
|
|
|
if club.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if club.changed_data:
|
|
|
|
club.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The club was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("users:profil", kwargs={"userid": str(club_instance.id)})
|
|
|
|
)
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": club, "showCGU": False, "action_name": _("Edit"),},
|
2019-11-04 16:55:03 +00:00
|
|
|
"users/user.html",
|
|
|
|
request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2017-11-20 03:41:29 +00:00
|
|
|
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-11-30 12:42:33 +00:00
|
|
|
@can_edit(User)
|
2017-11-30 12:52:33 +00:00
|
|
|
def edit_info(request, user, userid):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing base user informations.
|
|
|
|
Perform an acl check on user instance.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
user: User instance to edit
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User form.
|
|
|
|
|
|
|
|
"""
|
2017-12-28 16:47:02 +00:00
|
|
|
if user.is_class_adherent:
|
2018-09-20 06:39:48 +00:00
|
|
|
user_form = AdherentEditForm(
|
2020-05-17 10:51:05 +00:00
|
|
|
request.POST or None, request.FILES or None, instance=user.adherent, user=request.user
|
2017-12-28 16:47:02 +00:00
|
|
|
)
|
2018-04-14 23:16:49 +00:00
|
|
|
else:
|
|
|
|
user_form = ClubForm(
|
2020-05-17 10:51:05 +00:00
|
|
|
request.POST or None, request.FILES or None,instance=user.club, user=request.user
|
2017-12-28 16:47:02 +00:00
|
|
|
)
|
2018-04-14 23:16:49 +00:00
|
|
|
if user_form.is_valid():
|
|
|
|
if user_form.changed_data:
|
2020-05-17 16:01:22 +00:00
|
|
|
user = user_form.save(commit=False)
|
|
|
|
former_user = Adherent.objects.get(pseudo=user.pseudo)
|
|
|
|
if former_user.profile_image:
|
|
|
|
if (user.profile_image and user.profile_image.url != former_user.profile_image.url) or (not user.profile_image):
|
2020-05-18 14:52:53 +00:00
|
|
|
former_image = settings.BASE_DIR+former_user.profile_image.url
|
2020-05-17 16:01:22 +00:00
|
|
|
os.remove(former_image)
|
2020-04-17 00:16:56 +00:00
|
|
|
user = user_form.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The user was edited."))
|
2020-04-17 00:16:56 +00:00
|
|
|
|
2020-04-17 18:53:10 +00:00
|
|
|
if user.send_confirm_email_if_necessary(request):
|
|
|
|
messages.success(request, _("Sent a new confirmation email."))
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": str(userid)}))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": user_form, "action_name": _("Edit")}, "users/user.html", request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2016-07-01 20:47:08 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2019-11-04 16:55:03 +00:00
|
|
|
@can_edit(User, "state")
|
2017-11-30 13:41:31 +00:00
|
|
|
def state(request, user, userid):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing state of user.
|
|
|
|
Perform an acl check on user instance, and check if editing user
|
|
|
|
has state edition permission.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
user: User instance to edit
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User form.
|
|
|
|
|
|
|
|
"""
|
2018-04-14 23:16:49 +00:00
|
|
|
state_form = StateForm(request.POST or None, instance=user)
|
|
|
|
if state_form.is_valid():
|
|
|
|
if state_form.changed_data:
|
2020-04-17 22:12:22 +00:00
|
|
|
user_instance = state_form.save()
|
|
|
|
messages.success(request, _("The states were edited."))
|
|
|
|
if user_instance.trigger_email_changed_state(request):
|
2020-04-21 15:37:17 +00:00
|
|
|
messages.success(
|
|
|
|
request, _("An email to confirm the address was sent.")
|
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": str(userid)}))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": state_form, "action_name": _("Edit")}, "users/user.html", request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2016-07-01 20:47:08 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2017-12-31 16:11:19 +00:00
|
|
|
@login_required
|
2019-11-04 16:55:03 +00:00
|
|
|
@can_edit(User, "groups")
|
2017-12-31 16:11:19 +00:00
|
|
|
def groups(request, user, userid):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing groups of user.
|
|
|
|
Perform an acl check on user instance, and check if editing user
|
|
|
|
has groups edition permission.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
user: User instance to edit
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
group_form = GroupForm(request.POST or None, instance=user, user=request.user)
|
2018-04-14 23:16:49 +00:00
|
|
|
if group_form.is_valid():
|
|
|
|
if group_form.changed_data:
|
|
|
|
group_form.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The groups were edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": str(userid)}))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": group_form, "action_name": _("Edit")}, "users/user.html", request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2017-12-31 16:11:19 +00:00
|
|
|
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2019-11-04 16:55:03 +00:00
|
|
|
@can_edit(User, "password")
|
2017-11-30 13:41:31 +00:00
|
|
|
def password(request, user, userid):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing password of user.
|
|
|
|
Perform an acl check on user instance, and check if editing user
|
|
|
|
has password edition permission.
|
|
|
|
If User instance is in critical groups, the edition requires extra
|
|
|
|
permission.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
user: User instance to edit password
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User form.
|
|
|
|
|
|
|
|
"""
|
2018-01-31 04:51:47 +00:00
|
|
|
u_form = PassForm(request.POST or None, instance=user, user=request.user)
|
2016-07-08 01:12:28 +00:00
|
|
|
if u_form.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if u_form.changed_data:
|
|
|
|
u_form.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The password was changed."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": str(userid)}))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"userform": u_form, "action_name": _("Change the password")},
|
|
|
|
"users/user.html",
|
|
|
|
request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2016-07-01 22:35:44 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2017-12-31 16:11:19 +00:00
|
|
|
@login_required
|
2019-11-04 16:55:03 +00:00
|
|
|
@can_edit(User, "groups")
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_group(request, user, listrightid, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing groups of user.
|
|
|
|
Perform an acl check on user instance, and check if editing user
|
|
|
|
has groups edition permission.
|
|
|
|
If User instance is in critical groups, the edition requires extra
|
|
|
|
permission.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
user: User instance to edit groups
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User form.
|
|
|
|
|
|
|
|
"""
|
2018-03-31 15:18:39 +00:00
|
|
|
user.groups.remove(ListRight.objects.get(id=listrightid))
|
|
|
|
user.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("%s was removed from the group.") % user)
|
2019-11-04 16:55:03 +00:00
|
|
|
return HttpResponseRedirect(request.META.get("HTTP_REFERER"))
|
2017-12-31 16:11:19 +00:00
|
|
|
|
|
|
|
|
2018-05-03 08:26:17 +00:00
|
|
|
@login_required
|
2019-11-04 16:55:03 +00:00
|
|
|
@can_edit(User, "is_superuser")
|
2018-05-03 08:26:17 +00:00
|
|
|
def del_superuser(request, user, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing superuser attribute of user.
|
|
|
|
Perform an acl check on user instance, and check if editing user
|
|
|
|
has edition of superuser flag on target user.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
user: User instance to edit superuser flag.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User form.
|
|
|
|
|
|
|
|
"""
|
2018-05-03 08:26:17 +00:00
|
|
|
user.is_superuser = False
|
|
|
|
user.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("%s is no longer superuser.") % user)
|
2019-11-04 16:55:03 +00:00
|
|
|
return HttpResponseRedirect(request.META.get("HTTP_REFERER"))
|
2018-05-03 08:26:17 +00:00
|
|
|
|
|
|
|
|
2017-06-18 12:59:53 +00:00
|
|
|
@login_required
|
2017-11-28 21:54:13 +00:00
|
|
|
@can_create(ServiceUser)
|
2017-06-18 12:59:53 +00:00
|
|
|
def new_serviceuser(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for creation of new serviceuser, for external services on
|
|
|
|
ldap tree for auth purpose (dokuwiki, owncloud, etc).
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of create new serviceuser.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django ServiceUser form.
|
|
|
|
|
|
|
|
"""
|
2017-06-18 12:59:53 +00:00
|
|
|
user = ServiceUserForm(request.POST or None)
|
|
|
|
if user.is_valid():
|
2018-05-02 19:10:28 +00:00
|
|
|
user.save()
|
2019-11-04 16:55:03 +00:00
|
|
|
messages.success(request, _("The service user was created."))
|
|
|
|
return redirect(reverse("users:index-serviceusers"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": user, "action_name": _("Add")}, "users/user.html", request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2017-06-18 12:59:53 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2017-06-18 12:59:53 +00:00
|
|
|
@login_required
|
2017-11-30 13:41:31 +00:00
|
|
|
@can_edit(ServiceUser)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_serviceuser(request, serviceuser, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for edition of serviceuser, for external services on
|
|
|
|
ldap tree for auth purpose (dokuwiki, owncloud, etc).
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of edit target serviceuser.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
serviceuser: ServiceUser instance to edit attributes.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django ServiceUser form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
serviceuser = EditServiceUserForm(request.POST or None, instance=serviceuser)
|
2018-04-10 17:12:28 +00:00
|
|
|
if serviceuser.is_valid():
|
|
|
|
if serviceuser.changed_data:
|
2018-05-02 19:10:28 +00:00
|
|
|
serviceuser.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The service user was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:index-serviceusers"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": serviceuser, "action_name": _("Edit")}, "users/user.html", request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2017-06-18 12:59:53 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2017-06-18 12:59:53 +00:00
|
|
|
@login_required
|
2017-12-09 01:15:11 +00:00
|
|
|
@can_delete(ServiceUser)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_serviceuser(request, serviceuser, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for removing serviceuser, for external services on
|
|
|
|
ldap tree for auth purpose (dokuwiki, owncloud, etc).
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of deleting target serviceuser.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
serviceuser: ServiceUser instance to delete.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django ServiceUser form.
|
|
|
|
|
|
|
|
"""
|
2017-06-18 12:59:53 +00:00
|
|
|
if request.method == "POST":
|
2018-04-10 17:12:28 +00:00
|
|
|
serviceuser.delete()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The service user was deleted."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:index-serviceusers"))
|
2017-10-14 20:10:07 +00:00
|
|
|
return form(
|
2019-11-20 00:52:11 +00:00
|
|
|
{"objet": serviceuser, "objet_name": _("service user")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"users/delete.html",
|
|
|
|
request,
|
2017-10-14 20:10:07 +00:00
|
|
|
)
|
|
|
|
|
2017-06-18 12:59:53 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-11-30 13:41:31 +00:00
|
|
|
@can_create(Ban)
|
|
|
|
@can_edit(User)
|
|
|
|
def add_ban(request, user, userid):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for adding a ban object for user instance.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of adding a ban on target user, add_ban.
|
|
|
|
Syntaxe: DD/MM/AAAA, the ban takes an immediate effect.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
user: User instance to add a ban.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Ban form.
|
|
|
|
|
|
|
|
"""
|
2016-07-02 20:31:50 +00:00
|
|
|
ban_instance = Ban(user=user)
|
|
|
|
ban = BanForm(request.POST or None, instance=ban_instance)
|
2020-04-19 18:06:34 +00:00
|
|
|
ban.request = request
|
|
|
|
|
2016-07-02 20:31:50 +00:00
|
|
|
if ban.is_valid():
|
2018-04-14 23:16:49 +00:00
|
|
|
ban.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The ban was added."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": str(userid)}))
|
2018-01-10 17:35:13 +00:00
|
|
|
if user.is_ban():
|
2019-11-04 16:55:03 +00:00
|
|
|
messages.error(request, _("Warning: this user already has an active ban."))
|
2020-04-21 15:37:17 +00:00
|
|
|
return form({"userform": ban, "action_name": _("Add")}, "users/user.html", request)
|
2018-04-14 01:25:05 +00:00
|
|
|
|
2016-07-02 20:31:50 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-08 20:59:21 +00:00
|
|
|
@can_edit(Ban)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_ban(request, ban_instance, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing a ban object for user instance.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of editing a ban on target user, edit_ban.
|
|
|
|
Syntaxe: DD/MM/AAAA, the ban takes an immediate effect.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
ban: Ban instance to edit.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Ban form.
|
|
|
|
|
|
|
|
"""
|
2016-07-02 20:31:50 +00:00
|
|
|
ban = BanForm(request.POST or None, instance=ban_instance)
|
2020-04-19 18:06:34 +00:00
|
|
|
ban.request = request
|
|
|
|
|
2016-07-02 20:31:50 +00:00
|
|
|
if ban.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if ban.changed_data:
|
|
|
|
ban.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The ban was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:index"))
|
2020-04-21 15:37:17 +00:00
|
|
|
return form({"userform": ban, "action_name": _("Edit")}, "users/user.html", request)
|
2016-07-02 20:31:50 +00:00
|
|
|
|
2018-07-03 17:30:31 +00:00
|
|
|
|
2018-06-17 12:13:10 +00:00
|
|
|
@login_required
|
|
|
|
@can_delete(Ban)
|
|
|
|
def del_ban(request, ban, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for removing a ban object for user instance.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of deleting a ban on target user, del_ban.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
ban: Ban instance to delete.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Ban form.
|
|
|
|
|
|
|
|
"""
|
2018-07-03 17:30:31 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
ban.delete()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The ban was deleted."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": str(ban.user.id)}))
|
2019-11-20 00:52:11 +00:00
|
|
|
return form({"objet": ban, "objet_name": _("ban")}, "users/delete.html", request)
|
2018-06-17 12:13:10 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-08 20:59:21 +00:00
|
|
|
@can_create(Whitelist)
|
|
|
|
@can_edit(User)
|
|
|
|
def add_whitelist(request, user, userid):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for adding a whitelist object for user instance.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of adding a wheitelist on target user, add_whitelist.
|
|
|
|
Syntaxe: DD/MM/AAAA, the whitelist takes an immediate effect.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
user: User instance to add a whitelist.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Whitelist form.
|
|
|
|
|
|
|
|
"""
|
2016-07-04 18:04:11 +00:00
|
|
|
whitelist_instance = Whitelist(user=user)
|
2019-11-04 16:55:03 +00:00
|
|
|
whitelist = WhitelistForm(request.POST or None, instance=whitelist_instance)
|
2016-07-04 18:04:11 +00:00
|
|
|
if whitelist.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
whitelist.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The whitelist was added."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": str(userid)}))
|
2018-01-10 17:35:13 +00:00
|
|
|
if user.is_whitelisted():
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(
|
2019-11-04 16:55:03 +00:00
|
|
|
request, _("Warning: this user already has an active whitelist.")
|
2016-07-08 01:12:28 +00:00
|
|
|
)
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": whitelist, "action_name": _("Add")}, "users/user.html", request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2016-07-04 18:04:11 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-08 20:59:21 +00:00
|
|
|
@can_edit(Whitelist)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_whitelist(request, whitelist_instance, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing a whitelist object for user instance.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of editing a whitelist on target user, edit_whitelist.
|
|
|
|
Syntaxe: DD/MM/AAAA, the whitelist takes an immediate effect.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
whitelist: whitelist instance to edit.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Whitelist form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
whitelist = WhitelistForm(request.POST or None, instance=whitelist_instance)
|
2016-07-04 18:04:11 +00:00
|
|
|
if whitelist.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if whitelist.changed_data:
|
|
|
|
whitelist.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The whitelist was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:index"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": whitelist, "action_name": _("Edit")}, "users/user.html", request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2016-07-04 18:04:11 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2018-06-17 13:12:12 +00:00
|
|
|
@login_required
|
|
|
|
@can_delete(Whitelist)
|
|
|
|
def del_whitelist(request, whitelist, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for removing a whitelist object for user instance.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of deleting a whitelist on target user, del_whitelist.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
whitelist: Whitelist instance to delete.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Whitelist form.
|
|
|
|
|
|
|
|
"""
|
2018-07-03 17:30:31 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
whitelist.delete()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The whitelist was deleted."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("users:profil", kwargs={"userid": str(whitelist.user.id)})
|
|
|
|
)
|
2018-07-03 17:30:31 +00:00
|
|
|
return form(
|
2019-11-20 00:52:11 +00:00
|
|
|
{"objet": whitelist, "objet_name": _("whitelist")}, "users/delete.html", request
|
2018-07-03 17:30:31 +00:00
|
|
|
)
|
|
|
|
|
2018-06-17 13:12:12 +00:00
|
|
|
|
2018-06-26 16:46:57 +00:00
|
|
|
@login_required
|
2018-08-01 11:06:25 +00:00
|
|
|
@can_create(EMailAddress)
|
2018-06-26 16:46:57 +00:00
|
|
|
@can_edit(User)
|
2018-08-01 11:06:25 +00:00
|
|
|
def add_emailaddress(request, user, userid):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for adding an emailaddress object for user instance.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of adding an emailaddress on target user.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
user: User instance to add an emailaddress.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django EmailAddress form.
|
|
|
|
|
|
|
|
"""
|
2018-08-01 11:06:25 +00:00
|
|
|
emailaddress_instance = EMailAddress(user=user)
|
|
|
|
emailaddress = EMailAddressForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=emailaddress_instance
|
2018-06-26 16:46:57 +00:00
|
|
|
)
|
2018-08-01 11:06:25 +00:00
|
|
|
if emailaddress.is_valid():
|
|
|
|
emailaddress.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The local email account was created."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": str(userid)}))
|
2018-06-26 16:46:57 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": emailaddress, "showCGU": False, "action_name": _("Add"),},
|
2019-11-04 16:55:03 +00:00
|
|
|
"users/user.html",
|
|
|
|
request,
|
2018-06-26 16:46:57 +00:00
|
|
|
)
|
|
|
|
|
2018-07-30 15:00:41 +00:00
|
|
|
|
2018-06-26 16:46:57 +00:00
|
|
|
@login_required
|
2018-08-01 11:06:25 +00:00
|
|
|
@can_edit(EMailAddress)
|
|
|
|
def edit_emailaddress(request, emailaddress_instance, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for edit an emailaddress object for user instance.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of editing an emailaddress on target user.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
emailaddress: Emailaddress to edit.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django EmailAddress form.
|
|
|
|
|
|
|
|
"""
|
2018-08-01 11:06:25 +00:00
|
|
|
emailaddress = EMailAddressForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=emailaddress_instance
|
2018-06-26 16:46:57 +00:00
|
|
|
)
|
2018-08-01 11:06:25 +00:00
|
|
|
if emailaddress.is_valid():
|
|
|
|
if emailaddress.changed_data:
|
|
|
|
emailaddress.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The local email account was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse(
|
|
|
|
"users:profil", kwargs={"userid": str(emailaddress_instance.user.id)}
|
|
|
|
)
|
|
|
|
)
|
2018-06-26 16:46:57 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": emailaddress, "showCGU": False, "action_name": _("Edit"),},
|
2019-11-04 16:55:03 +00:00
|
|
|
"users/user.html",
|
|
|
|
request,
|
2018-06-26 16:46:57 +00:00
|
|
|
)
|
|
|
|
|
2018-07-30 15:00:41 +00:00
|
|
|
|
2018-06-26 16:46:57 +00:00
|
|
|
@login_required
|
2018-08-01 11:06:25 +00:00
|
|
|
@can_delete(EMailAddress)
|
|
|
|
def del_emailaddress(request, emailaddress, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for deleting an emailaddress object for user instance.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of deleting an emailaddress on target user.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
emailaddress: Emailaddress to delete.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django EmailAddress form.
|
|
|
|
|
|
|
|
"""
|
2018-07-30 15:00:41 +00:00
|
|
|
if request.method == "POST":
|
2018-08-01 11:06:25 +00:00
|
|
|
emailaddress.delete()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The local email account was deleted."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("users:profil", kwargs={"userid": str(emailaddress.user.id)})
|
|
|
|
)
|
2018-07-30 15:00:41 +00:00
|
|
|
return form(
|
2019-11-20 00:52:11 +00:00
|
|
|
{"objet": emailaddress, "objet_name": _("email address")},
|
2019-11-04 16:55:03 +00:00
|
|
|
"users/delete.html",
|
|
|
|
request,
|
2018-07-30 15:00:41 +00:00
|
|
|
)
|
|
|
|
|
2018-06-26 16:46:57 +00:00
|
|
|
|
2018-06-27 21:13:43 +00:00
|
|
|
@login_required
|
2018-06-29 14:36:04 +00:00
|
|
|
@can_edit(User)
|
2018-07-30 15:00:41 +00:00
|
|
|
def edit_email_settings(request, user_instance, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing User's emailaddress settings for user instance.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of editing email settings on target user.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
user: User instance to edit email settings.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User form.
|
|
|
|
|
|
|
|
"""
|
2018-07-30 15:00:41 +00:00
|
|
|
email_settings = EmailSettingsForm(
|
2019-11-04 16:55:03 +00:00
|
|
|
request.POST or None, instance=user_instance, user=request.user
|
2018-06-27 21:13:43 +00:00
|
|
|
)
|
2018-07-30 15:00:41 +00:00
|
|
|
if email_settings.is_valid():
|
|
|
|
if email_settings.changed_data:
|
|
|
|
email_settings.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The email settings were edited."))
|
2020-04-17 16:59:21 +00:00
|
|
|
|
2020-04-17 18:53:10 +00:00
|
|
|
if user_instance.send_confirm_email_if_necessary(request):
|
2020-04-21 15:37:17 +00:00
|
|
|
messages.success(
|
|
|
|
request, _("An email to confirm your address was sent.")
|
|
|
|
)
|
2020-04-17 18:53:10 +00:00
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("users:profil", kwargs={"userid": str(user_instance.id)})
|
|
|
|
)
|
2018-06-27 21:13:43 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{
|
|
|
|
"userform": email_settings,
|
|
|
|
"showCGU": False,
|
|
|
|
"load_js_file": "/static/js/email_address.js",
|
2019-11-20 00:52:11 +00:00
|
|
|
"action_name": _("Edit"),
|
2019-11-04 16:55:03 +00:00
|
|
|
},
|
|
|
|
"users/user.html",
|
|
|
|
request,
|
2018-06-27 21:13:43 +00:00
|
|
|
)
|
|
|
|
|
2018-07-30 15:00:41 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-08 20:59:21 +00:00
|
|
|
@can_create(School)
|
2016-07-06 17:45:36 +00:00
|
|
|
def add_school(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for adding a new school object.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of adding a new school, add_school.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django School form.
|
|
|
|
|
|
|
|
"""
|
2016-07-06 17:45:36 +00:00
|
|
|
school = SchoolForm(request.POST or None)
|
|
|
|
if school.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
school.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The school was added."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:index-school"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": school, "action_name": _("Add")}, "users/user.html", request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2016-07-06 17:45:36 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-08 20:59:21 +00:00
|
|
|
@can_edit(School)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_school(request, school_instance, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing a school instance object.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of editing a school, edit_school.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
school_instance: school instance to edit.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django School form.
|
|
|
|
|
|
|
|
"""
|
2016-07-08 00:25:12 +00:00
|
|
|
school = SchoolForm(request.POST or None, instance=school_instance)
|
|
|
|
if school.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if school.changed_data:
|
|
|
|
school.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The school was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:index-school"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": school, "action_name": _("Edit")}, "users/user.html", request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2016-07-08 00:25:12 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-13 17:35:16 +00:00
|
|
|
@can_delete_set(School)
|
2017-12-12 03:33:50 +00:00
|
|
|
def del_school(request, instances):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for deleting a school instance object.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of deleting a school, del_school.
|
|
|
|
A school can be deleted only if it is not assigned to a user (mode
|
|
|
|
protect).
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
school_instance: school instance to delete.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django School form.
|
|
|
|
|
|
|
|
"""
|
2017-12-12 03:33:50 +00:00
|
|
|
school = DelSchoolForm(request.POST or None, instances=instances)
|
2016-07-06 17:45:36 +00:00
|
|
|
if school.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
school_dels = school.cleaned_data["schools"]
|
2016-07-06 17:45:36 +00:00
|
|
|
for school_del in school_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
school_del.delete()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The school was deleted."))
|
2016-07-06 17:45:36 +00:00
|
|
|
except ProtectedError:
|
2016-07-08 01:12:28 +00:00
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
_(
|
|
|
|
"The school %s is assigned to at least one user,"
|
|
|
|
" impossible to delete it."
|
|
|
|
)
|
|
|
|
% school_del,
|
|
|
|
)
|
|
|
|
return redirect(reverse("users:index-school"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2019-11-20 00:52:11 +00:00
|
|
|
{"userform": school, "action_name": _("Confirm")}, "users/user.html", request
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2016-07-06 17:45:36 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2018-03-24 18:06:49 +00:00
|
|
|
@login_required
|
|
|
|
@can_create(ListShell)
|
|
|
|
def add_shell(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for adding a new linux shell object.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of adding a new shell, add_school.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Shell form.
|
|
|
|
|
|
|
|
"""
|
2018-03-24 18:06:49 +00:00
|
|
|
shell = ShellForm(request.POST or None)
|
|
|
|
if shell.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
shell.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The shell was added."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:index-shell"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2019-11-20 00:52:11 +00:00
|
|
|
{"userform": shell, "action_name": _("Add")}, "users/user.html", request
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2018-03-24 18:06:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_edit(ListShell)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_shell(request, shell_instance, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing a shell instance object.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of editing a shell, edit_shell.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
shell_instance: shell instance to edit.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Shell form.
|
|
|
|
|
|
|
|
"""
|
2018-03-24 18:06:49 +00:00
|
|
|
shell = ShellForm(request.POST or None, instance=shell_instance)
|
|
|
|
if shell.is_valid():
|
2018-03-31 22:06:44 +00:00
|
|
|
if shell.changed_data:
|
|
|
|
shell.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The shell was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:index-shell"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"userform": shell, "action_name": _("Edit")}, "users/user.html", request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2018-03-24 18:06:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@can_delete(ListShell)
|
2018-04-15 01:00:05 +00:00
|
|
|
def del_shell(request, shell, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for deleting a shell instance object.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of deleting a shell, del_shell.
|
|
|
|
A shell can be deleted only if it is not assigned to a user (mode
|
|
|
|
protect).
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
shell_instance: shell instance to delete.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Shell form.
|
|
|
|
|
|
|
|
"""
|
2018-03-24 18:06:49 +00:00
|
|
|
if request.method == "POST":
|
2018-03-31 15:18:39 +00:00
|
|
|
shell.delete()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The shell was deleted."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:index-shell"))
|
2020-04-21 15:37:17 +00:00
|
|
|
return form(
|
|
|
|
{"objet": shell, "objet_name": _("shell")}, "users/delete.html", request
|
|
|
|
)
|
2018-03-24 18:06:49 +00:00
|
|
|
|
|
|
|
|
2016-07-26 00:54:32 +00:00
|
|
|
@login_required
|
2017-12-08 20:59:21 +00:00
|
|
|
@can_create(ListRight)
|
2016-07-26 00:54:32 +00:00
|
|
|
def add_listright(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for adding a new group of rights and users (listright linked to groups)
|
|
|
|
object for user instance.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of adding a new listright.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django ListRight form.
|
|
|
|
|
|
|
|
"""
|
2016-07-26 00:54:32 +00:00
|
|
|
listright = NewListRightForm(request.POST or None)
|
|
|
|
if listright.is_valid():
|
2018-03-31 15:18:39 +00:00
|
|
|
listright.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The group of rights was added."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:index-listright"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{"form": listright, "action_name": _("Add"), "permissions": permission_tree()},
|
|
|
|
"users/edit_listright.html",
|
2019-11-04 16:55:03 +00:00
|
|
|
request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2016-07-26 00:54:32 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-26 00:54:32 +00:00
|
|
|
@login_required
|
2017-12-08 20:59:21 +00:00
|
|
|
@can_edit(ListRight)
|
2018-04-15 01:00:05 +00:00
|
|
|
def edit_listright(request, listright_instance, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for editing a listright instance object.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of editing a listright, edit_listright.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
listright_instance: listright instance to edit.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django ListRight form.
|
|
|
|
|
|
|
|
"""
|
2020-04-21 15:37:17 +00:00
|
|
|
listright_form = ListRightForm(request.POST or None, instance=listright_instance)
|
|
|
|
if listright_form.is_valid():
|
|
|
|
if listright_form.changed_data:
|
|
|
|
listright_form.save()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The group of rights was edited."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:index-listright"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2020-04-21 15:37:17 +00:00
|
|
|
{
|
|
|
|
"form": listright_form,
|
|
|
|
"action_name": _("Edit"),
|
|
|
|
"permissions": permission_tree(),
|
|
|
|
"instance": listright_instance,
|
|
|
|
},
|
|
|
|
"users/edit_listright.html",
|
2019-11-04 16:55:03 +00:00
|
|
|
request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2016-07-26 00:54:32 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-26 00:54:32 +00:00
|
|
|
@login_required
|
2017-12-13 17:35:16 +00:00
|
|
|
@can_delete_set(ListRight)
|
2017-12-27 20:21:04 +00:00
|
|
|
def del_listright(request, instances):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for deleting a listright instance object.
|
|
|
|
Perform an acl check on editing user, and check if editing user
|
|
|
|
has permission of deleting a listright, del_listright.
|
|
|
|
A listright/group can be deleted only if it is empty (mode
|
|
|
|
protect).
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
listright_instance: listright instance to delete.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django ListRight form.
|
|
|
|
|
|
|
|
"""
|
2017-12-13 17:35:16 +00:00
|
|
|
listright = DelListRightForm(request.POST or None, instances=instances)
|
2016-07-26 00:54:32 +00:00
|
|
|
if listright.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
listright_dels = listright.cleaned_data["listrights"]
|
2016-07-26 00:54:32 +00:00
|
|
|
for listright_del in listright_dels:
|
|
|
|
try:
|
2018-03-31 15:18:39 +00:00
|
|
|
listright_del.delete()
|
2019-11-20 00:52:11 +00:00
|
|
|
messages.success(request, _("The group of rights was deleted."))
|
2016-07-26 00:54:32 +00:00
|
|
|
except ProtectedError:
|
|
|
|
messages.error(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
_(
|
|
|
|
"The group of rights %s is assigned to at least one"
|
|
|
|
" user, impossible to delete it."
|
|
|
|
)
|
|
|
|
% listright_del,
|
|
|
|
)
|
|
|
|
return redirect(reverse("users:index-listright"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2019-11-20 00:52:11 +00:00
|
|
|
{"userform": listright, "action_name": _("Confirm")}, "users/user.html", request
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2016-07-26 00:54:32 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2017-05-26 01:07:10 +00:00
|
|
|
@login_required
|
2017-12-28 13:04:14 +00:00
|
|
|
@can_view_all(User)
|
2019-11-04 16:55:03 +00:00
|
|
|
@can_change(User, "state")
|
2017-05-26 01:07:10 +00:00
|
|
|
def mass_archive(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for performing a mass archive operation.
|
|
|
|
Check if editing User has the acl for globaly changing "State"
|
|
|
|
flag on users, and can edit all the users.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
pagination_number = GeneralOption.get_cached_value("pagination_number")
|
2019-03-17 03:46:55 +00:00
|
|
|
to_archive_form = MassArchiveForm(request.POST or None)
|
2017-05-26 01:07:10 +00:00
|
|
|
to_archive_list = []
|
2019-03-17 03:46:55 +00:00
|
|
|
if to_archive_form.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
date = to_archive_form.cleaned_data["date"]
|
|
|
|
full_archive = to_archive_form.cleaned_data["full_archive"]
|
|
|
|
to_archive_list = (
|
|
|
|
User.objects.exclude(id__in=all_has_access())
|
|
|
|
.exclude(id__in=all_has_access(search_time=date))
|
|
|
|
.exclude(state=User.STATE_NOT_YET_ACTIVE)
|
|
|
|
.exclude(state=User.STATE_FULL_ARCHIVE)
|
|
|
|
)
|
2019-03-17 03:46:55 +00:00
|
|
|
if not full_archive:
|
|
|
|
to_archive_list = to_archive_list.exclude(state=User.STATE_ARCHIVE)
|
2017-05-26 01:07:10 +00:00
|
|
|
if "valider" in request.POST:
|
2019-03-17 03:46:55 +00:00
|
|
|
if full_archive:
|
|
|
|
User.mass_full_archive(to_archive_list)
|
|
|
|
else:
|
|
|
|
User.mass_archive(to_archive_list)
|
2019-11-04 16:55:03 +00:00
|
|
|
messages.success(
|
|
|
|
request, _("%s users were archived.") % to_archive_list.count()
|
2019-03-17 03:46:55 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:index"))
|
2019-03-17 03:46:55 +00:00
|
|
|
to_archive_list = re2o_paginator(request, to_archive_list, pagination_number)
|
2017-10-14 20:10:07 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"userform": to_archive_form, "to_archive_list": to_archive_list},
|
|
|
|
"users/mass_archive.html",
|
|
|
|
request,
|
2017-10-14 20:10:07 +00:00
|
|
|
)
|
|
|
|
|
2017-05-26 01:07:10 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-27 20:21:04 +00:00
|
|
|
@can_view_all(Adherent)
|
2016-07-01 22:35:44 +00:00
|
|
|
def index(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for displaying the paginated list of all users/adherents in re2o.
|
|
|
|
Need the global acl for viewing all users, can_view_all.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Adherent Form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
pagination_number = GeneralOption.get_cached_value("pagination_number")
|
|
|
|
users_list = Adherent.objects.select_related("room")
|
2017-10-21 15:47:42 +00:00
|
|
|
users_list = SortTable.sort(
|
|
|
|
users_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.USERS_INDEX,
|
2017-10-21 15:47:42 +00:00
|
|
|
)
|
2018-04-03 03:00:06 +00:00
|
|
|
users_list = re2o_paginator(request, users_list, pagination_number)
|
2019-11-04 16:55:03 +00:00
|
|
|
return render(request, "users/index.html", {"users_list": users_list})
|
2016-07-03 16:09:58 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2017-10-23 03:02:55 +00:00
|
|
|
@login_required
|
2017-12-28 15:10:34 +00:00
|
|
|
@can_view_all(Club)
|
2017-10-23 03:02:55 +00:00
|
|
|
def index_clubs(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for displaying the paginated list of all users/clubs in re2o.
|
|
|
|
Need the global acl for viewing all users, can_view_all.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Adherent Form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
pagination_number = GeneralOption.get_cached_value("pagination_number")
|
|
|
|
clubs_list = Club.objects.select_related("room")
|
2017-10-23 03:02:55 +00:00
|
|
|
clubs_list = SortTable.sort(
|
|
|
|
clubs_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.USERS_INDEX,
|
2017-10-23 03:02:55 +00:00
|
|
|
)
|
2018-04-03 03:00:06 +00:00
|
|
|
clubs_list = re2o_paginator(request, clubs_list, pagination_number)
|
2019-11-04 16:55:03 +00:00
|
|
|
return render(request, "users/index_clubs.html", {"clubs_list": clubs_list})
|
2017-10-23 03:02:55 +00:00
|
|
|
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-27 20:21:04 +00:00
|
|
|
@can_view_all(Ban)
|
2016-07-05 17:34:57 +00:00
|
|
|
def index_ban(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for displaying the paginated list of all bans in re2o.
|
|
|
|
Need the global acl for viewing all bans, can_view_all.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Ban Form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
pagination_number = GeneralOption.get_cached_value("pagination_number")
|
|
|
|
ban_list = Ban.objects.select_related("user")
|
2017-10-21 21:45:21 +00:00
|
|
|
ban_list = SortTable.sort(
|
|
|
|
ban_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.USERS_INDEX_BAN,
|
2017-10-21 21:45:21 +00:00
|
|
|
)
|
2018-04-03 03:00:06 +00:00
|
|
|
ban_list = re2o_paginator(request, ban_list, pagination_number)
|
2019-11-04 16:55:03 +00:00
|
|
|
return render(request, "users/index_ban.html", {"ban_list": ban_list})
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-27 20:21:04 +00:00
|
|
|
@can_view_all(Whitelist)
|
2016-07-05 17:34:57 +00:00
|
|
|
def index_white(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for displaying the paginated list of all whitelists in re2o.
|
|
|
|
Need the global acl for viewing all whitelists, can_view_all.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Whitelist Form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
pagination_number = GeneralOption.get_cached_value("pagination_number")
|
|
|
|
white_list = Whitelist.objects.select_related("user")
|
2017-10-21 21:45:21 +00:00
|
|
|
white_list = SortTable.sort(
|
|
|
|
white_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.USERS_INDEX_BAN,
|
2017-10-21 21:45:21 +00:00
|
|
|
)
|
2018-04-03 03:00:06 +00:00
|
|
|
white_list = re2o_paginator(request, white_list, pagination_number)
|
2019-11-04 16:55:03 +00:00
|
|
|
return render(request, "users/index_whitelist.html", {"white_list": white_list})
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-27 20:21:04 +00:00
|
|
|
@can_view_all(School)
|
2016-07-08 00:25:12 +00:00
|
|
|
def index_school(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for displaying the paginated list of all schools in re2o.
|
|
|
|
Need the global acl for viewing all schools, can_view_all.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django School Form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
school_list = School.objects.order_by("name")
|
|
|
|
pagination_number = GeneralOption.get_cached_value("pagination_number")
|
2018-03-27 21:56:16 +00:00
|
|
|
school_list = SortTable.sort(
|
|
|
|
school_list,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.USERS_INDEX_SCHOOL,
|
2018-03-27 21:56:16 +00:00
|
|
|
)
|
2018-04-03 03:00:06 +00:00
|
|
|
school_list = re2o_paginator(request, school_list, pagination_number)
|
2019-11-04 16:55:03 +00:00
|
|
|
return render(request, "users/index_schools.html", {"school_list": school_list})
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-08 00:25:12 +00:00
|
|
|
|
2018-03-24 18:06:49 +00:00
|
|
|
@login_required
|
|
|
|
@can_view_all(ListShell)
|
|
|
|
def index_shell(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for displaying the paginated list of all shells in re2o.
|
|
|
|
Need the global acl for viewing all shells, can_view_all.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django Shell Form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
shell_list = ListShell.objects.order_by("shell")
|
|
|
|
return render(request, "users/index_shell.html", {"shell_list": shell_list})
|
2018-03-24 18:06:49 +00:00
|
|
|
|
|
|
|
|
2016-07-26 00:54:32 +00:00
|
|
|
@login_required
|
2017-12-27 20:21:04 +00:00
|
|
|
@can_view_all(ListRight)
|
2016-07-26 00:54:32 +00:00
|
|
|
def index_listright(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for displaying the listrights/groups list in re2o.
|
|
|
|
The listrights are sorted by members users, and individual
|
|
|
|
acl for a complete display.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django ListRight Form.
|
|
|
|
|
|
|
|
"""
|
2018-06-27 19:37:13 +00:00
|
|
|
rights = {}
|
2019-11-04 16:55:03 +00:00
|
|
|
for right in (
|
|
|
|
ListRight.objects.order_by("name")
|
|
|
|
.prefetch_related("permissions")
|
|
|
|
.prefetch_related("user_set")
|
|
|
|
):
|
|
|
|
rights[right] = right.user_set.annotate(
|
|
|
|
action_number=Count("revision"), last_seen=Max("revision__date_created")
|
|
|
|
)
|
|
|
|
superusers = User.objects.filter(is_superuser=True).annotate(
|
|
|
|
action_number=Count("revision"), last_seen=Max("revision__date_created")
|
|
|
|
)
|
2017-10-14 20:10:07 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"users/index_listright.html",
|
|
|
|
{"rights": rights, "superusers": superusers},
|
2017-10-14 20:10:07 +00:00
|
|
|
)
|
|
|
|
|
2016-07-26 00:54:32 +00:00
|
|
|
|
2017-06-18 12:59:53 +00:00
|
|
|
@login_required
|
2017-12-27 20:21:04 +00:00
|
|
|
@can_view_all(ServiceUser)
|
2017-06-18 12:59:53 +00:00
|
|
|
def index_serviceusers(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View for displaying the paginated list of all serviceusers in re2o
|
|
|
|
See ServiceUser model for more informations on service users.
|
|
|
|
Need the global acl for viewing all serviceusers, can_view_all.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django ServiceUser Form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
serviceusers_list = ServiceUser.objects.order_by("pseudo")
|
2017-10-14 20:10:07 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"users/index_serviceusers.html",
|
|
|
|
{"serviceusers_list": serviceusers_list},
|
2017-10-14 20:10:07 +00:00
|
|
|
)
|
|
|
|
|
2017-06-18 12:59:53 +00:00
|
|
|
|
2016-07-10 02:02:48 +00:00
|
|
|
@login_required
|
|
|
|
def mon_profil(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""Shortcuts view to profil view, with correct arguments.
|
|
|
|
Returns the view profil with users argument, users is set to
|
|
|
|
default request.user.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User Profil Form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": str(request.user.id)}))
|
2016-07-10 02:02:48 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2017-12-27 20:21:04 +00:00
|
|
|
@can_view(User)
|
2018-04-15 01:00:05 +00:00
|
|
|
def profil(request, users, **_kwargs):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""Profil view. Display informations on users, the single user.
|
|
|
|
Informations displayed are:
|
|
|
|
* Adherent or Club User instance informations
|
|
|
|
* Interface/Machine belonging to User instance
|
|
|
|
* Invoice belonging to User instance
|
|
|
|
* Ban instances belonging to User
|
|
|
|
* Whitelists instances belonging to User
|
|
|
|
* Email Settings of User instance
|
|
|
|
* Tickets belonging to User instance.
|
|
|
|
Requires the acl can_view on user instance.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
users: User instance to display profil
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django User Profil Form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
machines = (
|
|
|
|
Machine.objects.filter(user=users)
|
|
|
|
.select_related("user")
|
|
|
|
.prefetch_related("interface_set__domain__extension")
|
|
|
|
.prefetch_related("interface_set__ipv4__ip_type__extension")
|
|
|
|
.prefetch_related("interface_set__machine_type")
|
|
|
|
.prefetch_related("interface_set__domain__related_domain__extension")
|
|
|
|
)
|
2017-10-22 16:04:51 +00:00
|
|
|
machines = SortTable.sort(
|
|
|
|
machines,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.MACHINES_INDEX,
|
2017-10-22 16:04:51 +00:00
|
|
|
)
|
2019-09-29 16:27:35 +00:00
|
|
|
|
2019-08-11 19:51:31 +00:00
|
|
|
optionnal_apps = [import_module(app) for app in OPTIONNAL_APPS_RE2O]
|
2019-11-04 16:55:03 +00:00
|
|
|
optionnal_templates_list = [
|
|
|
|
app.views.profil(request, users)
|
|
|
|
for app in optionnal_apps
|
|
|
|
if hasattr(app.views, "profil")
|
|
|
|
]
|
2019-07-25 14:44:40 +00:00
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
pagination_large_number = GeneralOption.get_cached_value("pagination_large_number")
|
2018-04-16 21:57:22 +00:00
|
|
|
nb_machines = machines.count()
|
2018-04-03 03:00:06 +00:00
|
|
|
machines = re2o_paginator(request, machines, pagination_large_number)
|
2017-10-10 23:02:50 +00:00
|
|
|
factures = Facture.objects.filter(user=users)
|
2017-10-22 16:04:51 +00:00
|
|
|
factures = SortTable.sort(
|
|
|
|
factures,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.COTISATIONS_INDEX,
|
2017-10-22 16:04:51 +00:00
|
|
|
)
|
2017-10-10 23:02:50 +00:00
|
|
|
bans = Ban.objects.filter(user=users)
|
2017-10-22 16:04:51 +00:00
|
|
|
bans = SortTable.sort(
|
|
|
|
bans,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.USERS_INDEX_BAN,
|
2017-10-22 16:04:51 +00:00
|
|
|
)
|
2017-10-10 23:02:50 +00:00
|
|
|
whitelists = Whitelist.objects.filter(user=users)
|
2017-10-22 16:04:51 +00:00
|
|
|
whitelists = SortTable.sort(
|
|
|
|
whitelists,
|
2019-11-04 16:55:03 +00:00
|
|
|
request.GET.get("col"),
|
|
|
|
request.GET.get("order"),
|
|
|
|
SortTable.USERS_INDEX_WHITE,
|
2017-10-22 16:04:51 +00:00
|
|
|
)
|
2018-07-16 18:14:26 +00:00
|
|
|
try:
|
|
|
|
balance = find_payment_method(Paiement.objects.get(is_balance=True))
|
|
|
|
except Paiement.DoesNotExist:
|
|
|
|
user_solde = False
|
|
|
|
else:
|
2019-11-04 16:55:03 +00:00
|
|
|
user_solde = balance is not None and balance.can_credit_balance(request.user)
|
2016-07-08 01:12:28 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"users/profil.html",
|
2016-07-08 01:12:28 +00:00
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"users": users,
|
|
|
|
"machines_list": machines,
|
|
|
|
"nb_machines": nb_machines,
|
|
|
|
"optionnal_templates_list": optionnal_templates_list,
|
|
|
|
"facture_list": factures,
|
|
|
|
"ban_list": bans,
|
|
|
|
"white_list": whitelists,
|
|
|
|
"user_solde": user_solde,
|
|
|
|
"solde_activated": Paiement.objects.filter(is_balance=True).exists(),
|
|
|
|
"asso_name": AssoOption.objects.first().name,
|
|
|
|
"emailaddress_list": users.email_address,
|
|
|
|
"local_email_accounts_enabled": (
|
2018-07-30 15:00:41 +00:00
|
|
|
OptionalUser.objects.first().local_email_accounts_enabled
|
2019-11-04 16:55:03 +00:00
|
|
|
),
|
|
|
|
},
|
2016-07-08 01:40:04 +00:00
|
|
|
)
|
2016-07-03 16:09:58 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-20 10:06:33 +00:00
|
|
|
def reset_password(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""Reset password form, linked to form forgotten password.
|
|
|
|
If an user is found, send an email to him with a link
|
|
|
|
to reset its password.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Django ResetPassword Form.
|
|
|
|
|
|
|
|
"""
|
2016-07-20 10:06:33 +00:00
|
|
|
userform = ResetPasswordForm(request.POST or None)
|
|
|
|
if userform.is_valid():
|
|
|
|
try:
|
2017-10-14 20:10:07 +00:00
|
|
|
user = User.objects.get(
|
2019-11-04 16:55:03 +00:00
|
|
|
pseudo=userform.cleaned_data["pseudo"],
|
|
|
|
email=userform.cleaned_data["email"],
|
2020-04-17 15:35:24 +00:00
|
|
|
state__in=[User.STATE_ACTIVE, User.STATE_NOT_YET_ACTIVE],
|
2017-10-14 20:10:07 +00:00
|
|
|
)
|
2016-07-20 10:06:33 +00:00
|
|
|
except User.DoesNotExist:
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.error(request, _("The user doesn't exist."))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"userform": userform, "action_name": _("Reset")},
|
|
|
|
"users/user.html",
|
|
|
|
request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2017-08-28 19:51:12 +00:00
|
|
|
user.reset_passwd_mail(request)
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("An email to reset the password was sent."))
|
2019-11-04 16:55:03 +00:00
|
|
|
redirect(reverse("index"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"userform": userform, "action_name": _("Reset")}, "users/user.html", request
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2016-07-20 10:06:33 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-20 01:53:46 +00:00
|
|
|
def process(request, token):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""Process view, in case of both reset password, or confirm email in case
|
|
|
|
of new email set.
|
|
|
|
This view calls process_passwd or process_email.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Correct Django process Form.
|
|
|
|
|
|
|
|
"""
|
2016-07-20 01:53:46 +00:00
|
|
|
valid_reqs = Request.objects.filter(expires_at__gt=timezone.now())
|
|
|
|
req = get_object_or_404(valid_reqs, token=token)
|
|
|
|
|
|
|
|
if req.type == Request.PASSWD:
|
|
|
|
return process_passwd(request, req)
|
2020-04-17 00:16:56 +00:00
|
|
|
elif req.type == Request.EMAIL:
|
|
|
|
return process_email(request, req)
|
2016-07-20 01:53:46 +00:00
|
|
|
else:
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.error(request, _("Error: please contact an admin."))
|
2019-11-04 16:55:03 +00:00
|
|
|
redirect(reverse("index"))
|
2016-07-20 01:53:46 +00:00
|
|
|
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2016-07-20 01:53:46 +00:00
|
|
|
def process_passwd(request, req):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""Process view, in case of reset password by email. Returns
|
|
|
|
a form to change and reset the password.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Correct Django process password Form.
|
|
|
|
|
|
|
|
"""
|
2016-07-20 01:53:46 +00:00
|
|
|
user = req.user
|
2018-01-31 04:51:47 +00:00
|
|
|
u_form = PassForm(request.POST or None, instance=user, user=request.user)
|
2016-07-20 01:53:46 +00:00
|
|
|
if u_form.is_valid():
|
2018-01-31 04:51:47 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
2020-04-17 17:59:25 +00:00
|
|
|
user.confirm_mail()
|
2018-01-31 04:51:47 +00:00
|
|
|
u_form.save()
|
2019-11-20 00:52:11 +00:00
|
|
|
reversion.set_comment("Password reset")
|
2020-04-17 17:59:25 +00:00
|
|
|
|
2020-04-17 23:03:41 +00:00
|
|
|
# Delete all remaining requests
|
|
|
|
Request.objects.filter(user=user, type=Request.PASSWD).delete()
|
2018-08-15 17:15:26 +00:00
|
|
|
messages.success(request, _("The password was changed."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(reverse("index"))
|
2018-04-14 01:25:05 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"userform": u_form, "action_name": _("Change the password")},
|
|
|
|
"users/user.html",
|
|
|
|
request,
|
2018-04-14 01:25:05 +00:00
|
|
|
)
|
2017-10-14 20:10:07 +00:00
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2020-04-17 11:17:18 +00:00
|
|
|
def process_email(request, req):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""Process view, in case of confirm a new email. Returns
|
|
|
|
a form to notify the success of the email confirmation to
|
|
|
|
request.User.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Correct Django process email Form.
|
|
|
|
|
|
|
|
"""
|
2020-04-17 11:17:18 +00:00
|
|
|
user = req.user
|
|
|
|
if request.method == "POST":
|
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
user.confirm_mail()
|
|
|
|
user.save()
|
|
|
|
reversion.set_comment("Email confirmation")
|
|
|
|
|
2020-04-17 23:03:41 +00:00
|
|
|
# Delete all remaining requests
|
|
|
|
Request.objects.filter(user=user, type=Request.EMAIL).delete()
|
2020-04-17 11:17:18 +00:00
|
|
|
messages.success(request, _("The %s address was confirmed." % user.email))
|
|
|
|
return redirect(reverse("index"))
|
|
|
|
|
|
|
|
return form(
|
2020-04-17 13:22:53 +00:00
|
|
|
{"email": user.email, "name": user.get_full_name()},
|
2020-04-17 11:17:18 +00:00
|
|
|
"users/confirm_email.html",
|
2020-04-21 15:37:17 +00:00
|
|
|
request,
|
2020-04-17 11:17:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-04-17 11:39:11 +00:00
|
|
|
@login_required
|
2020-04-17 11:17:18 +00:00
|
|
|
@can_edit(User)
|
2020-04-17 11:39:11 +00:00
|
|
|
def resend_confirmation_email(request, logged_user, userid):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View to resend confirm email, for adding a new email.
|
|
|
|
Check if User has the correct acl.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Correct Django resend email Form.
|
|
|
|
|
|
|
|
"""
|
2020-04-17 09:34:54 +00:00
|
|
|
try:
|
|
|
|
user = User.objects.get(
|
|
|
|
id=userid,
|
2020-04-17 15:35:24 +00:00
|
|
|
email_state__in=[User.EMAIL_STATE_PENDING, User.EMAIL_STATE_UNVERIFIED],
|
2020-04-17 09:34:54 +00:00
|
|
|
)
|
|
|
|
except User.DoesNotExist:
|
|
|
|
messages.error(request, _("The user doesn't exist."))
|
2020-04-17 09:22:29 +00:00
|
|
|
|
2020-04-17 09:34:54 +00:00
|
|
|
if request.method == "POST":
|
2020-04-17 19:11:24 +00:00
|
|
|
user.confirm_email_address_mail(request)
|
2020-04-17 09:34:54 +00:00
|
|
|
messages.success(request, _("An email to confirm your address was sent."))
|
2020-04-17 00:16:56 +00:00
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": userid}))
|
2020-04-16 22:24:35 +00:00
|
|
|
|
2020-04-21 15:37:17 +00:00
|
|
|
return form({"email": user.email}, "users/resend_confirmation_email.html", request)
|
2020-04-16 22:24:35 +00:00
|
|
|
|
|
|
|
|
2018-08-28 18:18:09 +00:00
|
|
|
@login_required
|
|
|
|
def initial_register(request):
|
2020-06-01 15:28:48 +00:00
|
|
|
"""View to register both a new room, and a new interface/machine for a user.
|
|
|
|
This view is used with switchs function of redirect web after AAA authentication
|
|
|
|
failed. Then, the users log-in, and the new mac-address and switch port, in order to
|
|
|
|
get the room, are included in HTTP Headers by the switch redirection functionnality.
|
|
|
|
This allow to add the new interface with the correct mac-address, and confirm if needed,
|
|
|
|
the new room of request.user.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
request (django request): Standard django request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Initial room and interface/machine register Form.
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
switch_ip = request.GET.get("switch_ip", None)
|
|
|
|
switch_port = request.GET.get("switch_port", None)
|
|
|
|
client_mac = request.GET.get("client_mac", None)
|
|
|
|
u_form = InitialRegisterForm(
|
|
|
|
request.POST or None,
|
|
|
|
user=request.user,
|
|
|
|
switch_ip=switch_ip,
|
|
|
|
switch_port=switch_port,
|
|
|
|
client_mac=client_mac,
|
|
|
|
)
|
2018-08-28 18:18:09 +00:00
|
|
|
if not u_form.fields:
|
2019-01-08 23:40:59 +00:00
|
|
|
messages.error(request, _("Incorrect URL, or already registered device."))
|
2019-11-04 16:55:03 +00:00
|
|
|
return redirect(
|
|
|
|
reverse("users:profil", kwargs={"userid": str(request.user.id)})
|
|
|
|
)
|
2018-10-03 00:58:55 +00:00
|
|
|
if switch_ip and switch_port:
|
2019-11-04 16:55:03 +00:00
|
|
|
port = Port.objects.filter(
|
|
|
|
switch__interface__ipv4__ipv4=switch_ip, port=switch_port
|
|
|
|
).first()
|
2018-08-28 18:18:09 +00:00
|
|
|
if u_form.is_valid():
|
2019-11-04 16:55:03 +00:00
|
|
|
messages.success(
|
|
|
|
request,
|
|
|
|
_(
|
|
|
|
"Successful registration! Please"
|
|
|
|
" disconnect and reconnect your Ethernet"
|
|
|
|
" cable to get Internet access."
|
|
|
|
),
|
2018-08-28 18:18:09 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
return form({}, "users/plugin_out.html", request)
|
2018-08-28 18:18:09 +00:00
|
|
|
return form(
|
2019-11-04 16:55:03 +00:00
|
|
|
{"userform": u_form, "port": port, "mac": client_mac},
|
|
|
|
"users/user_autocapture.html",
|
|
|
|
request,
|
2018-08-28 18:18:09 +00:00
|
|
|
)
|
|
|
|
|