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

fix: sessions cannot be edited after cfs ends #6757

Merged
merged 2 commits into from
Jan 21, 2020

Conversation

codedsun
Copy link
Contributor

Fixes #6726

Short description of what this resolves:

fix: sessions cannot be edited after cfs ends

Checklist

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream development branch.
  • The unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All the functions created/modified in this PR contain relevant docstrings.

@auto-label auto-label bot added the fix label Jan 18, 2020
Copy link
Member

@mrsaicharan1 mrsaicharan1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this locally?

@codedsun
Copy link
Contributor Author

codedsun commented Jan 18, 2020

@mrsaicharan1 - Yes the CI is failing, I am fixing the dredd test

@codecov
Copy link

codecov bot commented Jan 18, 2020

Codecov Report

Merging #6757 into development will decrease coverage by 0.01%.
The diff coverage is 43.75%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #6757      +/-   ##
===============================================
- Coverage         65.4%   65.38%   -0.02%     
===============================================
  Files              300      301       +1     
  Lines            15337    15356      +19     
===============================================
+ Hits             10031    10041      +10     
- Misses            5306     5315       +9
Impacted Files Coverage Δ
app/api/speakers.py 47.42% <33.33%> (-0.45%) ⬇️
app/api/sessions.py 41.12% <33.33%> (-0.2%) ⬇️
app/api/helpers/speaker.py 50% <50%> (ø)
app/api/schema/events.py 91.53% <0%> (+0.06%) ⬆️
app/models/event.py 78.52% <0%> (+0.15%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f1787ca...73ae8f9. Read the comment docs.

@@ -148,6 +150,11 @@ def before_update_object(self, session, data, view_kwargs):
if session.is_locked and data.get('is_locked') == session.is_locked:
raise ForbiddenException({'source': '/data/attributes/is-locked'}, "Locked sessions cannot be edited")

speakers_call = safe_query(self, SpeakersCall, 'event_id', session.event_id, 'event-id')
if speakers_call.ends_at.replace(tzinfo=None) <= datetime.now().replace(tzinfo=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I won't be able to delete the session as well.

Second, you have made it timezone unaware

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal - Shall the sessions be deleted after the CFS is ended?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admin/Co-organizer should be able to edit and delete both

@codedsun
Copy link
Contributor Author

@iamareebjamal - Review

Copy link
Member

@kushthedude kushthedude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the complete issue, Speaker details needs to be locked as well. Or if you are partially fixing than don't mention the fixes keyword!

@codedsun
Copy link
Contributor Author

codedsun commented Jan 19, 2020

Read the complete issue, Speaker details needs to be locked as well

I have read the issue, the speaker details can't be locked currently as it's related to the user not the CFS of the event. Once the speaker is created the same profile is applied for all the cfs of every event.
@kushthedude

Edit: The above is not true as the speaker profile is generated everytime for every new event

@kushthedude
Copy link
Member

kushthedude commented Jan 19, 2020 via email

@codedsun
Copy link
Contributor Author

codedsun commented Jan 19, 2020

@kushthedude - What I looked upon is for every event a new speaker profile is generated.

@codedsun codedsun force-pushed the sessions-edit branch 2 times, most recently from 70ed3e9 to 5f0755e Compare January 19, 2020 09:02
@codedsun
Copy link
Contributor Author

@iamareebjamal @kushthedude @mrsaicharan1 - Please review. Thanks

@codedsun
Copy link
Contributor Author

@iamareebjamal - Review please thanks.

if speakers_call and not (has_access('is_admin') or has_access('is_organizer', event_id=speaker.event_id) or
has_access('is_coorganizer', event_id=speaker.event_id)):
speakers_call_tz = speakers_call.ends_at.tzinfo
if speakers_call.ends_at <= datetime.now().replace(tzinfo=speakers_call_tz):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate logic

from app.models.session_speaker_link import SessionsSpeakersLink
from app.models.user import User

from datetime import datetime

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'datetime.datetime' imported but unused

from app.api.schema.speakers import SpeakerSchema
from app.models import db
from app.models.event import Event
from app.models.session import Session
from app.models.speaker import Speaker
from app.models.speakers_call import SpeakersCall

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'app.models.speakers_call.SpeakersCall' imported but unused

@@ -17,6 +18,8 @@
from app.models.session_type import SessionType
from app.models.speaker import Speaker
from app.models.track import Track
from app.models.speakers_call import SpeakersCall
from datetime import datetime

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'datetime.datetime' imported but unused

@@ -17,6 +18,8 @@
from app.models.session_type import SessionType
from app.models.speaker import Speaker
from app.models.track import Track
from app.models.speakers_call import SpeakersCall

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'app.models.speakers_call.SpeakersCall' imported but unused

else:
return True
else:
raise ForbiddenException({'source' : '/data/event-id'}, 'Speaker Calls for event {id} not found'.format(id=event_id))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (125 > 120 characters)
whitespace before ':'

speakers_call_tz = speakers_call.ends_at.tzinfo
if speakers_call.ends_at <= datetime.now()\
.replace(tzinfo=speakers_call_tz) and not (has_access('is_admin')
or has_access('is_organizer', event_id=event_id) or has_access('is_coorganizer', event_id=event_id)):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent
visually indented line with same indent as next logical line

@@ -0,0 +1,22 @@

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

speakers_call = SpeakersCall.query.filter_by(event_id=event_id).one()
if speakers_call:
speakers_call_tz = speakers_call.ends_at.tzinfo
if speakers_call.ends_at <= datetime.now().replace(tzinfo=speakers_call_tz)\

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

@codedsun codedsun force-pushed the sessions-edit branch 2 times, most recently from 110d5d1 to 7236b59 Compare January 20, 2020 14:22
speakers_call = SpeakersCall.query.filter_by(event_id=event_id).one()
if speakers_call:
speakers_call_tz = speakers_call.ends_at.tzinfo
if speakers_call.ends_at <= datetime.now().replace(tzinfo=speakers_call_tz) \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

@codedsun
Copy link
Contributor Author

@iamareebjamal - Review now

speakers_call = SpeakersCall.query.filter_by(event_id=event_id).one()
if speakers_call:
speakers_call_tz = speakers_call.ends_at.tzinfo
if speakers_call.ends_at <= datetime.now().replace(tzinfo=speakers_call_tz) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use datetime.utcnow()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal - Won't work

TypeError: can't compare offset-naive and offset-aware datetimes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to compare the current time (with the timezone of the speaker call) and the speaker call end date which already is timezone aware

speakers_call = SpeakersCall.query.filter_by(event_id=event_id).one()
if speakers_call:
speakers_call_tz = speakers_call.ends_at.tzinfo
if speakers_call.ends_at <= datetime.now().replace(tzinfo=speakers_call_tz) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just return not of this expression, no need for explicit returns of boolean

@codedsun
Copy link
Contributor Author

@iamareebjamal - Ping!

Method to check that user has permission to edit the speaker or session
after the CFS ends
"""
speakers_call = SpeakersCall.query.filter_by(event_id=event_id).one()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will not filter out deleted speaker calls

Method to check that user has permission to edit the speaker or session
after the CFS ends
"""
speakers_call = SpeakersCall.query.filter_by(event_id=event_id, deleted_at=None).one()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

@niranjan94
Copy link
Member

Codacy Here is an overview of what got changed by this pull request:

Complexity increasing per file
==============================
- app/api/helpers/speaker.py  5
         

See the complete overview on Codacy

@codedsun
Copy link
Contributor Author

@iamareebjamal - Review

@iamareebjamal iamareebjamal merged commit d2d7c37 into fossasia:development Jan 21, 2020
@codedsun
Copy link
Contributor Author

@iamareebjamal - Thankyou lord 🥇😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Session & Speaker: User can change his session/speaker details after CFS is closed
6 participants