def get_form_kwargs(self): kwargs = super(AclPatternCreate, self).get_form_kwargs() try: AclService.get_acl(id=self.get_obj_id()) kwargs['initial'] = {'acl_id': self.get_obj_id()} return kwargs except: raise Http404
def save(self): role_id = self.cleaned_data[ROLE_ID] places = self.cleaned_data[PLACES] for place in places: try: AclService.role_deny_place(role_id=role_id, place_id=place.id) except AclAlreadyAdded: continue
def get_form_kwargs(self): kwargs = super(AclPatternUpdate, self).get_form_kwargs() try: AclService.get_pattern(id=self.get_obj_id()) kwargs['pattern_id'] = self.get_obj_id() return kwargs except: raise Http404
def save(self): person_id = self.cleaned_data[PERSON_ID] places = self.cleaned_data[PLACES] for place in places: try: AclService.person_deny_place(person_id=person_id, place_id=place.id) except AclAlreadyAdded: continue
def get_object(self, queryset=None): if self.obj is None: try: self.obj = AclService.get_acl(id=self.kwargs[ID]) except: raise Http404 return self.obj
def get(self, request: HttpRequest, controller_id: str): controller_id = self.parse_int_pk(controller_id) resolved_acls = AclService.resolve_acls_by_controller(controller_id) acl_dtos = list([ ResolvedAclOutDto.from_values(a[0], a[1], a[2], a[3]) for a in resolved_acls ]) return ApiResponse.success(acl_dtos)
def save(self): pattern = AclService.update_pattern( pattern_id=self.cleaned_data['pattern_id'], from_time=self.cleaned_data['from_time'], until_time=self.cleaned_data['until_time'], days_of_week=self.cleaned_data['days_of_week'], days_of_month=self.cleaned_data['days_of_month'], months=self.cleaned_data['months']) return pattern
def post(self, request: HttpRequest, id: str, dto: SimplePatternInDto): id = self.parse_int_pk(id) pattern = AclService.create_pattern(id, dto.validated_data['from_time'], dto.validated_data['until_time'], dto.days_of_week, dto.days_of_month, dto.months) return ApiResponse.success( SimplePatternOutDto.from_simple_pattern(pattern))
def __init__(self, *args, **kwargs): pattern_id = kwargs.pop('pattern_id', None) super(ACLUpdateForm, self).__init__(*args, **kwargs) if pattern_id: pattern = AclService.get_pattern(id=pattern_id) self.fields['pattern_id'].initial = pattern_id self.fields['from_time'].initial = pattern.from_time self.fields['until_time'].initial = pattern.until_time self.fields['days_of_week'].initial = ast.literal_eval( pattern.days_of_week) self.fields['days_of_month'].initial = ast.literal_eval( pattern.days_of_month) self.fields['months'].initial = ast.literal_eval(pattern.months)
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
def get_object(self, queryset=None): return AclService.get_pattern(id=self.kwargs[ID])
def get_queryset(self): return AclService.get_patterns(acl_id=self.kwargs[ID])
def delete(self, request, *args, **kwargs): AclService.delete_acl(id=self.kwargs[ID]) return HttpResponseRedirect(self.get_success_url())
def get_queryset(self): return AclService.get_person_acls(person_id=self.get_obj_id())
def delete(self, request, *args, **kwargs): self.acl_id = self.get_object().acl_id AclService.delete_pattern(pattern_id=self.kwargs[ID]) return HttpResponseRedirect(self.get_success_url())
def get_object(self, queryset=None): if self.obj is None: self.obj = AclService.get_pattern(id=self.kwargs[ID]) return self.obj
def put(self, request: HttpRequest, person_id: str, place_id: str): person_id = self.parse_int_pk(person_id) place_id = self.parse_int_pk(place_id) acl = AclService.person_allow_place(person_id, place_id) return ApiResponse.success(PersonAclOutDto.from_person_acl(acl))
def delete(self, request: HttpRequest, id: str): id = self.parse_int_pk(id) AclService.delete_acl(id) return ApiResponse.success()
def delete(self, request: HttpRequest, pattern_id: str): pattern_id = self.parse_int_pk(pattern_id) AclService.delete_pattern(pattern_id) return ApiResponse.success()
def get(self, request: HttpRequest, id: str): id = self.parse_int_pk(id) patterns = AclService.get_patterns(id) pattern_dtos = list( [SimplePatternOutDto.from_simple_pattern(p) for p in patterns]) return ApiResponse.success(pattern_dtos)
def get_queryset(self): try: return AclService.get_role_acls(role_id=self.get_obj_id()) except: raise Http404
def get(self, request: HttpRequest, id: str): id = self.parse_int_pk(id) acls = AclService.get_person_acls(id) acl_dtos = list([PersonAclOutDto.from_person_acl(a) for a in acls]) return ApiResponse.success(acl_dtos)