-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat: Serving event invoices through a protected route #6145
feat: Serving event invoices through a protected route #6145
Conversation
|
||
################ | ||
|
||
@ticket_blueprint.route('/events/invoices/<string:invoice_identifier>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 2 blank lines, found 5
7c91ac4
to
a69eee9
Compare
return ForbiddenError({'source': ''}, 'Authentication Required to access Invoice').respond() | ||
|
||
|
||
@ticket_blueprint.route('/events/invoices/<string:invoice_identifier>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redefinition of unused 'event_invoices' from line 349
a69eee9
to
701d844
Compare
Codecov Report
@@ Coverage Diff @@
## development #6145 +/- ##
===============================================
- Coverage 66.1% 66.07% -0.04%
===============================================
Files 288 288
Lines 14484 14503 +19
===============================================
+ Hits 9575 9583 +8
- Misses 4909 4920 +11
Continue to review full report at Codecov.
|
65fbdfc
to
7686a12
Compare
@iamareebjamal @uds5501 @shreyanshdwivedi Please have a look at this as it is ready now. |
The title of this PR seems misleading xD. Instead of "secure", it can be simply "protected" or "restricted" |
app/api/auth.py
Outdated
@ticket_blueprint.route('/events/invoices/<string:invoice_identifier>') | ||
@jwt_required() | ||
def event_invoices(invoice_identifier): | ||
if current_user: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are better design methods that you can consider. For eg:
if not current_user:
raise Forbidden error
There will be no unnecessary if-else ladder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@poush This if-else ladder is required because at each stage, we are validating the user & the corresponding permissions. If there is any violation at any point, we throw the appropriate exception.
The example given by you is more or less the equivalent of my logic. If we use
if not current_user:
raise Forbidden error
we would then have to proceed with the checks in the else block (similar to what I've implemented)
else if current_user.is_staff and current_user.is_verified:
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we would then have to proceed with the checks in the else block
No you won't
You can assume from the next line that current_user is present, removing the need of nested conditions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we would then have to proceed with the checks in the else block
No you won't
You can assume from the next line that current_user is present, removing the need of nested conditions
Won't the nesting still be present to check for current_user.is_verified & other cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if current_user:
# 1 level nesting
if current_user.is_verified:
# 2 level
else:
# 2 level
throw
else:
# 1 level
throw
Max Level 2
Conditions 4
if not current_user:
throw
if current_user.is_verified:
throw
# continue
Max level nesting: 0
Conditions 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamareebjamal @poush Understood! Will be updating this.
5f443af
to
3bbece4
Compare
9b8a190
to
26e4503
Compare
184735d
to
2b3002b
Compare
2b3002b
to
af13476
Compare
af13476
to
ff2ff13
Compare
Refactored code to reduce nesting
ff2ff13
to
cd7c662
Compare
@iamareebjamal @poush THis is ready for another review |
Refactored code to reduce nesting
Fixes #6144
Short description of what this resolves:
This route serves event invoices in the same way the order invoices and tickets are served. It allows event organizers to access their respective event invoices.
Allows staff members to download/view them.
Changes proposed in this pull request:
Checklist
development
branch.