hedy
hedy copied to clipboard
🧹 Move public_profile code from app.py to auth.py
Description
Currently we store the public profile related POST functions in app.py
to ensure we can push achievements to the users. We are unable to perform this action in auth.py
due to circular imports. However, with the use of requests
we can simply make a POST from anywhere on the website, not being restricted by any imports. We use the same structure for when we are retrieving achievements on the front-end.
Still struggling a bit on what would be the best approach to fix this. By far the easiest solution would be to simply remove the achievement, but this is not the desired solution. Shortly stated this is caused by a bad dependency implementation long ago (my bad...). We have to decide if re-writing the achievements structure is worth if or if we want to use a "bucket-fix" as described above.
Hi @jpelay Another old issue to look into, I am not sure this is still relevant?
Hi @jtwaleson! Here is another issue about cleaning up the code base that you might enjoy working on? (no rush of course, I know your already have 2 other issues to work on, but since we are cleaning up, we are also looking whether we have people to take on older open issues)
Description Currently we store the public profile related POST functions in
app.py
to ensure we can push achievements to the users. We are unable to perform this action inauth.py
due to circular imports. However, with the use ofrequests
we can simply make a POST from anywhere on the website, not being restricted by any imports. We use the same structure for when we are retrieving achievements on the front-end.
@Felienne is this still the current state? I haven't really done something like this yet, so not sure if I can easily implement 'requests'?
Description Currently we store the public profile related POST functions in
app.py
to ensure we can push achievements to the users. We are unable to perform this action inauth.py
due to circular imports. However, with the use ofrequests
we can simply make a POST from anywhere on the website, not being restricted by any imports. We use the same structure for when we are retrieving achievements on the front-end.@Felienne is this still the current state? I haven't really done something like this yet, so not sure if I can easily implement 'requests'?
I don't know to be honest! Maybe @jpelay knows? If not, surely @rix0rrr will!
Thanks for the confidence, but to be honest I'm not quite sure either 😅
What we have to go on is this:
Move public_profile code from app.py to auth.py
So apparently there is some endpoint code that has to do with public profiles, that should have been in auth.py
but wasn't put there because of:
due to circular imports
Probably there is a 3rd file somewhere that currently imports auth.py
, but also that auth.py
would need to import in order to do public profile-related work.
That's why the public_profile code was put into app.py
, because nothing imports app.py
.
However, with the use of
requests
we can simply make a POST from anywhere on the website
This is the part that confuses me the most.
requests
is a Python library that we use to make HTTP requests to other websites: https://requests.readthedocs.io/en/latest/
The only thing that is making HTTP requests currently is:
- The frontend to the backend.
- The backend to services like Dynamo and S3 and Mailchimp.
Since requests
is a backend library (Python), the only thing I can think of that @TiBiBa had in mind here was the backend making HTTP requests to itself? But that seems unnecessary, you can also reorganize the code.
Bottom line: I'm also not quite sure what was meant here.
Aha it probably has to do with this code:
https://github.com/hedyorg/hedy/blob/main/app.py#L2526
I think the point is to move this function:
@app.route('/auth/public_profile', methods=['POST'])
@requires_login
def update_public_profile(user):
To auth.py
, by untangling some dependencies.