Ejemplo n.º 1
0
 def save(self):
     if self.cleaned_data[PLACE_ID]:
         place_id = self.cleaned_data[PLACE_ID]
         doors = self.cleaned_data[DOORS]
         for door in doors:
             PlaceService.detach_door(place_id=place_id, door_id=door.id)
     if self.cleaned_data[CONTROLLER_ID]:
         controller_id = self.cleaned_data[CONTROLLER_ID]
         doors = self.cleaned_data[DOORS]
         for door in doors:
             ControllerService.detach_door(controller_id=controller_id, door_id=door.id)
 def put(self, request: HttpRequest, id: str, dto: ControllerInDto):
     id = self.parse_int_pk(id)
     controller = ControllerService.update(id,
                                           name=dto.name,
                                           controller_id=dto.controller_id)
     return ApiResponse.success(
         ControllerOutDto.from_controller(controller))
Ejemplo n.º 3
0
def resolve_acls_by_controller(
    controller_id: str
) -> List[Tuple[AclType, Key, Door, SimpleRecurringPattern]]:
    controller = ControllerService.get_by_controller_id(controller_id)
    role_acls = list(
        RoleACLEntry.objects.filter(place__doors__controller=controller))
    person_acls = list(
        PersonACLEntry.objects.filter(place__doors__controller=controller))
    result = list()
    for acl in role_acls:
        doors = list(acl.place.doors.filter(controller=controller))
        patterns = list(acl.simplerecurringpattern_set.all())
        for person in acl.role.person_set.all():
            for key in person.key_set.all():
                for door in doors:
                    for pattern in patterns:
                        result.append((acl.type, key, door, pattern))
    for acl in person_acls:
        doors = list(acl.place.doors.filter(controller=controller))
        patterns = list(acl.simplerecurringpattern_set.all())
        for key in acl.person.key_set.all():
            for door in doors:
                for pattern in patterns:
                    result.append((acl.type, key, door, pattern))
    return result
Ejemplo n.º 4
0
 def save(self, commit=True):
     controller = ControllerService.update(
         id=self.cleaned_data['id'],
         name=self.cleaned_data['name'],
         controller_id=self.cleaned_data['controller_id']
     )
     return controller
Ejemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        controller_id = kwargs.pop(CONTROLLER_ID, None)
        super(DoorDetachControllerForm, self).__init__(*args, **kwargs)

        if controller_id:
            self.fields[CONTROLLER_ID] = forms.IntegerField(widget=forms.HiddenInput, initial=controller_id)
            doors = ControllerService.get_doors(id=controller_id)
            self.fields[DOORS].queryset = doors
        self.fields[DOORS].empty_label = None
Ejemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        controller_id = kwargs.pop(CONTROLLER_ID, None)
        super(DoorAttachToControllerForm, self).__init__(*args, **kwargs)

        if controller_id:
            self.fields[CONTROLLER_ID].initial = controller_id
            doors = ControllerService.get_untouched_doors(id=controller_id)
            self.fields[DOORS].queryset = doors
        self.fields[DOORS].empty_label = None
Ejemplo n.º 7
0
 def delete(self, request: HttpRequest, controller_id: str, door_id: str):
     controller_id = self.parse_int_pk(controller_id)
     door_id = self.parse_int_pk(door_id)
     ControllerService.detach_door(controller_id, door_id)
     return ApiResponse.success()
Ejemplo n.º 8
0
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     doors = ControllerService.get_doors(id)
     door_dtos = list([DoorOutDto.from_door(d) for d in doors])
     return ApiResponse.success(door_dtos)
Ejemplo n.º 9
0
 def delete(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     ControllerService.delete(id)
     return ApiResponse.success()
Ejemplo n.º 10
0
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     controller = ControllerService.get(id)
     return ApiResponse.success(ControllerOutDto.from_controller(controller))
Ejemplo n.º 11
0
 def post(self, request: HttpRequest, dto: ControllerInDto):
     controller = ControllerService.create(dto.name, dto.controller_id)
     return ApiResponse.success(ControllerOutDto.from_controller(controller))
Ejemplo n.º 12
0
 def get(self, request: HttpRequest):
     controllers = ControllerService.get_all()
     controller_dtos = list([ControllerOutDto.from_controller(c) for c in controllers])
     return ApiResponse.success(controller_dtos)
Ejemplo n.º 13
0
 def get_queryset(self):
     try:
         return ControllerService.get_doors(id=self.get_obj_id())
     except:
         raise Http404
Ejemplo n.º 14
0
 def get_queryset(self):
     if self.queryset is None:
         controller = ControllerService.get(id=self.get_obj_id())
         self.queryset = AclService.resolve_acls_by_controller(
             controller_id=controller.controller_id)
     return self.queryset
Ejemplo n.º 15
0
class ControllerMultipleChoiceForm(forms.Form):
    controllers = forms.ModelMultipleChoiceField(queryset=ControllerService.get_none(), widget=CheckboxSelectMultiple)
    door_id = forms.IntegerField(widget=forms.HiddenInput)
Ejemplo n.º 16
0
 def save(self):
     controllers = self.cleaned_data['controllers']
     door_id = self.cleaned_data['door_id']
     for controller in controllers:
         ControllerService.detach_door(controller_id=controller.id, door_id=door_id)
Ejemplo n.º 17
0
 def save(self):
     controller_id = self.cleaned_data[CONTROLLER_ID]
     doors = self.cleaned_data[DOORS]
     for door in doors:
         ControllerService.attach_door(controller_id=controller_id, door_id=door.id)