Skip to content

Commit 85f4449

Browse files
EmmanuelSagekoitoror
authored andcommitted
CON-281-bug(activity-page): fix activity page query
- Add filtering events by current user location - Add super admin priviledge to view all locations [Delivers CON-281]
1 parent 736634a commit 85f4449

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

api/events/schema.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
filter_events_by_date_range,
1818
validate_page_and_per_page
1919
)
20+
from helpers.auth.user_details import get_user_from_db
2021

2122
utc = pytz.utc
2223

@@ -257,10 +258,14 @@ def resolve_all_events(self, info, **kwargs):
257258
page = kwargs.get('page')
258259
per_page = kwargs.get('per_page')
259260
page, per_page = validate_page_and_per_page(page, per_page)
261+
260262
query = Events.get_query(info)
261263
response = filter_events_by_date_range(
262264
query, start_date, end_date
263265
)
266+
user = get_user_from_db()
267+
response = CalendarEvents().get_events_in_location(
268+
user, response)
264269
response.sort(
265270
key=lambda x: parser.parse(x.start_time).astimezone(utc),
266271
reverse=True)

helpers/calendar/events.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from api.room.models import Room as RoomModel
1111
from .analytics_helper import CommonAnalytics
1212
from .credentials import Credentials, get_google_calendar_events
13+
from api.location.models import Location as LocationModel
14+
from api.role.models import Role as RoleModel
1315

1416

1517
class RoomSchedules(Credentials):
@@ -214,3 +216,25 @@ def sync_all_events(self):
214216
rooms = RoomModel.query.filter_by(state='active')
215217
for room in rooms:
216218
self.sync_single_room_events(room)
219+
220+
def get_events_in_location(self, user, events):
221+
"""
222+
This method matches the current_user's location with the events
223+
in that location and filters to return the events for that location
224+
but returns all locations for a user with super admin role
225+
"""
226+
events_in_location = []
227+
228+
admin_role = RoleModel.query.filter_by(
229+
id=user.roles[0].id).first()
230+
if admin_role.role == 'Super Admin':
231+
return events
232+
233+
location = LocationModel.query.filter_by(
234+
name=user.location).first()
235+
for event in events:
236+
room = RoomModel.query.filter_by(
237+
calendar_id=event.room.calendar_id).first()
238+
if room.location_id == location.id:
239+
events_in_location.append(event)
240+
return events_in_location

0 commit comments

Comments
 (0)