diff --git a/apps/tmu/views.py b/apps/tmu/views.py index d58941f..bdbd4d6 100644 --- a/apps/tmu/views.py +++ b/apps/tmu/views.py @@ -1,3 +1,5 @@ +import requests + from rest_framework import status from rest_framework.authentication import TokenAuthentication from rest_framework.generics import get_object_or_404 @@ -26,6 +28,9 @@ def post(self, request): """ Create new ATIS (from vATIS). """ + # Forward request to SimTraffic so the data is replicated there + requests.post("https://api.simtraffic.net/vatis", data=request.data) + ATIS.objects.filter(facility=request.data.get("facility")).delete() serializer = ATISSerializer(data=request.data) if serializer.is_valid(): diff --git a/apps/users/management/commands/sync_vatusa_roster.py b/apps/users/management/commands/sync_vatusa_roster.py index 5b266a7..5933953 100644 --- a/apps/users/management/commands/sync_vatusa_roster.py +++ b/apps/users/management/commands/sync_vatusa_roster.py @@ -48,6 +48,46 @@ def sync_visit_roster(): ) +def sync_home_roster(): + home_roster = get_vatusa_roster() + + # Checks for users that do not exist on local roster. + for user in home_roster: + query = User.objects.filter(cid=user.get('cid')) + if not query.exists(): + User.objects.create_user( + cid=user.get('cid'), + email=user.get('email'), + first_name=user.get('fname'), + last_name=user.get('lname'), + rating=user.get('rating_short'), + ).set_membership('HC') + else: + user_obj = query.first() + user_obj.rating = user.get('rating_short') + user_obj.save() + user_obj.set_membership('HC') + + # Checks for users that were removed from VATUSA roster. + cids = [user.get('cid') for user in home_roster] + for user in User.objects.filter(roles__short='HC'): + if user.cid not in cids: + user.set_membership(None) + + +def sync_visit_roster(): + visit_roster = get_vatusa_roster('visit') + remote_cids = {user['cid'] for user in visit_roster} + + # Users that have been added to the local roster but not the VATUSA roster. + for local_cid in User.objects.filter(roles__short='VC').values_list('cid', flat=True): + if local_cid not in remote_cids: + requests.post( + f'https://api.vatusa.net/v2/facility/{os.getenv("FACILITY_IATA")}/roster/manageVisitor/{local_cid}/', + params={'apikey': os.getenv('VATUSA_API_TOKEN')}, + ) + + class Command(BaseCommand): help = "Pulls VATUSA roster for configured facility" # noqa: A003 diff --git a/apps/users/models.py b/apps/users/models.py index 282cfc8..b62b42a 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -241,6 +241,12 @@ def set_membership(self, short, override=True): params={"apikey": os.getenv("VATUSA_API_TOKEN")}, ) + if short == 'VC': + requests.post( + f'https://api.vatusa.net/v2/facility/{os.getenv("FACILITY_IATA")}/roster/manageVisitor/{self.cid}/', + params={'apikey': os.getenv('VATUSA_API_TOKEN')}, + ) + self.status = Status.ACTIVE self.save() diff --git a/emails/welcome_email.html b/emails/welcome_email.html index 59f077d..0d835df 100644 --- a/emails/welcome_email.html +++ b/emails/welcome_email.html @@ -29,21 +29,6 @@
Please join our Discord server by clicking this link or using the invite code 93225ukwrW.
-TeamSpeak is our primary voice communications platform. While on the network, all controllers must be in a TeamSpeak channel for coordination. TeamSpeak 3 can be downloaded at https://www.teamspeak.com/en.
-You can connect to our server by using the IP ts.zhuartcc.org. Use your full name as your nickname when you connect. Please do not share the server IP with anybody outside of the Houston ARTCC.
-