|
@@ -1,16 +1,23 @@
|
|
|
from rest_framework import serializers
|
|
|
-from metaservicesynced.models import Orders
|
|
|
+from metaservicesynced.models import Orders, Client
|
|
|
+from metaservicesynced.ejabber import *
|
|
|
from tickets.models import Task, TaskList
|
|
|
+from core.config import DEBUG, WEBSERVICE_NAME, EJ_HOST, EJ_SERVICE
|
|
|
import traceback
|
|
|
+import requests
|
|
|
+
|
|
|
|
|
|
class OrdersSerializer(serializers.ModelSerializer):
|
|
|
class Meta:
|
|
|
model = Orders
|
|
|
fields = '__all__'
|
|
|
|
|
|
+
|
|
|
def create(self, validated_data):
|
|
|
ModelClass = self.Meta.model
|
|
|
|
|
|
+
|
|
|
+
|
|
|
if "ticket" not in validated_data:
|
|
|
# Create ticket with minimal required data
|
|
|
task_data = {
|
|
@@ -50,5 +57,63 @@ class OrdersSerializer(serializers.ModelSerializer):
|
|
|
)
|
|
|
)
|
|
|
raise TypeError(msg)
|
|
|
-
|
|
|
+ else:
|
|
|
+ if DEBUG: print("[CREATING EJABBER ROOMS]")
|
|
|
+ # Get neccessary data
|
|
|
+ order_num = instance.pk
|
|
|
+ support = pick_support()
|
|
|
+ client = instance.client_id.user.phone_number
|
|
|
+ provider = instance.provider.user_id.phone_number
|
|
|
+
|
|
|
+ for room_name, room_members in get_rooms(WEBSERVICE_NAME, order_num, support, client, provider).items():
|
|
|
+ # Create ejabber rooms
|
|
|
+ data = {
|
|
|
+ "name": room_name,
|
|
|
+ "service": EJ_SERVICE,
|
|
|
+ "host": EJ_HOST,
|
|
|
+ }
|
|
|
+ res = ej_execute("create_room", data)
|
|
|
+ if DEBUG: print(f"[RESPONSE CREATED]: {res.json()}")
|
|
|
+ if DEBUG: print(f"[ROOM]: {room_name}")
|
|
|
+
|
|
|
+ # Set rooms to members_only
|
|
|
+ data = {
|
|
|
+ "name": room_name,
|
|
|
+ "service": EJ_SERVICE,
|
|
|
+ "option": "members_only",
|
|
|
+ "value": "true"
|
|
|
+ }
|
|
|
+ res = ej_execute("change_room_option", data)
|
|
|
+ if DEBUG: print(f"[SET ROOM TO MEMBERS ONLY]: {res.json()}")
|
|
|
+
|
|
|
+ """
|
|
|
+ Add members to the room
|
|
|
+
|
|
|
+ member_account is a dict that contains members credentials
|
|
|
+ Key - the same thing that is in room_members
|
|
|
+ Value - tuple (jid, ejabber affiliation).
|
|
|
+ Affiliation can be one of: owner, admin, member, outcast, none.
|
|
|
+ owner > admin
|
|
|
+ """
|
|
|
+ members_accounts = {
|
|
|
+ "owner": ("sports_backend@" + EJ_HOST, "owner"),
|
|
|
+ "client": (client, "member"),
|
|
|
+ "support": (support, "member"),
|
|
|
+ "provider": (provider, "member"),
|
|
|
+ }
|
|
|
+ data = {
|
|
|
+ "name": room_name,
|
|
|
+ "service": EJ_SERVICE,
|
|
|
+ "jid": "sports_backend@" + EJ_HOST,
|
|
|
+ "affiliation": "owner"
|
|
|
+ }
|
|
|
+ #
|
|
|
+ # REQUIRES TO BE TESTED, RESULTS OF THIS WERE NOT CONFIRMED TO BE CORRECT
|
|
|
+ #
|
|
|
+ # Add all neccessary member to the room
|
|
|
+ for member in room_members:
|
|
|
+ data["jid"] = members_accounts[member][0]
|
|
|
+ data["affiliation"] = members_accounts[member][1]
|
|
|
+ res = ej_execute("set_room_affiliation", data)
|
|
|
+ if DEBUG: print(f"[ADDED USER]: {res.json()}")
|
|
|
return instance
|