Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o
Commits
12637841
Commit
12637841
authored
Oct 15, 2017
by
chirac
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Menage
parent
e11b1623
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
144 additions
and
85 deletions
+144
-85
logs/views.py
logs/views.py
+4
-5
machines/views.py
machines/views.py
+2
-22
re2o/utils.py
re2o/utils.py
+136
-0
users/models.py
users/models.py
+0
-56
users/views.py
users/views.py
+2
-2
No files found.
logs/views.py
View file @
12637841
...
...
@@ -47,18 +47,17 @@ from reversion.models import Revision
from
reversion.models
import
Version
,
ContentType
from
users.models
import
User
,
ServiceUser
,
Right
,
School
,
ListRight
,
ListShell
from
users.models
import
Ban
,
Whitelist
,
all_has_access
from
users.models
import
all_whitelisted
,
all_baned
,
all_adherent
from
users.models
import
Ban
,
Whitelist
from
cotisations.models
import
Facture
,
Vente
,
Article
,
Banque
,
Paiement
from
cotisations.models
import
Cotisation
from
machines.models
import
Machine
,
MachineType
,
IpType
,
Extension
,
Interface
from
machines.models
import
Domain
,
IpList
from
machines.views
import
all_active_assigned_interfaces_count
from
machines.views
import
all_active_interfaces_count
from
topologie.models
import
Switch
,
Port
,
Room
from
preferences.models
import
GeneralOption
from
re2o.views
import
form
from
re2o.utils
import
all_whitelisted
,
all_baned
,
all_has_access
,
all_adherent
from
re2o.utils
import
all_active_assigned_interfaces_count
from
re2o.utils
import
all_active_interfaces_count
STATS_DICT
=
{
0
:
[
"Tout"
,
36
],
...
...
machines/views.py
View file @
12637841
...
...
@@ -53,30 +53,10 @@ from .forms import EditIpTypeForm, IpTypeForm, DelIpTypeForm, DomainForm, AliasF
from
.forms
import
EditOuverturePortListForm
,
EditOuverturePortConfigForm
from
.models
import
IpType
,
Machine
,
Interface
,
IpList
,
MachineType
,
Extension
,
Mx
,
Ns
,
Domain
,
Service
,
Service_link
,
Vlan
,
Nas
,
Text
,
OuverturePortList
,
OuverturePort
from
users.models
import
User
from
users.models
import
all_has_access
from
preferences.models
import
GeneralOption
,
OptionalMachine
from
re2o.templatetags.bootstrap_form_typeahead
import
hidden_id
,
input_id
def
all_active_interfaces
():
"""Renvoie l'ensemble des machines autorisées à sortir sur internet """
return
Interface
.
objects
.
filter
(
machine__in
=
Machine
.
objects
.
filter
(
user__in
=
all_has_access
()).
filter
(
active
=
True
)).
select_related
(
'domain'
).
select_related
(
'machine'
).
select_related
(
'type'
).
select_related
(
'ipv4'
).
select_related
(
'domain__extension'
).
select_related
(
'ipv4__ip_type'
).
distinct
()
def
all_active_assigned_interfaces
():
""" Renvoie l'ensemble des machines qui ont une ipv4 assignées et disposant de l'accès internet"""
return
all_active_interfaces
().
filter
(
ipv4__isnull
=
False
)
def
all_active_interfaces_count
():
""" Version light seulement pour compter"""
return
Interface
.
objects
.
filter
(
machine__in
=
Machine
.
objects
.
filter
(
user__in
=
all_has_access
()).
filter
(
active
=
True
))
def
all_active_assigned_interfaces_count
():
""" Version light seulement pour compter"""
return
all_active_interfaces_count
().
filter
(
ipv4__isnull
=
False
)
def
form
(
ctx
,
template
,
request
):
c
=
ctx
c
.
update
(
csrf
(
request
))
return
render
(
request
,
template
,
c
)
from
re2o.utils
import
all_active_assigned_interfaces
,
all_has_access
from
re2o.views
import
form
def
f_type_id
(
is_type_tt
):
""" The id that will be used in HTML to store the value of the field
...
...
re2o/utils.py
0 → 100644
View file @
12637841
# -*- mode: python; coding: utf-8 -*-
# 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.
#
# Copyright © 2017 Gabriel Détraz
# Copyright © 2017 Goulven Kermarec
# Copyright © 2017 Augustin Lemesle
#
# 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.
# -*- coding: utf-8 -*-
# David Sinquin, Gabriel Détraz, Goulven Kermarec
"""
Regroupe les fonctions transversales utiles
Fonction :
- récupérer tous les utilisateurs actifs
- récupérer toutes les machines
- récupérer tous les bans
etc
"""
from
__future__
import
unicode_literals
from
django.utils
import
timezone
from
django.db.models
import
Q
from
cotisations.models
import
Cotisation
,
Facture
,
Paiement
,
Vente
from
machines.models
import
Domain
,
Interface
,
Machine
from
users.models
import
User
,
Ban
,
Whitelist
from
preferences.models
import
Service
DT_NOW
=
timezone
.
now
()
def
all_adherent
(
search_time
=
DT_NOW
):
""" Fonction renvoyant tous les users adherents. Optimisee pour n'est
qu'une seule requete sql
Inspecte les factures de l'user et ses cotisation, regarde si elles
sont posterieur à now (end_time)"""
return
User
.
objects
.
filter
(
facture__in
=
Facture
.
objects
.
filter
(
vente__in
=
Vente
.
objects
.
filter
(
cotisation__in
=
Cotisation
.
objects
.
filter
(
vente__in
=
Vente
.
objects
.
filter
(
facture__in
=
Facture
.
objects
.
all
().
exclude
(
valid
=
False
)
)
).
filter
(
date_end__gt
=
search_time
)
)
)
).
distinct
()
def
all_baned
(
search_time
=
DT_NOW
):
""" Fonction renvoyant tous les users bannis """
return
User
.
objects
.
filter
(
ban__in
=
Ban
.
objects
.
filter
(
date_end__gt
=
search_time
)
).
distinct
()
def
all_whitelisted
(
search_time
=
DT_NOW
):
""" Fonction renvoyant tous les users whitelistes """
return
User
.
objects
.
filter
(
whitelist__in
=
Whitelist
.
objects
.
filter
(
date_end__gt
=
search_time
)
).
distinct
()
def
all_has_access
(
search_time
=
DT_NOW
):
""" Renvoie tous les users beneficiant d'une connexion
: user adherent ou whiteliste et non banni """
return
User
.
objects
.
filter
(
Q
(
state
=
User
.
STATE_ACTIVE
)
&
~
Q
(
ban__in
=
Ban
.
objects
.
filter
(
date_end__gt
=
search_time
))
&
(
Q
(
whitelist__in
=
Whitelist
.
objects
.
filter
(
date_end__gt
=
search_time
))
|
Q
(
facture__in
=
Facture
.
objects
.
filter
(
vente__in
=
Vente
.
objects
.
filter
(
cotisation__in
=
Cotisation
.
objects
.
filter
(
vente__in
=
Vente
.
objects
.
filter
(
facture__in
=
Facture
.
objects
.
all
()
.
exclude
(
valid
=
False
)
)
).
filter
(
date_end__gt
=
search_time
)
)
)))
).
distinct
()
def
all_active_interfaces
():
"""Renvoie l'ensemble des machines autorisées à sortir sur internet """
return
Interface
.
objects
.
filter
(
machine__in
=
Machine
.
objects
.
filter
(
user__in
=
all_has_access
()
).
filter
(
active
=
True
)
).
select_related
(
'domain'
).
select_related
(
'machine'
)
\
.
select_related
(
'type'
).
select_related
(
'ipv4'
)
\
.
select_related
(
'domain__extension'
).
select_related
(
'ipv4__ip_type'
)
\
.
distinct
()
def
all_active_assigned_interfaces
():
""" Renvoie l'ensemble des machines qui ont une ipv4 assignées et
disposant de l'accès internet"""
return
all_active_interfaces
().
filter
(
ipv4__isnull
=
False
)
def
all_active_interfaces_count
():
""" Version light seulement pour compter"""
return
Interface
.
objects
.
filter
(
machine__in
=
Machine
.
objects
.
filter
(
user__in
=
all_has_access
()
).
filter
(
active
=
True
)
)
def
all_active_assigned_interfaces_count
():
""" Version light seulement pour compter"""
return
all_active_interfaces_count
().
filter
(
ipv4__isnull
=
False
)
users/models.py
View file @
12637841
...
...
@@ -144,62 +144,6 @@ def get_admin_right():
return
admin_right
def
all_adherent
(
search_time
=
DT_NOW
):
""" Fonction renvoyant tous les users adherents. Optimisee pour n'est
qu'une seule requete sql
Inspecte les factures de l'user et ses cotisation, regarde si elles
sont posterieur à now (end_time)"""
return
User
.
objects
.
filter
(
facture__in
=
Facture
.
objects
.
filter
(
vente__in
=
Vente
.
objects
.
filter
(
cotisation__in
=
Cotisation
.
objects
.
filter
(
vente__in
=
Vente
.
objects
.
filter
(
facture__in
=
Facture
.
objects
.
all
().
exclude
(
valid
=
False
)
)
).
filter
(
date_end__gt
=
search_time
)
)
)
).
distinct
()
def
all_baned
(
search_time
=
DT_NOW
):
""" Fonction renvoyant tous les users bannis """
return
User
.
objects
.
filter
(
ban__in
=
Ban
.
objects
.
filter
(
date_end__gt
=
search_time
)
).
distinct
()
def
all_whitelisted
(
search_time
=
DT_NOW
):
""" Fonction renvoyant tous les users whitelistes """
return
User
.
objects
.
filter
(
whitelist__in
=
Whitelist
.
objects
.
filter
(
date_end__gt
=
search_time
)
).
distinct
()
def
all_has_access
(
search_time
=
DT_NOW
):
""" Renvoie tous les users beneficiant d'une connexion
: user adherent ou whiteliste et non banni """
return
User
.
objects
.
filter
(
Q
(
state
=
User
.
STATE_ACTIVE
)
&
~
Q
(
ban__in
=
Ban
.
objects
.
filter
(
date_end__gt
=
search_time
))
&
(
Q
(
whitelist__in
=
Whitelist
.
objects
.
filter
(
date_end__gt
=
search_time
))
|
Q
(
facture__in
=
Facture
.
objects
.
filter
(
vente__in
=
Vente
.
objects
.
filter
(
cotisation__in
=
Cotisation
.
objects
.
filter
(
vente__in
=
Vente
.
objects
.
filter
(
facture__in
=
Facture
.
objects
.
all
()
.
exclude
(
valid
=
False
)
)
).
filter
(
date_end__gt
=
search_time
)
)
)))
).
distinct
()
class
UserManager
(
BaseUserManager
):
"""User manager basique de django"""
def
_create_user
(
...
...
users/views.py
View file @
12637841
...
...
@@ -53,7 +53,7 @@ from reversion.models import Version
from
reversion
import
revisions
as
reversion
from
users.serializers
import
MailSerializer
from
users.models
import
User
,
Right
,
Ban
,
Whitelist
,
School
,
ListRight
from
users.models
import
Request
,
ServiceUser
,
all_has_access
from
users.models
import
Request
,
ServiceUser
from
users.forms
import
DelRightForm
,
BanForm
,
WhitelistForm
,
DelSchoolForm
from
users.forms
import
DelListRightForm
,
NewListRightForm
from
users.forms
import
InfoForm
,
BaseInfoForm
,
StateForm
...
...
@@ -65,7 +65,7 @@ from machines.models import Machine
from
preferences.models
import
OptionalUser
,
GeneralOption
from
re2o.views
import
form
from
re2o.utils
import
all_has_access
def
password_change_action
(
u_form
,
user
,
request
,
req
=
False
):
""" Fonction qui effectue le changeemnt de mdp bdd"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment