-
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
fix: add access control check for draft events #7367
Conversation
Codecov Report
@@ Coverage Diff @@
## development #7367 +/- ##
===============================================
+ Coverage 64.18% 64.23% +0.04%
===============================================
Files 259 259
Lines 13126 13130 +4
===============================================
+ Hits 8425 8434 +9
+ Misses 4701 4696 -5
Continue to review full report at Codecov.
|
app/api/events.py
Outdated
if 'Authorization' not in request.headers and not has_access( | ||
'is_registrar', event_id=event.id | ||
): | ||
view_kwargs['id'] = None |
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.
Use after get object
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.
made changes @iamareebjamal pls review
app/api/events.py
Outdated
@@ -659,6 +659,13 @@ def before_get_object(self, view_kwargs): | |||
else: | |||
view_kwargs['id'] = None | |||
|
|||
def after_get_object(self, event, view_kwargs): | |||
if event.state == 'Draft': |
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 is no Draft
state in the event
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.
The default state is this only..
open-event-server/app/models/event.py
Line 76 in 27588e5
state = db.Column(db.String, default="Draft") |
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 changing to
if event.state == 'Draft': | |
if event.state == 'draft': |
is causing logic to fail and I found that it's because "state": "Draft"
in response
** I have created the event using the default configurations
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.
+-----------+---------+
| state | count |
|-----------+---------|
| draft | 664 |
| published | 528 |
+-----------+---------+
Production DB
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.
The default state is this only..
open-event-server/app/models/event.py
Line 76 in 27588e5
state = db.Column(db.String, default="Draft")
Change it here as well
Co-authored-by: Areeb Jamal <[email protected]>
made changes @iamareebjamal pls review |
app/api/events.py
Outdated
@@ -659,6 +659,13 @@ def before_get_object(self, view_kwargs): | |||
else: | |||
view_kwargs['id'] = None | |||
|
|||
def after_get_object(self, event, view_kwargs): | |||
if event.state == "draft": | |||
if 'Authorization' not in request.headers and not has_access( |
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.
This should be or
Great. Now please add unit tests for the conditions
|
def get_event(db, user=None): | ||
event = EventFactoryBasic() | ||
if user: | ||
role, _ = get_or_create(Role, name='owner', title_name='Owner') |
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.
Black would make changes.
@iamareebjamal pls review |
@@ -0,0 +1,61 @@ | |||
from tests.factories.event import EventFactoryBasic |
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.
rename file to test_event_view_access.py
return event | ||
|
||
|
||
def test_eventdetails_draft_get_unauthenticateduser_error(db, client): |
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.
def test_eventdetails_draft_get_unauthenticateduser_error(db, client): | |
def test_event_draft_get_unauthenticated_error(db, client): |
assert response.status_code == 404 | ||
|
||
|
||
def test_eventdetails_draft_get_normaluser_error(db, client, jwt): |
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.
def test_eventdetails_draft_get_normaluser_error(db, client, jwt): | |
def test_event_draft_get_normal_error(db, client, jwt): |
assert response.status_code == 404 | ||
|
||
|
||
def test_eventdetails_draft_get_owner(db, client, user, jwt): |
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.
def test_eventdetails_draft_get_owner(db, client, user, jwt): | |
def test_event_draft_get_owner(db, client, user, jwt): |
assert response.status_code == 200 | ||
|
||
|
||
def test_eventdetails_draft_get_admin(db, client, admin_jwt): |
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.
def test_eventdetails_draft_get_admin(db, client, admin_jwt): | |
def test_event_draft_get_admin(db, client, admin_jwt): |
|
||
|
||
def get_event(db, user=None): | ||
event = EventFactoryBasic() |
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.
Pass in state='draft' explicitly
@manav1403 Thank you. Great job. I have suggested a few final changes in the PR |
|
||
|
||
def get_event(db, user=None): | ||
event = EventFactoryBasic(state='draft') |
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.
Black would make changes.
Fixes #7343
Short description of what this resolves:
Earlier the events with status Draft were visible to any user at the event details endpoint using the id.
The expected behavior was that only admin and registrars should be able to see the drafted events only.
Changes proposed in this pull request:
Checklist
development
branch.