Skip to content

Commit

Permalink
🔨 Set trailing slash for CalDAV urls only on runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
devmount committed May 28, 2024
1 parent ed625ff commit 382cc8a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
5 changes: 3 additions & 2 deletions backend/src/appointment/controller/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,11 @@ def __init__(self, subscriber_id: int, calendar_id: int, redis_instance, url: st
super().__init__(subscriber_id, calendar_id, redis_instance)

self.provider = CalendarProvider.caldav
self.url = url
self.url = url if url[-1] == '/' else url + '/'
self.password = password
self.user = user
# connect to CalDAV server

# connect to the CalDAV server
self.client = DAVClient(url=url, username=user, password=password)

def test_connection(self) -> bool:
Expand Down
8 changes: 0 additions & 8 deletions backend/src/appointment/routes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ def create_my_calendar(
google_tkn=external_connection.token,
)
else:
# make sure, the CalDAV url has a trailing slash
if calendar.url[-1] != '/':
calendar.url += '/'

con = CalDavConnector(
redis_instance=None,
url=calendar.url,
Expand Down Expand Up @@ -194,10 +190,6 @@ def update_my_calendar(
if not repo.calendar.is_owned(db, calendar_id=id, subscriber_id=subscriber.id):
raise validation.CalendarNotAuthorizedException()

# make sure, the CalDAV url has a trailing slash
if calendar.provider == CalendarProvider.caldav and calendar.url[-1] != '/':
calendar.url += '/'

cal = repo.calendar.update(db=db, calendar=calendar, calendar_id=id)
return schemas.CalendarOut(id=cal.id, title=cal.title, color=cal.color, connected=cal.connected)

Expand Down
4 changes: 2 additions & 2 deletions backend/test/integration/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def test_update_existing_caldav_calendar_with_password(self, with_client, with_d
with with_db() as db:
cal = db.scalars(query).one()

assert cal.url == os.getenv("CALDAV_TEST_CALENDAR_URL") + "x/"
assert cal.url == os.getenv("CALDAV_TEST_CALENDAR_URL") + "x"
assert cal.user == os.getenv("CALDAV_TEST_USER") + "x"
assert cal.password == os.getenv("CALDAV_TEST_PASS") + "x"

Expand Down Expand Up @@ -394,6 +394,6 @@ def test_update_existing_caldav_calendar_without_password(self, with_client, wit
with with_db() as db:
cal = db.scalars(query).one()

assert cal.url == os.getenv("CALDAV_TEST_CALENDAR_URL") + "/"
assert cal.url == os.getenv("CALDAV_TEST_CALENDAR_URL")
assert cal.user == os.getenv("CALDAV_TEST_USER")
assert cal.password == ''

0 comments on commit 382cc8a

Please sign in to comment.