-
Notifications
You must be signed in to change notification settings - Fork 52
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
Feature/public event #287
base: develop
Are you sure you want to change the base?
Feature/public event #287
Changes from 14 commits
5ef6469
885a843
1f4b084
8e0d1ee
5a8adeb
59532d6
235c4b2
d32ca25
ef0f679
c6477a5
b7cc686
540f1bf
49ac8e7
e111110
573cd2b
847eb09
b9d6016
e715f4c
14fc7e2
f515361
e4f2ee0
9ffa3ea
e8571f1
05c90a1
71ee772
9cf15b1
70be019
1bc712c
f371ce1
05310b7
c02ffd0
8a58f78
b6ff758
093881b
7b4ee13
986b43b
cf5b771
76db81a
9bbed18
94c4a32
b08636e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ | |
|
||
from app.config import (CALENDAR_HOME_PAGE, CALENDAR_REGISTRATION_PAGE, | ||
CALENDAR_SITE_NAME, email_conf, templates) | ||
from app.database.models import Event, User | ||
|
||
from app.database.models import Event, User, UserEvent | ||
from app.internal.utils import get_current_user | ||
noam-y marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use Kobi's user system instead |
||
mail = FastMail(email_conf) | ||
|
||
|
||
|
@@ -52,6 +52,49 @@ def send( | |
return True | ||
|
||
|
||
def send_email_to_event_participants( | ||
yammesicka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
session: Session, event_id: int, | ||
title: str, content: str, | ||
background_tasks: BackgroundTasks = BackgroundTasks | ||
) -> bool: | ||
"""This function is being used to send emails in the background. | ||
it uses the main elements of the func writen above. | ||
It takes an event and a user and it sends the event to the user. | ||
Args: | ||
session(Session): The session to redirect to the database. | ||
title (str): Title of the email that is being sent. | ||
event_id (int): Id number of the event that is used. | ||
content (str): body of email sent. | ||
background_tasks (BackgroundTasks): Function from fastapi that lets | ||
you apply tasks in the background. | ||
Returns: | ||
bool: Returns True if emails were sent, False if none. | ||
""" | ||
event_owner = session.query(Event.owner).filter(id == event_id).first() | ||
if event_owner != get_current_user(session): | ||
return False | ||
# makes sure only event owner can send an email via this func. | ||
mailing_list = session.query(User.email).join( | ||
UserEvent, User.id == UserEvent.user_id | ||
).filter( | ||
event_id == event_id).all() | ||
valid_mailing_list = list(filter(verify_email_pattern, mailing_list)) | ||
if not valid_mailing_list: | ||
return False | ||
# making sure app doesn't crash if emails are invalid | ||
event = session.query(Event).get(event_id) | ||
subject = f"{event.title}: {title}" | ||
recipients = valid_mailing_list | ||
body = content | ||
for r in recipients: | ||
print(r) | ||
noam-y marked this conversation as resolved.
Show resolved
Hide resolved
|
||
background_tasks.add_task(send_internal, | ||
subject=subject, | ||
recipients=r, | ||
body=body) | ||
return True | ||
|
||
|
||
def send_email_invitation(sender_name: str, | ||
recipient_name: str, | ||
recipient_mail: str, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
from app.dependencies import get_db | ||
from app.internal.utils import delete_instance | ||
from app.main import app | ||
from app.routers.event import add_new_event, add_user_to_event | ||
from app.routers.user import create_user | ||
from app.routers import event as evt | ||
|
||
|
||
|
@@ -99,6 +101,46 @@ | |
] | ||
|
||
|
||
# ------------------------------------------------- | ||
# fixtures | ||
# ------------------------------------------------- | ||
|
||
|
||
@pytest.fixture | ||
def new_event(session, new_user): | ||
event = add_new_event(TestApp.event_test_data, session) | ||
return event | ||
|
||
|
||
@pytest.fixture | ||
def new_user(session): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe you can use existing fixtures? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried but didn't really find a proper user fixture inside the file. ill try going over the code again There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are enough user fixtures, use one of the others. |
||
user = create_user( | ||
session=session, | ||
username='new_test_username', | ||
password='new_test_password', | ||
email='[email protected]', | ||
language_id='english' | ||
) | ||
|
||
return user | ||
|
||
|
||
# ------------------------------------------------- | ||
# tests | ||
# ------------------------------------------------- | ||
|
||
|
||
def test_joining_public_event(session, new_event, new_user): | ||
"""test in order to make sure user is added the first time | ||
he asks to join event, yet won't join the same user twice""" | ||
first_join = add_user_to_event( | ||
session, event_id=new_event.id, user_id=new_user.id) | ||
assert first_join | ||
second_join = add_user_to_event( | ||
session, event_id=new_event.id, user_id=new_user.id) | ||
assert not second_join | ||
|
||
|
||
def test_eventedit(event_test_client): | ||
response = event_test_client.get("/event/edit") | ||
assert response.ok | ||
|
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.
Event doesn't have "friends" option?
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 meaning of friends is different- public event is meant to allow any user in the platform to join the event, just like the public events on facebook. so it means the owner's friends don't matter in this feature :)
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.
Can you please explain what is the meaning of public/private event? is it like busy/free?
Thanks
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.
a pubic event is event anyone can join. it means you don't need to be invited directly from the owner, you can join the event by yourself by clicking a button on event page