Exemplo n.º 1
0
 async def update_operation_link(self, operation_id: str, link_id: str,
                                 link_data: dict, access: BaseWorld.Access):
     operation = await self.get_operation_object(operation_id, access)
     link = self.search_operation_for_link(operation, link_id)
     if link.access not in access['access']:
         raise JsonHttpForbidden(
             f'Cannot update link {link_id} due to insufficient permissions.'
         )
     if link.is_finished() or link.can_ignore():
         raise JsonHttpForbidden(
             f'Cannot update a finished link: {link_id}')
     if link_data.get('command'):
         command_str = link_data.get('command')
         link.executor.command = command_str
         link.ability = self.build_ability(link_data.get('ability', {}),
                                           link.executor)
         link.command = self._encode_string(command_str)
     if link_data.get('status'):
         link_status = link_data['status']
         if not link.is_valid_status(link_status):
             raise JsonHttpBadRequest(
                 f'Cannot update link {link_id} due to invalid link status.'
             )
         link.status = link_status
     return link.display
Exemplo n.º 2
0
    async def create_or_update_object(self, request: web.Request):
        data, access, obj_id, query, search = await self._parse_common_data_from_request(request)

        matched_obj = self._api_manager.find_object(self.ram_key, query)
        if matched_obj and matched_obj.access not in access['access']:
            raise JsonHttpForbidden(f'Cannot update {self.description} due to insufficient permissions: {obj_id}')

        return self._api_manager.create_object_from_schema(self.schema, data, access)
Exemplo n.º 3
0
    async def update_main_config(self, request):
        data = await self.parse_json_body(request, schema=ConfigUpdateSchema())

        try:
            self._api_manager.update_main_config(prop=data['prop'],
                                                 value=data['value'])
        except ConfigUpdateNotAllowed as ex:
            raise JsonHttpForbidden(error='Update not allowed',
                                    details={'property': ex.property})

        return web.json_response(self._api_manager.get_filtered_config('main'))
Exemplo n.º 4
0
 async def get_operation_object(self, operation_id: str, access: dict):
     try:
         operation = (await self._data_svc.locate('operations',
                                                  {'id': operation_id}))[0]
     except IndexError:
         raise JsonHttpNotFound(f'Operation not found: {operation_id}')
     if operation.match(access):
         return operation
     raise JsonHttpForbidden(
         f'Cannot view operation due to insufficient permissions: {operation_id}'
     )
Exemplo n.º 5
0
    async def get_object(self, request: web.Request):
        data, access, obj_id, query, search = await self._parse_common_data_from_request(request)

        obj = self._api_manager.find_object(self.ram_key, query)
        if not obj:
            raise JsonHttpNotFound(f'{self.description.capitalize()} not found: {obj_id}')
        elif obj.access not in access['access']:
            raise JsonHttpForbidden(f'Cannot view {self.description} due to insufficient permissions: {obj_id}')

        include = request['querystring'].get('include')
        exclude = request['querystring'].get('exclude')

        return self._api_manager.dump_object_with_filters(obj, include, exclude)
Exemplo n.º 6
0
    async def create_or_update_on_disk_object(self, request: web.Request):
        data, access, obj_id, query, search = await self._parse_common_data_from_request(request)

        matched_obj = self._api_manager.find_object(self.ram_key, query)
        if not matched_obj:
            obj = await self._api_manager.create_on_disk_object(data, access, self.ram_key, self.id_property,
                                                                self.obj_class)
        else:
            if matched_obj.access in access['access']:
                obj = await self._api_manager.replace_on_disk_object(matched_obj, data, self.ram_key, self.id_property)
            else:
                raise JsonHttpForbidden(f'Cannot update {self.description} due to insufficient permissions: {obj_id}')

        return obj