def get_table() -> Table:
     persons = PersonService.get_all()
     data = []
     for person in persons:
         data.append({
             'person': person,
             'keys': PersonService.get_keys(id=person.id),
             'roles': PersonService.get_roles(id=person.id)
         })
     return PersonHomePageTable(data=data)
def create(name: str, access_key: str, person_id: int) -> Key:
    person = PersonService.get(person_id)
    try:
        return Key.objects.create(name=name,
                                  access_key=access_key,
                                  person=person)
    except:
        raise exceptions.KeyManageFailed
 def get_context_data(self, **kwargs):
     context = super(Home, self).get_context_data(**kwargs)
     context['table'] = self.get_table()
     context['person_count'] = PersonService.get_all().count()
     context['keys_count'] = KeyService.get_all().count()
     context['roles_count'] = RoleService.get_all().count()
     context['places_count'] = PlaceService.get_all().count()
     return context
Beispiel #4
0
    def __init__(self, *args, **kwargs):
        person_id = kwargs.pop('person_id', None)
        super(RoleDetachForm, self).__init__(*args, **kwargs)

        if person_id:
            self.fields['person_id'].initial = person_id
            roles = PersonService.get_roles(id=person_id)
            self.fields['roles'].queryset = roles
        self.fields['roles'].empty_label = None
def person_allow_place(person_id: int, place_id: int) -> PersonACLEntry:
    person = PersonService.get(person_id)
    place = PlaceService.get(place_id)
    if PersonACLEntry.objects.filter(
            person=person, place=place, type=AclType.ACL_ALLOW).count() > 0:
        raise exceptions.AclAlreadyAdded
    try:
        return PersonACLEntry.objects.create(person=person,
                                             place=place,
                                             type=AclType.ACL_ALLOW)
    except:
        raise exceptions.ACLManageFailed
Beispiel #6
0
class KeyCreateForm(forms.ModelForm):
    name = forms.CharField(widget=TextInput, help_text='Key name')
    access_key = forms.CharField(widget=TextInput, help_text='Access key')
    person = forms.ModelChoiceField(queryset=PersonService.get_all(),
                                    help_text='Choose person for key',
                                    empty_label='Choose person',
                                    widget=forms.Select)

    class Meta:
        model = Key
        fields = ['name', 'access_key', 'person']

    def save(self, commit=True):
        key = KeyService.create(name=self.cleaned_data['name'],
                                access_key=self.cleaned_data['access_key'],
                                person_id=self.cleaned_data['person'].id)
        return key
def update(id: int,
           name: str = None,
           access_key: str = None,
           person_id: int = None) -> Key:
    key = get(id)
    if name is not None:
        key.name = name
    if access_key is not None:
        key.access_key = access_key
    if person_id is not None:
        person = PersonService.get(person_id)
        key.person = person
    try:
        key.save()
        return key
    except:
        raise exceptions.KeyManageFailed
class PersonMultipleChoiceForm(forms.Form):
    role_id = forms.IntegerField(widget=forms.HiddenInput)
    persons = forms.ModelMultipleChoiceField(queryset=PersonService.get_none(),
                                             widget=CheckboxSelectMultiple)
Beispiel #9
0
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     roles = PersonService.get_roles(id)
     key_dtos = list([RoleOutDto.from_role(r) for r in roles])
     return ApiResponse.success(key_dtos)
Beispiel #10
0
 def delete(self, request: HttpRequest, person_id: str, role_id: str):
     person_id = self.parse_int_pk(person_id)
     role_id = self.parse_int_pk(role_id)
     PersonService.detach_role(person_id, role_id)
     return ApiResponse.success()
Beispiel #11
0
 def delete(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     PersonService.delete(id)
     return ApiResponse.success()
Beispiel #12
0
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     keys = PersonService.get_keys(id)
     key_dtos = list([KeyOutDto.from_key(k) for k in keys])
     return ApiResponse.success(key_dtos)
Beispiel #13
0
 def get(self, request: HttpRequest, id: str):
     id = self.parse_int_pk(id)
     person = PersonService.get(id)
     return ApiResponse.success(PersonOutDto.from_person(person))
 def save(self):
     role_id = self.cleaned_data[ROLE_ID]
     persons = self.cleaned_data[PERSONS]
     for person in persons:
         PersonService.detach_role(person_id=person.id, role_id=role_id)
 def save(self, commit=True):
     person = PersonService.create(name=self.cleaned_data[NAME])
     return person
Beispiel #16
0
 def post(self, request: HttpRequest, dto: PersonInDto):
     person = PersonService.create(dto.name)
     return ApiResponse.success(PersonOutDto.from_person(person))
Beispiel #17
0
 def get_queryset(self):
     try:
         return PersonService.get_roles(id=self.get_obj_id())
     except:
         raise Http404("Roles does not exist")
Beispiel #18
0
 def get_queryset(self):
     try:
         return PersonService.get_keys(id=self.get_obj_id())
     except:
         raise Http404("Person not exist")
Beispiel #19
0
 def save(self):
     person_id = self.cleaned_data['person_id']
     roles = self.cleaned_data['roles']
     for role in roles:
         PersonService.detach_role(person_id=person_id, role_id=role.id)
 def save(self, commit=True):
     person = PersonService.update(id=self.cleaned_data[ID],
                                   name=self.cleaned_data[NAME])
     return person
Beispiel #21
0
 def put(self, request: HttpRequest, id: str, dto: PersonInDto):
     id = self.parse_int_pk(id)
     person = PersonService.update(id, dto.name)
     return ApiResponse.success(PersonOutDto.from_person(person))
Beispiel #22
0
 def get(self, request: HttpRequest):
     personnel = PersonService.get_all()
     person_dtos = list([PersonOutDto.from_person(p) for p in personnel])
     return ApiResponse.success(person_dtos)
def get_person_acls(person_id: int) -> List[PersonACLEntry]:
    person = PersonService.get(person_id)
    try:
        return list(person.personaclentry_set.all())
    except:
        raise exceptions.SomethingWrong