blob: 79c01127461e9709d52e4d80e819deba1a785b71 [file] [log] [blame]
Scott Bakeraf599eb2017-03-21 12:43:26 -07001from synchronizers.new_base.modelaccessor import *
Scott Baker46a3ee92017-05-30 16:44:56 -07002from synchronizers.new_base.policy import Policy
Scott Bakerb63ea792016-08-11 10:24:48 -07003
Scott Baker46a3ee92017-05-30 16:44:56 -07004class UserPolicy(Policy):
5 model_name = "User"
6
7 def handle_create(self, user):
8 return self.handle_update(user)
9
10 def handle_update(self, user):
11 controller_users = ControllerUser.objects.filter(user_id=user.id)
12 existing_controllers = [cu.controller for cu in controller_users]
13 existing_controller_ids = [c.id for c in existing_controllers]
14 all_controllers = Controller.objects.all()
15 for controller in all_controllers:
16 if controller.id not in existing_controller_ids:
17 ctrl_user = ControllerUser(controller=controller, user=user)
18 ctrl_user.save()
Scott Bakerb63ea792016-08-11 10:24:48 -070019