Skip to content

Commit ef53bc3

Browse files
committed
fix/ Fix de la détection de notifications
1 parent bb82e74 commit ef53bc3

File tree

10 files changed

+33
-14
lines changed

10 files changed

+33
-14
lines changed

app/administration/routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from app.models.utilisateur import UTILISATEUR
1717
from app.models.a_acces import A_ACCES
1818
from app.models.role import ROLE
19-
from app.utils import Whoosh
19+
from app.utils import Whoosh, check_notitications
2020
from fasteners import InterProcessLock
2121

2222

@@ -37,6 +37,7 @@ def administration():
3737
roles=all_roles,
3838
is_admin=True,
3939
is_authenticated=True,
40+
has_notifications=check_notitications(),
4041
)
4142

4243

app/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
def admin_required(f):
66
@wraps(f)
77
def decorated_function(*args, **kwargs):
8-
if not current_user.id_Role == 1:
8+
if not current_user.is_admin():
99
abort(403)
1010
return f(*args, **kwargs)
1111
return decorated_function

app/desktop/routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from app import socketio
55
from app.extensions import db
66
from app.models.fichier import FICHIER
7+
from app.utils import check_notitications
78

89
@bp.route('/')
910
@login_required
1011
def desktop():
11-
return render_template('desktop/index.html', is_authenticated=True, is_admin=current_user.id_Role == 1, has_notifications=current_user.NOTIFICATION != [])
12+
return render_template('desktop/index.html', is_authenticated=True, is_admin=current_user.is_admin(), has_notifications=check_notitications())

app/home/routes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from app.models.a_recherche import A_RECHERCHE
88
from app.forms.search_form import SearchForm
99
from datetime import datetime
10+
from app.utils import check_notitications
1011

1112

1213
@bp.route("/", methods=["GET", "POST"])
@@ -30,11 +31,12 @@ def home():
3031
if form.validate_on_submit():
3132
add_research(current_user.id_Utilisateur, form.search.data)
3233
return redirect(url_for("search.search", query=form.search.data))
34+
print(current_user.NOTIFICATION)
3335
return render_template(
3436
"home/index.html",
3537
is_authenticated=True,
36-
is_admin=current_user.id_Role == 1,
37-
has_notifications=current_user.NOTIFICATION != [],
38+
is_admin=current_user.is_admin(),
39+
has_notifications=check_notitications(),
3840
favorite_files=favorite_files,
3941
researches=researches,
4042
form=form,

app/models/utilisateur.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def get_id(self):
2525

2626
def to_dict(self):
2727
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
28+
29+
def is_admin(self):
30+
return self.id_Role == 1
2831

2932
FICHIER_: Mapped[List['FICHIER']] = relationship('FICHIER', secondary='FAVORIS', back_populates='UTILISATEUR_')
3033
ROLE_: Mapped[Optional['ROLE']] = relationship('ROLE', back_populates='UTILISATEUR')

app/notifications/routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from app.models.notification import NOTIFICATION
1919
from app.models.utilisateur import UTILISATEUR
2020
from app.models.role import ROLE
21+
from app.utils import check_notitications
2122

2223

2324
@bp.route("/", methods=["GET"])
@@ -36,7 +37,7 @@ def notifications():
3637
roles=roles,
3738
is_authenticated=True,
3839
is_admin=True,
39-
has_notifications=current_user.NOTIFICATION != [],
40+
has_notifications=check_notitications(),
4041
)
4142

4243

app/profil/routes.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from app.forms.edit_profil_form import Edit_profil_form
88
from flask_bcrypt import check_password_hash, generate_password_hash
99
from app.models.utilisateur import UTILISATEUR
10+
from app.utils import check_notitications
1011

1112

1213
@bp.route("/", methods=["GET", "POST"])
@@ -20,8 +21,8 @@ def profil():
2021
return render_template(
2122
"profil/index.html",
2223
is_authenticated=True,
23-
is_admin=current_user.id_Role == 1,
24-
has_notifications=current_user.NOTIFICATION != [],
24+
is_admin=current_user.is_admin(),
25+
has_notifications=check_notitications(),
2526
user=current_user,
2627
edit_mode=False,
2728
)
@@ -59,8 +60,8 @@ def edit():
5960
return render_template(
6061
"profil/index.html",
6162
is_authenticated=True,
62-
is_admin=current_user.id_Role == 1,
63-
has_notifications=current_user.NOTIFICATION != [],
63+
is_admin=current_user.is_admin(),
64+
has_notifications=check_notitications(),
6465
user=current_user,
6566
form=form,
6667
edit_mode=True,

app/search/routes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from app.forms.search_form import SearchForm
99
from app import socketio
1010
from fasteners import InterProcessLock
11+
from app.utils import check_notitications
1112

1213

1314
@bp.route("/", methods=["GET", "POST"])
@@ -27,8 +28,8 @@ def search():
2728
return render_template(
2829
"search/index.html",
2930
is_authenticated=True,
30-
is_admin=current_user.id_Role == 1,
31-
has_notifications=current_user.NOTIFICATION != [],
31+
is_admin=current_user.is_admin(),
32+
has_notifications=check_notitications(),
3233
folders=results,
3334
query=query,
3435
form=form,

app/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</li>
3838
{% if is_admin %}
3939
<li>
40-
<a href="{{ url_for('administration.administration') }}">Admin</a>
40+
<a href="{{ url_for('administration.administration') }}">Administration</a>
4141
</li>
4242
<li>
4343
<a href="{{ url_for('notifications.notifications') }}">

app/utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from app.extensions import db
2626
from flask_login import current_user
2727
from app.models.favoris import FAVORIS
28+
from app.models.notification import NOTIFICATION
2829
import re
2930

3031
class SingletonMeta(type):
@@ -248,4 +249,12 @@ def read_pptx(self, file_path):
248249
for shape in slide.shapes:
249250
if hasattr(shape, "text"):
250251
text += shape.text
251-
return text
252+
return text
253+
254+
def check_notitications():
255+
"""Check if there is any notification in the database.
256+
257+
Returns:
258+
bool: True if there is any notification, False otherwise.
259+
"""
260+
return NOTIFICATION.query.all() != []

0 commit comments

Comments
 (0)