Skip to content

feature/event privacy + fix eventview error #271

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

Merged
merged 23 commits into from
Feb 20, 2021

Conversation

imimouni
Copy link
Contributor

3 levels of event privacy-
'Public' - can be shown by anyone
'Private' - for other users - The event start date end date and owner is shown all other details are 'private' or not shown
'Hidden' - can only be seen by owner, the event will not be shown to anyone other than the owner

small fix in eventview function - a '?' was missing between 'event_id' and 'messages=' in the routing link.

Copy link
Member

@yammesicka yammesicka left a comment

Choose a reason for hiding this comment

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

Great job! I've added few insights, please take a look :)

Copy link
Member

@yammesicka yammesicka left a comment

Choose a reason for hiding this comment

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

Great job! I've added few more insights

Comment on lines 116 to 126
event = create_event(db=session,
title=title,
start=start,
end=end,
owner_id=owner_id,
privacy=privacy,
content=content,
location=location,
invitees=invited_emails,
category_id=category_id,
availability=availability)
Copy link
Member

Choose a reason for hiding this comment

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

create_events(
    session, title, start, end, owner_id, privacy, content, location,
    invited_emails, category_id, availability,
)

(less space, without repeating things, easy enough to see git diif on next addition)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why this happened...
Almost for all of your comments are stuff I didn't actually change . It's from the prehooks that automatically formatted everything 😭

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it back to the way it was.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, I know you said that it's preferable to not repeat things but as the function itself has some deafult values that sometimes are necessary or not I changed the formatting but did leave the explicit attributing of each variable to the parameters as I saw that otherwise this causes problems and misunderstanding in tests and so on.
It's less pretty yes, but leaves less room for mistakes and doesn't require to change the create_event function parameters order (especially parameters that are not related to my feature which could confuse or mess up other things)

Comment on lines 12 to 25
class PrivateEvent:
"""Represents a private event to show a non-owner of private event"""
def __init__(self, start, end, owner_id) -> None:
self.title = PrivacyKinds.Private.name
self.start = start
self.end = end
self.privacy = PrivacyKinds.Private.name
self.content = PrivacyKinds.Private.name
self.owner_id = owner_id
self.location = PrivacyKinds.Private.name
self.color = Null
self.invitees = PrivacyKinds.Private.name
self.category_id = Null
self.emotion = Null
Copy link
Member

Choose a reason for hiding this comment

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

Why aren't we using the regular Event object from the ORM?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A few reasons - as to not modify the original event to hide all the details, to not create an extra redundant instance in the database and also when using the Event instance there is a problem with an sa_instance attribute that created a lot of problems when I tried to create a copy of the original event.
In short I think that using this neutral object will prevent messing up and cluttering the database and provide an event element with only the relevant non private details.

Copy link
Member

Choose a reason for hiding this comment

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

There's a major problem with such an object, 'cause we will need to keep it updated for any changes of the original event object.
Don't you create it from existing event anyway?

Copy link
Contributor Author

@imimouni imimouni Feb 17, 2021

Choose a reason for hiding this comment

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

Do you have a better suggestion ?
Originally I tried to create a copy of the original event but this resulted in a lot of errors as sqlalchemy adds an "sa_instance" attribute to the object, and when I tried to remove it only for the event copy that also cause a lot of errors. I researched this a lot and found that this is the way others solved these issues- by creating another object to represent only the values we need without a connection to the database.

Is there some way that I could make sure this object will accept any future attributes that will be added to the Event table? Like maybe make it inherit from it ?

Copy link
Member

Choose a reason for hiding this comment

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

Originally I tried to create a copy of the original event but this resulted in a lot of errors as sqlalchemy adds an "sa_instance" attribute to the object

Why is that a problem?


I think the best solution is to use the original Event instance.
If it is not possible, maybe we should inherit from it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I found out (lots of trial and error and additional research) how to overcome sqlalchemy weird additional attributes and create a copy of the event as an Event object, without saving it :)
will be in the commit I will soon upload

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now uploaded :)

@codecov-io
Copy link

codecov-io commented Feb 17, 2021

Codecov Report

Merging #271 (29c5173) into develop (44563e8) will increase coverage by 0.01%.
The diff coverage is 96.22%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #271      +/-   ##
===========================================
+ Coverage    98.23%   98.25%   +0.01%     
===========================================
  Files           70       72       +2     
  Lines         3010     3155     +145     
===========================================
+ Hits          2957     3100     +143     
- Misses          53       55       +2     
Impacted Files Coverage Δ
app/routers/event.py 96.55% <95.23%> (-0.34%) ⬇️
app/database/models.py 96.80% <100.00%> (+0.03%) ⬆️
app/internal/calendar_privacy.py 100.00% <100.00%> (ø)
app/internal/privacy.py 100.00% <100.00%> (ø)
app/routers/profile.py 92.79% <100.00%> (+0.06%) ⬆️
app/internal/statistics.py 100.00% <0.00%> (ø)

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 44563e8...29c5173. Read the comment docs.

Copy link
Member

@yammesicka yammesicka left a comment

Choose a reason for hiding this comment

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

Great job. We're about to finish working on this feature. DM me when you finish

@@ -1,86 +0,0 @@
<div class="form_row">
Copy link
Member

Choose a reason for hiding this comment

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

Did you removed this on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well yes.
I noticed the file was moved to templates/partials/calendar/event so I thought this was left over accidentally as it wasn't being loaded from anywhere.

@yammesicka yammesicka merged commit ad65015 into PythonFreeCourse:develop Feb 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants