Commit 7b0b5c2a authored by Maël Kervella's avatar Maël Kervella

Pep8 compliance on users

parent 8afc8e43
......@@ -26,6 +26,7 @@
Here are defined some functions to check acl on the application.
"""
def can_view(user):
"""Check if an user can view the application.
......
......@@ -89,12 +89,16 @@ class PassForm(FormRevMixin, FieldPermissionFormMixin, forms.ModelForm):
password1 = self.cleaned_data.get("passwd1")
password2 = self.cleaned_data.get("passwd2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError("Les 2 nouveaux mots de passe sont différents")
raise forms.ValidationError(
"Les 2 nouveaux mots de passe sont différents"
)
return password2
def clean_selfpasswd(self):
"""Verifie si il y a lieu que le mdp self est correct"""
if not self.instance.check_password(self.cleaned_data.get("selfpasswd")):
if not self.instance.check_password(
self.cleaned_data.get("selfpasswd")
):
raise forms.ValidationError("Le mot de passe actuel est incorrect")
return
......@@ -386,7 +390,11 @@ class ClubAdminandMembersForm(FormRevMixin, ModelForm):
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(ClubAdminandMembersForm, self).__init__(*args, prefix=prefix, **kwargs)
super(ClubAdminandMembersForm, self).__init__(
*args,
prefix=prefix,
**kwargs
)
class PasswordForm(FormRevMixin, ModelForm):
......
......@@ -19,12 +19,14 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os, pwd
import os
import pwd
from django.core.management.base import BaseCommand, CommandError
from users.forms import PassForm
from re2o.script_utils import get_user, get_system_user, form_cli
class Command(BaseCommand):
help = "Changer le mot de passe d'un utilisateur"
......@@ -42,6 +44,13 @@ class Command(BaseCommand):
if not ok:
raise CommandError(msg)
self.stdout.write("Changement du mot de passe de %s" % target_user.pseudo)
self.stdout.write(
"Changement du mot de passe de %s" % target_user.pseudo
)
form_cli(PassForm,current_user,"Changement du mot de passe",instance=target_user)
form_cli(
PassForm,
current_user,
"Changement du mot de passe",
instance=target_user
)
......@@ -19,7 +19,9 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os, sys, pwd
import os
import sys
import pwd
from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
......@@ -28,6 +30,7 @@ from reversion import revisions as reversion
from users.models import User, ListShell
from re2o.script_utils import get_user, get_system_user
class Command(BaseCommand):
help = 'Change the default shell of a user'
......@@ -36,13 +39,13 @@ class Command(BaseCommand):
def handle(self, *args, **options):
current_username = get_system_user()
current_username = get_system_user()
current_user = get_user(current_username)
target_username = options["target_username"] or current_username
target_user = get_user(target_username)
#L'utilisateur n'a pas le droit de changer le shell
# L'utilisateur n'a pas le droit de changer le shell
ok, msg = target_user.can_change_shell(current_user)
if not ok:
raise CommandError(msg)
......@@ -52,9 +55,16 @@ class Command(BaseCommand):
current_shell = "inconnu"
if target_user.shell:
current_shell = target_user.shell.get_pretty_name()
self.stdout.write("Choisissez un shell pour l'utilisateur %s (le shell actuel est %s) :" % (target_user.pseudo, current_shell))
self.stdout.write(
"Choisissez un shell pour l'utilisateur %s (le shell actuel est "
"%s) :" % (target_user.pseudo, current_shell)
)
for shell in shells:
self.stdout.write("%d - %s (%s)" % (shell.id, shell.get_pretty_name(), shell.shell))
self.stdout.write("%d - %s (%s)" % (
shell.id,
shell.get_pretty_name(),
shell.shell
))
shell_id = input("Entrez un nombre : ")
try:
......@@ -72,4 +82,7 @@ class Command(BaseCommand):
reversion.set_user(current_user)
reversion.set_comment("Shell modifié")
self.stdout.write(self.style.SUCCESS("Shell modifié. La modification peut prendre quelques minutes pour s'appliquer."))
self.stdout.write(self.style.SUCCESS(
"Shell modifié. La modification peut prendre quelques minutes "
"pour s'appliquer."
))
......@@ -4,7 +4,6 @@
# quelques clics.
#
# Copyright © 2018 Benjamin Graillot
#
# Copyright © 2013-2015 Raphaël-David Lasseri <lasseri@crans.org>
#
# This program is free software; you can redistribute it and/or modify
......@@ -32,7 +31,8 @@ from users.models import User
# Une liste d'expressions régulières à chercher dans les logs.
# Elles doivent contenir un groupe 'date' et un groupe 'user'.
# Pour le CAS on prend comme entrée cat ~/cas.log | grep -B 2 -A 2 "ACTION: AUTHENTICATION_SUCCESS"| grep 'WHEN\|WHO'|sed 'N;s/\n/ /'
# Pour le CAS on prend comme entrée
# cat ~/cas.log | grep -B 2 -A 2 "ACTION: AUTHENTICATION_SUCCESS"| grep 'WHEN\|WHO'|sed 'N;s/\n/ /'
COMPILED_REGEX = map(re.compile, [
r'^(?P<date>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}).*(?:'r'dovecot.*Login: user=<|'r'sshd.*Accepted.*for 'r')(?P<user>[^ >]+).*$',
r'^(?P<date>.*) LOGIN INFO User logged in : (?P<user>.*)',
......@@ -48,8 +48,10 @@ DATE_FORMATS = [
"%a %b %d CEST %H:%M:%S%Y"
]
class Command(BaseCommand):
help = 'Update the time of the latest connection for users by matching stdin against a set of regular expressions'
help = ('Update the time of the latest connection for users by matching '
'stdin against a set of regular expressions')
def handle(self, *args, **options):
......@@ -65,7 +67,9 @@ class Command(BaseCommand):
for i, regex in enumerate(COMPILED_REGEX):
m = regex.match(line)
if m:
parsed_log[m.group('user')] = make_aware(datetime.strptime(m.group('date'), DATE_FORMATS[i]))
parsed_log[m.group('user')] = make_aware(
datetime.strptime(m.group('date'), DATE_FORMATS[i])
)
return parsed_log
parsed_log = parse_logs(sys.stdin)
......
......@@ -7,8 +7,11 @@ from users.models import User
UTC = pytz.timezone('UTC')
# TODO : remove of finsihed this because currently it should
# be failing! Who commited that ?!
class Command(BaseCommand):
commands = ['email_remainder',]
commands = ['email_remainder']
args = '[command]'
help = 'Send email remainders'
......@@ -27,6 +30,6 @@ class Command(BaseCommand):
elif remaining.days == 1:
last_day_reminder()
def month_reminder():
pass
......@@ -20,6 +20,7 @@ from django.core.management.base import BaseCommand, CommandError
from users.models import User
class Command(BaseCommand):
help = 'Synchronise le ldap à partir du sql. A utiliser dans un cron'
......@@ -37,4 +38,3 @@ class Command(BaseCommand):
def handle(self, *args, **options):
for usr in User.objects.all():
usr.ldap_sync(mac_refresh=options['full'])
This diff is collapsed.
......@@ -20,11 +20,12 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#Maël Kervella
# Maël Kervella
from rest_framework import serializers
from users.models import Club, Adherent
class MailingSerializer(serializers.ModelSerializer):
name = serializers.CharField(source='pseudo')
......@@ -32,6 +33,7 @@ class MailingSerializer(serializers.ModelSerializer):
model = Club
fields = ('name',)
class MailingMemberSerializer(serializers.ModelSerializer):
class Meta:
model = Adherent
......
......@@ -34,109 +34,79 @@ urlpatterns = [
url(r'^new_user/$', views.new_user, name='new-user'),
url(r'^new_club/$', views.new_club, name='new-club'),
url(r'^edit_info/(?P<userid>[0-9]+)$', views.edit_info, name='edit-info'),
url(
r'^edit_club_admin_members/(?P<clubid>[0-9]+)$',
url(r'^edit_club_admin_members/(?P<clubid>[0-9]+)$',
views.edit_club_admin_members,
name='edit-club-admin-members'
),
name='edit-club-admin-members'),
url(r'^state/(?P<userid>[0-9]+)$', views.state, name='state'),
url(r'^groups/(?P<userid>[0-9]+)$', views.groups, name='groups'),
url(r'^password/(?P<userid>[0-9]+)$', views.password, name='password'),
url(r'^del_group/(?P<userid>[0-9]+)/(?P<listrightid>[0-9]+)$', views.del_group, name='del-group'),
url(r'^del_group/(?P<userid>[0-9]+)/(?P<listrightid>[0-9]+)$',
views.del_group,
name='del-group'),
url(r'^new_serviceuser/$', views.new_serviceuser, name='new-serviceuser'),
url(
r'^edit_serviceuser/(?P<serviceuserid>[0-9]+)$',
url(r'^edit_serviceuser/(?P<serviceuserid>[0-9]+)$',
views.edit_serviceuser,
name='edit-serviceuser'
),
url(
r'^del_serviceuser/(?P<serviceuserid>[0-9]+)$',
name='edit-serviceuser'),
url(r'^del_serviceuser/(?P<serviceuserid>[0-9]+)$',
views.del_serviceuser,
name='del-serviceuser'
),
name='del-serviceuser'),
url(r'^add_ban/(?P<userid>[0-9]+)$', views.add_ban, name='add-ban'),
url(r'^edit_ban/(?P<banid>[0-9]+)$', views.edit_ban, name='edit-ban'),
url(
r'^add_whitelist/(?P<userid>[0-9]+)$',
url(r'^add_whitelist/(?P<userid>[0-9]+)$',
views.add_whitelist,
name='add-whitelist'
),
url(
r'^edit_whitelist/(?P<whitelistid>[0-9]+)$',
name='add-whitelist'),
url(r'^edit_whitelist/(?P<whitelistid>[0-9]+)$',
views.edit_whitelist,
name='edit-whitelist'
),
name='edit-whitelist'),
url(r'^add_school/$', views.add_school, name='add-school'),
url(
r'^edit_school/(?P<schoolid>[0-9]+)$',
url(r'^edit_school/(?P<schoolid>[0-9]+)$',
views.edit_school,
name='edit-school'
),
name='edit-school'),
url(r'^del_school/$', views.del_school, name='del-school'),
url(r'^add_listright/$', views.add_listright, name='add-listright'),
url(
r'^edit_listright/(?P<listrightid>[0-9]+)$',
url(r'^edit_listright/(?P<listrightid>[0-9]+)$',
views.edit_listright,
name='edit-listright'
),
name='edit-listright'),
url(r'^del_listright/$', views.del_listright, name='del-listright'),
url(r'^add_shell/$', views.add_shell, name='add-shell'),
url(
r'^edit_shell/(?P<listshellid>[0-9]+)$',
url(r'^edit_shell/(?P<listshellid>[0-9]+)$',
views.edit_shell,
name='edit-shell'
),
url(
r'^del_shell/(?P<listshellid>[0-9]+)$',
name='edit-shell'),
url(r'^del_shell/(?P<listshellid>[0-9]+)$',
views.del_shell,
name='del-shell'
),
name='del-shell'),
url(r'^profil/(?P<userid>[0-9]+)$', views.profil, name='profil'),
url(r'^index_ban/$', views.index_ban, name='index-ban'),
url(r'^index_white/$', views.index_white, name='index-white'),
url(r'^index_school/$', views.index_school, name='index-school'),
url(r'^index_shell/$', views.index_shell, name='index-shell'),
url(r'^index_listright/$', views.index_listright, name='index-listright'),
url(
r'^index_serviceusers/$',
url(r'^index_serviceusers/$',
views.index_serviceusers,
name='index-serviceusers'
),
name='index-serviceusers'),
url(r'^mon_profil/$', views.mon_profil, name='mon-profil'),
url(r'^process/(?P<token>[a-z0-9]{32})/$', views.process, name='process'),
url(r'^reset_password/$', views.reset_password, name='reset-password'),
url(r'^mass_archive/$', views.mass_archive, name='mass-archive'),
url(
r'^history/(?P<object_name>\w+)/(?P<object_id>[0-9]+)$',
url(r'^history/(?P<object_name>\w+)/(?P<object_id>[0-9]+)$',
re2o.views.history,
name='history',
kwargs={'application':'users'},
),
kwargs={'application': 'users'}),
url(r'^$', views.index, name='index'),
url(r'^index_clubs/$', views.index_clubs, name='index-clubs'),
url(
r'^rest/ml/std/$',
url(r'^rest/ml/std/$',
views.ml_std_list,
name='ml-std-list'
),
url(
r'^rest/ml/std/member/(?P<ml_name>\w+)/$',
name='ml-std-list'),
url(r'^rest/ml/std/member/(?P<ml_name>\w+)/$',
views.ml_std_members,
name='ml-std-members'
),
url(
r'^rest/ml/club/$',
name='ml-std-members'),
url(r'^rest/ml/club/$',
views.ml_club_list,
name='ml-club-list'
),
url(
r'^rest/ml/club/admin/(?P<ml_name>\w+)/$',
name='ml-club-list'),
url(r'^rest/ml/club/admin/(?P<ml_name>\w+)/$',
views.ml_club_admins,
name='ml-club-admins'
),
url(
r'^rest/ml/club/member/(?P<ml_name>\w+)/$',
name='ml-club-admins'),
url(r'^rest/ml/club/member/(?P<ml_name>\w+)/$',
views.ml_club_members,
name='ml-club-members'
),
name='ml-club-members'),
]
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment