Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add social features [1st part] #360

Draft
wants to merge 349 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
349 commits
Select commit Hold shift + click to select a range
cd94318
Merge branch 'dev' into add-social-features
SamR1 Sep 14, 2023
864c9fd
Merge branch 'dev' into add-social-features
SamR1 Sep 20, 2023
dcab166
Client - update translation on reports
SamR1 Sep 20, 2023
7f102cf
API - return report comment id
SamR1 Sep 26, 2023
052ad55
Client - hide comment actions buttons in admin
SamR1 Sep 26, 2023
7dbe155
Client - add note on a report in administration
SamR1 Sep 26, 2023
00c1aa9
API - mark report as unresolved
SamR1 Sep 26, 2023
0323bba
Client - mark a report as (un-)resolved
SamR1 Sep 26, 2023
a068709
Client - update report detail display
SamR1 Sep 26, 2023
b903297
API - reports refacto
SamR1 Sep 27, 2023
9d239f4
API - create notification on report creation
SamR1 Sep 27, 2023
46e2494
Client - display report notification
SamR1 Sep 30, 2023
07d10d7
Client - fix notification icon padding in navbar
SamR1 Sep 30, 2023
ff5ea21
Client - fix translation in user route
SamR1 Sep 30, 2023
70e09c5
Client - fix report detail display on small screens
SamR1 Sep 30, 2023
0d5fa06
Client - hide item when empty in user detail
SamR1 Sep 30, 2023
7f5e037
Merge branch 'dev' into add-social-features
SamR1 Oct 2, 2023
57bf9e9
Merge branch 'dev' into add-social-features
SamR1 Oct 4, 2023
5065796
Merge branch 'dev' into add-social-features
SamR1 Oct 8, 2023
159b8c9
API - update dependency
SamR1 Oct 11, 2023
c3c7868
Client - init workout reporting
SamR1 Oct 11, 2023
37c889a
Client - init user reporting
SamR1 Oct 11, 2023
9108ddc
Client - fix User card style
SamR1 Oct 11, 2023
90713ca
Client - display reports in filters only for admins
SamR1 Oct 11, 2023
ee711d1
Client - lint fix
SamR1 Oct 11, 2023
57235fd
API - deactivate a user account
SamR1 Oct 11, 2023
d5b773b
Client - update user active status (in report detail)
SamR1 Oct 11, 2023
e90badb
API - update test
SamR1 Oct 15, 2023
c3158fd
Client - display user status in user card
SamR1 Oct 15, 2023
5cf57e5
Client - update reports list display
SamR1 Oct 15, 2023
8207885
Merge branch 'dev' into add-social-features
SamR1 Nov 18, 2023
0acfb93
fix after merge
SamR1 Nov 18, 2023
f68e0db
Merge branch 'dev' into add-social-features
SamR1 Nov 19, 2023
d4427d6
Merge branch 'dev' into add-social-features
SamR1 Nov 22, 2023
565e50c
Client - update marked
SamR1 Nov 25, 2023
7d8f855
Client - fix wrong conflict resolution after previous merge on AdminMenu
SamR1 Nov 25, 2023
650f3a6
Client - fix style dashboard
SamR1 Nov 25, 2023
66c317b
API - fix users cli when setting admin rights
SamR1 Nov 26, 2023
c2b5159
API - minor test refacto
SamR1 Dec 3, 2023
f948d7a
API - init user account suspension
SamR1 Dec 3, 2023
82de8e7
Client - user account suspension instead of deactivation in moderation
SamR1 Dec 3, 2023
a6e5775
Client - update suspended user display (WIP)
SamR1 Dec 3, 2023
2cc1ff9
API & Client - suspended user has a limited access to application (wip)
SamR1 Dec 9, 2023
2cc21b9
Client - display suspension message in User Header
SamR1 Dec 9, 2023
c3520ad
Merge branch 'dev' into add-social-features
SamR1 Dec 20, 2023
0f4415e
update migration after merge
SamR1 Dec 20, 2023
7061242
Merge branch 'dev' into add-social-features
SamR1 Dec 23, 2023
a4686d3
Client - remove duplicated error message on user info
SamR1 Dec 26, 2023
b46a16d
API - workouts from suspended user are not returned in timeline
SamR1 Dec 26, 2023
0e76a5b
API - suspended users are not returned in relationships
SamR1 Dec 26, 2023
dd9214f
API - notifications from suspended users are not returned
SamR1 Dec 26, 2023
c7bf152
Merge branch 'dev' into add-social-features
SamR1 Jan 6, 2024
1640f62
Client - hide actions buttons when report is resolved in admin
SamR1 Jan 7, 2024
2e3b35b
API - returns records ordered by type when getting workout
SamR1 Jan 7, 2024
c8dee8c
API - store user when resolving report
SamR1 Jan 7, 2024
b2e4624
Client - display user who resolves report
SamR1 Jan 7, 2024
05a366b
Client - minor refacto
SamR1 Jan 7, 2024
d9c6992
API - minor refacto on user service
SamR1 Jan 10, 2024
4fbc304
API - refacto (init administration services)
SamR1 Jan 10, 2024
9601873
API & Client - log action in db on report update & user (un-)suspension
SamR1 Jan 10, 2024
0928cbb
API - return admin action w/ report
SamR1 Jan 13, 2024
3ddc154
API - return actions and comments only when getting one report
SamR1 Jan 13, 2024
49278bf
Client - display admin actions on report detail
SamR1 Jan 13, 2024
ad57c25
Client - minor refacto
SamR1 Jan 14, 2024
3a0411a
Client - add label to textarea on report action
SamR1 Jan 14, 2024
980585b
Merge branch 'dev' into add-social-features
SamR1 Jan 17, 2024
ecd2945
API - report is not returned on creation since it is not displayed
SamR1 Jan 21, 2024
3e3f508
API - update admin action model
SamR1 Jan 21, 2024
05f5421
API - a suspended user can not be suspended again
SamR1 Jan 21, 2024
f557aef
API - add note to admin action
SamR1 Jan 27, 2024
c2d80ab
API - get suspension action for a given user
SamR1 Jan 27, 2024
8be7225
API - user can appeal a suspension (wip)
SamR1 Jan 27, 2024
4926eec
Client - add reason when (un-)suspending user account
SamR1 Jan 27, 2024
74573b9
Client - user can appeal a suspension (wip)
SamR1 Jan 27, 2024
ae1680f
API & Client - user can appeal suspension only once
SamR1 Jan 27, 2024
6bfceed
API - process suspension appeal
SamR1 Jan 28, 2024
05d4137
Client - process suspension appeal (wip)
SamR1 Jan 28, 2024
62f1cda
Client - buttons translations refacto
SamR1 Jan 28, 2024
b09118a
Client - add link to make appeal on user profile
SamR1 Jan 28, 2024
1c24f42
API - minor tests refacto
SamR1 Jan 28, 2024
c689c54
API - add missing tests
SamR1 Jan 28, 2024
280fe6c
API & Client - display notification when a user appeal suspension
SamR1 Jan 28, 2024
ba6eece
Client - minor refacto
SamR1 Jan 28, 2024
2558499
Client - hide report button after submitting report
SamR1 Jan 28, 2024
670bc9c
Merge branch 'dev' into add-social-features
SamR1 Feb 4, 2024
d8cf5e9
Client - minor refacto
SamR1 Feb 7, 2024
be67d24
Client - update report form display on workout detail
SamR1 Feb 7, 2024
fd5d017
Client - update report form display on comments
SamR1 Feb 7, 2024
6db6257
Merge branch 'dev' into add-social-features
SamR1 Feb 10, 2024
efd7664
API - report id and admin id are mandatory on user (un)-suspension
SamR1 Feb 14, 2024
9e23400
API & Client - refacto (rename 'note' column on admin_actions table)
SamR1 Feb 14, 2024
2f76bf0
Client - display admin action reason
SamR1 Feb 14, 2024
97bc35e
API - minor refacto on workouts decorator
SamR1 Feb 14, 2024
dc179bf
API - report creation refacto
SamR1 Feb 18, 2024
6d309e0
API & Client - allow deleting reported object or reporter (wip)
SamR1 Feb 18, 2024
437b6dc
API & Client - user suspension refacto
SamR1 Feb 21, 2024
cf516a0
API - tests refacto
SamR1 Feb 25, 2024
c16f55c
API - init workout/comment moderation
SamR1 Feb 25, 2024
5bfac2f
API - init admin action on workouts/comments
SamR1 Feb 25, 2024
9419861
API - create admin action on workout/comment suspension
SamR1 Feb 25, 2024
7b44fcc
API - exclude suspended workouts/comments (wip)
SamR1 Feb 28, 2024
b2753bb
Merge branch 'dev' into add-social-features
SamR1 Mar 2, 2024
12c8065
Merge branch 'dev' into add-social-features
SamR1 Mar 10, 2024
a316e51
Merge branch 'dev' into add-social-features
SamR1 Apr 13, 2024
632db9e
Merge branch 'dev' into add-social-features
SamR1 Apr 21, 2024
954af80
Merge branch 'dev' into add-social-features
SamR1 May 1, 2024
77598a5
Client - minor style fix on workout detail
SamR1 May 1, 2024
234f1ca
Client - handle content suspension in reports (WIP)
SamR1 May 1, 2024
d9c015d
Client - fix typo
SamR1 May 1, 2024
4e269b8
Merge branch 'dev' into add-social-features
SamR1 May 5, 2024
fd471fd
Merge branch 'dev' into add-social-features
SamR1 May 8, 2024
994a4bb
Merge branch 'dev' into add-social-features
SamR1 May 9, 2024
2a22a63
Merge branch 'dev' into add-social-features
SamR1 May 18, 2024
49f0be9
API & Client - return suspended comment only to owner or for report
SamR1 May 20, 2024
590b9df
API & Client - user can not like, comment or report suspended comment
SamR1 May 20, 2024
6250883
Merge branch 'dev' into add-social-features
SamR1 May 20, 2024
8c11cdf
Merge branch 'dev' into add-social-features
SamR1 May 22, 2024
b6fc2d7
API - return admin action with suspended comment
SamR1 May 29, 2024
3c29217
Client - refacto on appeal
SamR1 May 29, 2024
5b5496f
API & Client - move endpoint to process appeal
SamR1 May 29, 2024
c48f254
API - minor test mixin refacto
SamR1 May 29, 2024
325ca33
API & Client - handle comment suspension and appeal
SamR1 May 29, 2024
2bbc37b
Client - add missing 'en' translation
SamR1 Jun 1, 2024
dc9874a
API - return only owner suspended workout in timeline
SamR1 Jun 1, 2024
4407786
API & Client - handle workout suspension and appeal
SamR1 Jun 2, 2024
eb93bab
Client - add missing translations
SamR1 Jun 2, 2024
e9c73fb
Client - report placeholder translations refacto
SamR1 Jun 2, 2024
a842a83
Client - add visibility icon on workout card
SamR1 Jun 2, 2024
9f531a8
API - process workout suspension appeal
SamR1 Jun 2, 2024
134fcc2
Client - add button to hide appeal status
SamR1 Jun 2, 2024
a4c67a7
API & Client - user can report comment, user or workout once
SamR1 Jun 2, 2024
18c2479
Client - init files for 'cs', 'eu' and 'pt' translations
SamR1 Jun 2, 2024
cc10143
Merge branch 'dev' into add-social-features
SamR1 Jun 29, 2024
550c9ec
Client - minor fix
SamR1 Jul 3, 2024
38b4c20
API - rename endpoint
SamR1 Jul 3, 2024
3878f7d
API - send email on user account suspension/reactivation
SamR1 Jul 3, 2024
7e39fda
Merge branch 'dev' into add-social-features
SamR1 Jul 14, 2024
80a7ee0
API - minor refacto
SamR1 Jul 14, 2024
9d9eab7
API & Client - return light version of users in comment & admin actions
SamR1 Jul 14, 2024
ff1628d
API - add function to format date in emails
SamR1 Jul 17, 2024
1eb557c
API - minor refacto
SamR1 Jul 17, 2024
266ca94
API - update tests mixin
SamR1 Jul 17, 2024
c117da0
API - send email on comment/workout suspension
SamR1 Jul 17, 2024
0c4a550
Client - fix error in timeline when loading workouts
SamR1 Jul 17, 2024
5fd52e6
API - improve admin action loading (wip)
SamR1 Jul 17, 2024
c0c2030
API - send email on comment/workout un-suspension
SamR1 Jul 20, 2024
f4addd3
Merge branch 'dev' into add-social-features
SamR1 Jul 20, 2024
90a8f60
API - move admin action creation and email sending in services
SamR1 Jul 21, 2024
6f35db1
API - refacto
SamR1 Jul 21, 2024
0b4b690
API - move appeal process in report service
SamR1 Jul 21, 2024
e1166ad
API & Client - send a warning to user
SamR1 Jul 21, 2024
c78244e
API - minor refacto on reports email service
SamR1 Jul 24, 2024
99f2570
API - update comment/workout (un-)suspension email templates
SamR1 Jul 24, 2024
6817f20
API - add reported comment/workout in user warning email
SamR1 Jul 24, 2024
634d03a
API & Client - a user can only receive one warning per report
SamR1 Jul 24, 2024
a0f1ce3
API - minor refacto
SamR1 Jul 24, 2024
2484ae8
Client - add spinner on report loading and update
SamR1 Jul 24, 2024
23b5375
API & Client - create a notification on comment/workout (un-)suspension
SamR1 Jul 24, 2024
c525f1d
API & Client - display user warning in notifications (wip)
SamR1 Jul 27, 2024
ab6e9e7
Client - minor refacto for existing composable
SamR1 Jul 27, 2024
d9af2bd
Client - refacto loading and sucess for comments and workouts (wip)
SamR1 Jul 27, 2024
c0e3d26
Client - add composables for app, appeal, auth. user and equipments
SamR1 Jul 28, 2024
658fea8
API - speedup tests by handling records only on workouts & records tests
SamR1 Jul 28, 2024
7c82c26
API - minor refacto on workout serializer
SamR1 Jul 28, 2024
8dc2f7d
API - return a light version of workout when getting a list, to improve
SamR1 Jul 31, 2024
a7420f8
API - user serializer refacto (wip)
SamR1 Jul 31, 2024
50288e2
API & Client - user serializer returns light version by default
SamR1 Jul 31, 2024
9afbd5a
Merge branch 'dev' into add-social-features
SamR1 Aug 3, 2024
3470cd0
Merge remote-tracking branch 'origin/dev' into add-social-features
SamR1 Aug 3, 2024
92afc8d
API - fix datetime usage
SamR1 Aug 4, 2024
50785d6
Client - improve notifications display
SamR1 Aug 4, 2024
84e4df4
Client - change default sort in reports list
SamR1 Aug 4, 2024
2c0b2a9
Client - display only one error message in user profil
SamR1 Aug 4, 2024
96691fc
API - tests refacto
SamR1 Aug 4, 2024
02bdb04
API - fix user report creation when content report exists for same user
SamR1 Aug 4, 2024
33bacee
Client - update reports table labels in administration
SamR1 Aug 4, 2024
f550d5d
Client - notifications minor fixes
SamR1 Aug 4, 2024
704f093
Client - display notification date
SamR1 Aug 4, 2024
159d130
Client - hide appeal button for comment in notifs when notif is warning
SamR1 Aug 4, 2024
d285cd4
Client - add button to hide appeal in report
SamR1 Aug 4, 2024
9ddebce
API & Client - handle appeal when user/content are already reactivated
SamR1 Aug 11, 2024
a45987a
Client - fix user appeal
SamR1 Aug 14, 2024
0786506
API - add tests on new emails + fix
SamR1 Aug 14, 2024
def191d
Merge branch 'dev' into add-social-features
SamR1 Aug 25, 2024
5a4e77c
Merge branch 'dev' into add-social-features
SamR1 Sep 1, 2024
ea7be93
Client - display Profil and Notifications buttons on user warning page
SamR1 Sep 1, 2024
2efc814
Client - update user appeal display in admin notifications
SamR1 Sep 1, 2024
2e18cfa
API & Client - process appeal on user warning (wip)
SamR1 Sep 1, 2024
2edb889
Merge branch 'dev' into add-social-features
SamR1 Sep 21, 2024
54dadc7
API & Client - create notif when user warning has been lifted (wip)
SamR1 Sep 22, 2024
d293ba1
API - init email for user warning lifting (WIP)
SamR1 Sep 22, 2024
1701c1d
API - send email when user warning is lifted
SamR1 Sep 29, 2024
c435e6a
API - tests refacto
SamR1 Sep 29, 2024
962fe5d
API - report must exists on admin action creation
SamR1 Sep 29, 2024
e83d9ba
API & Client - report action refacto
SamR1 Sep 29, 2024
c9f6cc0
API & Client - fix user suspension on comment/workout reports
SamR1 Sep 29, 2024
1dc93d3
API - send email on appeal approval on user/comment/workout suspension
SamR1 Sep 29, 2024
e9ae49f
Client - fix translations on description and notes
SamR1 Sep 29, 2024
f7587a6
API & Client - fix user detail display when user is not an admin
SamR1 Sep 29, 2024
53f5cbb
Client - minor fixes
SamR1 Oct 2, 2024
b04f246
API & Client - minor refacto
SamR1 Oct 2, 2024
0a805a9
Merge branch 'dev' into add-social-features
SamR1 Oct 6, 2024
6c91a6e
Client - fix appeal in notifications
SamR1 Oct 6, 2024
6caec1d
Merge branch 'dev' into add-social-features
SamR1 Oct 9, 2024
ecb4cfe
Merge branch 'dev' into add-social-features
SamR1 Oct 12, 2024
580013d
API & Client - update existing appeal on suspension lifting
SamR1 Oct 12, 2024
4681f3f
API & Client - handle reactivation when object already reativated
SamR1 Oct 12, 2024
4e1975b
API & Client - display report associated with suspension in user info
SamR1 Oct 13, 2024
036a72f
Client - fix user picture color on notification marked as read
SamR1 Oct 13, 2024
0bd1ba7
API - fix email on auth user account info
SamR1 Oct 13, 2024
45711d2
Client - fix buttons color and translation on report detail
SamR1 Oct 13, 2024
0a8392b
Merge branch 'dev' into add-social-features
SamR1 Oct 30, 2024
5778512
API & Client - improve workout suspension display + fix
SamR1 Nov 1, 2024
696bee2
API & Client - improve comment suspension display
SamR1 Nov 1, 2024
6d98f4a
API - send email when appeal is rejected
SamR1 Nov 1, 2024
c5dd56d
Merge remote-tracking branch 'origin/dev' into add-social-features
SamR1 Nov 9, 2024
067ac8a
Client - add missing notification types
SamR1 Nov 9, 2024
63db498
Client - add button to access report & missing filters on reports
SamR1 Nov 10, 2024
f5f62d3
API & Client - display in admin in unresolved reports exists
SamR1 Nov 10, 2024
59559d3
API & Client - display user report actions in admin (wip)
SamR1 Nov 10, 2024
f71cdf4
API & Client - add moderation tab in user profile + refacto
SamR1 Nov 11, 2024
da865ca
Client - update link to user when display in administration
SamR1 Nov 11, 2024
597d277
API & Client - handle user suspension in profile
SamR1 Nov 11, 2024
45ccfe9
API & Client - minor refacto
SamR1 Nov 11, 2024
174d866
Client - fix Description and Notes
SamR1 Nov 11, 2024
70de5cd
API - return equipment only to workout owner
SamR1 Nov 11, 2024
68d98f5
API & Client - create notification on user registration
SamR1 Nov 11, 2024
a97dd48
API - fix report action model
SamR1 Nov 11, 2024
91abd04
API - display public workouts only from followed users in timeline
SamR1 Nov 13, 2024
545c555
API - fix workout like response
SamR1 Nov 13, 2024
c9bd63f
Client - update dark theme
SamR1 Nov 13, 2024
a6c21ce
Client - fix like icon
SamR1 Nov 13, 2024
596f583
Client - fix notifications
SamR1 Nov 13, 2024
13980f4
API - fix notification creation on appeal
SamR1 Nov 13, 2024
bb86af5
Client - fix user suggestion background on dark theme
SamR1 Nov 13, 2024
2dd7db3
API - minor tests refacto
SamR1 Nov 13, 2024
8e1e720
API - fix mention notification
SamR1 Nov 13, 2024
8d7c15a
Client - add 'no-console' rule (warn) to ESlint config
SamR1 Nov 16, 2024
c5bc882
API - do not display comment (follower only) notification when user
SamR1 Nov 16, 2024
d52c0cc
API - create mention notification if comment notification does not exist
SamR1 Nov 16, 2024
a09ca22
Client - minor refacto
SamR1 Nov 17, 2024
6a430bf
Client - mention workout owner in comment
SamR1 Nov 17, 2024
d528bb7
Client - make users suggestions on comments tabbable
SamR1 Nov 17, 2024
bae0a2f
API - improve get comments query performances
SamR1 Nov 17, 2024
724432b
Client - display suspension on replies
SamR1 Nov 17, 2024
99ccd19
Merge branch 'dev' into add-social-features
SamR1 Nov 17, 2024
f563bf8
Client - fix mentions
SamR1 Nov 20, 2024
4e9ecff
Client - fix workout and comment display for unauthenticated user
SamR1 Nov 20, 2024
fe0a688
API - add comments to user data export
SamR1 Nov 20, 2024
4ebf02e
lint fix
SamR1 Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .github/workflows/.tests-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
EMAIL_URL: "smtp://none:[email protected]:1025"
FLASK_APP: fittrackee/__main__.py
SENDER_EMAIL: [email protected]
UI_URL: https://0.0.0.0:5000

jobs:
python:
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ test-e2e-client:
E2E_ARGS=client $(PYTEST) e2e --driver firefox $(PYTEST_ARGS)

test-python:
# for tests parallelization: 4 workers max.
# make test-python PYTEST_ARGS="-p no:warnings -n auto --maxprocesses=4"
$(PYTEST) fittrackee $(PYTEST_ARGS)

test-python-cov:
# for tests parallelization: 4 workers max.
# make test-python PYTEST_ARGS="-p no:warnings -n auto --maxprocesses=4"
$(PYTEST) fittrackee --cov-config .coveragerc --cov=fittrackee --cov-report term-missing $(PYTEST_ARGS)
Expand Down
12 changes: 12 additions & 0 deletions fittrackee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.exc import ProgrammingError
from sqlalchemy.ext.declarative import DeclarativeMeta
from werkzeug.middleware.proxy_fix import ProxyFix

from fittrackee.emails.email import EmailService
Expand All @@ -41,6 +42,7 @@
db = SQLAlchemy(
engine_options={"future": True}, session_options={"future": True}
)
BaseModel: DeclarativeMeta = db.Model
bcrypt = Bcrypt()
migrate = Migrate()
email_service = EmailService()
Expand Down Expand Up @@ -128,26 +130,36 @@ def create_app(init_email: bool = True) -> Flask:
pass

from .application.app_config import config_blueprint # noqa
from .comments.comments import comments_blueprint # noqa
from .equipments.equipment_types import equipment_types_blueprint
from .equipments.equipments import equipments_blueprint
from .oauth2.routes import oauth2_blueprint # noqa
from .reports.reports import reports_blueprint # noqa
from .users.auth import auth_blueprint # noqa
from .users.follow_requests import follow_requests_blueprint # noqa
from .users.notifications import notifications_blueprint # noqa
from .users.users import users_blueprint # noqa
from .workouts.records import records_blueprint # noqa
from .workouts.sports import sports_blueprint # noqa
from .workouts.stats import stats_blueprint # noqa
from .workouts.timeline import timeline_blueprint # noqa
from .workouts.workouts import workouts_blueprint # noqa

app.register_blueprint(auth_blueprint, url_prefix='/api')
app.register_blueprint(equipment_types_blueprint, url_prefix='/api')
app.register_blueprint(equipments_blueprint, url_prefix='/api')
app.register_blueprint(oauth2_blueprint, url_prefix='/api')
app.register_blueprint(comments_blueprint, url_prefix='/api')
app.register_blueprint(config_blueprint, url_prefix='/api')
app.register_blueprint(records_blueprint, url_prefix='/api')
app.register_blueprint(sports_blueprint, url_prefix='/api')
app.register_blueprint(stats_blueprint, url_prefix='/api')
app.register_blueprint(users_blueprint, url_prefix='/api')
app.register_blueprint(workouts_blueprint, url_prefix='/api')
app.register_blueprint(follow_requests_blueprint, url_prefix='/api')
app.register_blueprint(timeline_blueprint, url_prefix='/api')
app.register_blueprint(notifications_blueprint, url_prefix='/api')
app.register_blueprint(reports_blueprint, url_prefix='/api')

if app.debug:
logging.getLogger('sqlalchemy').setLevel(logging.WARNING)
Expand Down
9 changes: 3 additions & 6 deletions fittrackee/application/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
from flask import current_app
from sqlalchemy.engine.base import Connection
from sqlalchemy.event import listens_for
from sqlalchemy.ext.declarative import DeclarativeMeta
from sqlalchemy.orm.mapper import Mapper
from sqlalchemy.orm.session import Session
from sqlalchemy.sql import text

from fittrackee import VERSION, db
from fittrackee import BaseModel, db
from fittrackee.users.models import User

BaseModel: DeclarativeMeta = db.Model


class AppConfig(BaseModel):
__tablename__ = 'app_config'
Expand Down Expand Up @@ -55,10 +52,10 @@ def serialize(self) -> Dict:
'privacy_policy': self.privacy_policy,
'privacy_policy_date': self.privacy_policy_date,
'stats_workouts_limit': self.stats_workouts_limit,
'version': VERSION,
'version': current_app.config['VERSION'],
'weather_provider': (
weather_provider
if weather_provider in ['darksky', 'visualcrossing']
if weather_provider in ['visualcrossing']
else None
),
}
Expand Down
Empty file added fittrackee/comments/__init__.py
Empty file.
248 changes: 248 additions & 0 deletions fittrackee/comments/comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
from datetime import datetime
from typing import Dict, Optional, Tuple, Union

from flask import Blueprint, request
from sqlalchemy import exc

from fittrackee import db
from fittrackee.oauth2.server import require_auth
from fittrackee.privacy_levels import PrivacyLevel, can_view
from fittrackee.reports.models import ReportActionAppeal
from fittrackee.responses import (
ForbiddenErrorResponse,
HttpResponse,
InvalidPayloadErrorResponse,
handle_error_and_return_response,
)
from fittrackee.users.models import User
from fittrackee.utils import clean_input, decode_short_id
from fittrackee.workouts.decorators import check_workout
from fittrackee.workouts.models import Workout

from .decorators import check_workout_comment
from .models import Comment, CommentLike, get_comments

comments_blueprint = Blueprint('comments', __name__)


@comments_blueprint.route(
"/workouts/<string:workout_short_id>/comments", methods=["POST"]
)
@require_auth(scopes=["workouts:write"])
@check_workout(only_owner=False, as_data=False)
def add_workout_comment(
auth_user: User, workout: Workout, workout_short_id: str
) -> Union[Tuple[Dict, int], HttpResponse]:
comment_data = request.get_json()
if (
not comment_data
or not comment_data.get('text')
or not comment_data.get('text_visibility')
):
return InvalidPayloadErrorResponse()
try:
reply_to = comment_data.get('reply_to')
comment = None
if reply_to:
comment = Comment.query.filter(
Comment.uuid == decode_short_id(reply_to),
Comment.user_id.not_in(auth_user.get_blocked_by_user_ids()),
).first()
if (
not comment
or comment.suspended_at
or not can_view(comment, "text_visibility", auth_user)
):
return InvalidPayloadErrorResponse("'reply_to' is invalid")

new_comment = Comment(
user_id=auth_user.id,
workout_id=workout.id,
text=clean_input(comment_data['text']),
text_visibility=PrivacyLevel(comment_data['text_visibility']),
reply_to=comment.id if comment else None,
)
db.session.add(new_comment)
db.session.flush()
new_comment.create_mentions()
db.session.commit()

return (
{
'status': 'created',
'comment': new_comment.serialize(auth_user),
},
201,
)
except (exc.IntegrityError, ValueError) as e:
return handle_error_and_return_response(
error=e,
message='Error during comment save.',
status='fail',
db=db,
)


@comments_blueprint.route(
"/comments/<string:comment_short_id>", methods=["GET"]
)
@require_auth(scopes=["workouts:read"], optional_auth_user=True)
@check_workout_comment(only_owner=False)
def get_workout_comment(
auth_user: Optional[User], comment: Comment
) -> Union[Tuple[Dict, int], HttpResponse]:
return (
{
'status': 'success',
'comment': comment.serialize(auth_user, get_parent_comment=True),
},
200,
)


@comments_blueprint.route(
"/workouts/<string:workout_short_id>/comments", methods=["GET"]
)
@require_auth(scopes=['workouts:read'], optional_auth_user=True)
@check_workout(only_owner=False, as_data=False)
def get_workout_comments(
auth_user: Optional[User], workout: Workout, workout_short_id: str
) -> Union[Dict, HttpResponse]:
try:
comments = get_comments(
workout_id=workout.id,
user=auth_user,
)
return {
'status': 'success',
'data': {
'comments': [
comment.serialize(auth_user) for comment in comments
]
},
}
except Exception as e:
return handle_error_and_return_response(e)


@comments_blueprint.route(
"/comments/<string:comment_short_id>", methods=["DELETE"]
)
@require_auth(scopes=["workouts:write"])
@check_workout_comment()
def delete_workout_comment(
auth_user: User, comment: Comment
) -> Union[Tuple[Dict, int], HttpResponse]:
try:
db.session.delete(comment)
db.session.commit()
return {'status': 'no content'}, 204
except (
exc.IntegrityError,
exc.OperationalError,
ValueError,
OSError,
) as e:
return handle_error_and_return_response(e, db=db)


@comments_blueprint.route(
"/comments/<string:comment_short_id>", methods=["PATCH"]
)
@require_auth(scopes=["workouts:write"])
@check_workout_comment()
def update_workout_comment(
auth_user: User, comment: Comment
) -> Union[Dict, HttpResponse]:
comment_data = request.get_json()
if not comment_data or not comment_data.get('text'):
return InvalidPayloadErrorResponse()

try:
comment.text = clean_input(comment_data['text'])
comment.modification_date = datetime.utcnow()
comment.update_mentions()
db.session.commit()
return {
'status': 'success',
'comment': comment.serialize(auth_user),
}

except (exc.IntegrityError, exc.OperationalError, ValueError) as e:
return handle_error_and_return_response(e)


@comments_blueprint.route(
"/comments/<string:comment_short_id>/like", methods=["POST"]
)
@require_auth(scopes=["workouts:write"])
@check_workout_comment(only_owner=False)
def like_comment(
auth_user: User, comment: Comment
) -> Union[Tuple[Dict, int], HttpResponse]:
if comment.suspended_at:
return ForbiddenErrorResponse()
try:
like = CommentLike(user_id=auth_user.id, comment_id=comment.id)
db.session.add(like)
db.session.commit()
except exc.IntegrityError:
db.session.rollback()
return {
'status': 'success',
'comment': comment.serialize(auth_user),
}, 200


@comments_blueprint.route(
"/comments/<string:comment_short_id>/like/undo",
methods=["POST"],
)
@require_auth(scopes=["workouts:write"])
@check_workout_comment(only_owner=False)
def undo_comment_like(
auth_user: User, comment: Comment
) -> Union[Tuple[Dict, int], HttpResponse]:
like = CommentLike.query.filter_by(
user_id=auth_user.id, comment_id=comment.id
).first()
if like:
db.session.delete(like)
db.session.commit()
return {
'status': 'success',
'comment': comment.serialize(auth_user),
}, 200


@comments_blueprint.route(
"/comments/<string:comment_short_id>/suspension/appeal",
methods=["POST"],
)
@require_auth(scopes=["workouts:write"])
@check_workout_comment(only_owner=True)
def appeal_comment_suspension(
auth_user: User, comment: Comment
) -> Union[Tuple[Dict, int], HttpResponse]:
if not comment.suspended_at:
return InvalidPayloadErrorResponse("workout comment is not suspended")
suspension_action = comment.suspension_action
if not suspension_action:
return InvalidPayloadErrorResponse("workout comment has no suspension")

text = request.get_json().get("text")
if not text:
return InvalidPayloadErrorResponse("no text provided")

try:
appeal = ReportActionAppeal(
action_id=suspension_action.id, user_id=auth_user.id, text=text
)
db.session.add(appeal)
db.session.commit()
return {"status": "success"}, 201

except exc.IntegrityError:
return InvalidPayloadErrorResponse("you can appeal only once")
except (exc.OperationalError, ValueError) as e:
return handle_error_and_return_response(e, db=db)
36 changes: 36 additions & 0 deletions fittrackee/comments/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from functools import wraps
from typing import TYPE_CHECKING, Any, Callable, Optional

from fittrackee.responses import ForbiddenErrorResponse, NotFoundErrorResponse

from .exceptions import CommentForbiddenException
from .utils import get_comment

if TYPE_CHECKING:
from fittrackee.users.models import User


def check_workout_comment(only_owner: bool = True) -> Callable:
def decorator_check_workout_comment(f: Callable) -> Callable:
@wraps(f)
def wrapper_check_workout_comment(
*args: Any, **kwargs: Any
) -> Callable:
auth_user: Optional['User'] = args[0]
comment_short_id: str = kwargs["comment_short_id"]

try:
comment = get_comment(comment_short_id, auth_user)
except CommentForbiddenException:
return NotFoundErrorResponse(
f"workout comment not found (id: {comment_short_id})"
)
if only_owner and (
not auth_user or auth_user.id != comment.user.id
):
return ForbiddenErrorResponse()
return f(auth_user, comment)

return wrapper_check_workout_comment

return decorator_check_workout_comment
6 changes: 6 additions & 0 deletions fittrackee/comments/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from fittrackee.exceptions import GenericException


class CommentForbiddenException(GenericException):
def __init__(self) -> None:
super().__init__('error', 'you do not have permissions')
Loading