Beispiel #1
0
    def delete(self):
        try:
            fn = getattr(self.model, model_fn(self, 'delete'))
            task = fn(*self.model_args)
        except AttributeError:
            e = InvalidOperation(
                'WOKAPI0002E', {'resource': get_class_name(self)})
            raise cherrypy.HTTPError(405, str(e))

        cherrypy.response.status = 202

        # log request
        method = 'DELETE'
        code = self.getRequestMessage(method)
        reqParams = utf8_dict(self.log_args)
        log_id = log_request(
            code,
            reqParams,
            None,
            method,
            cherrypy.response.status,
            class_name=get_class_name(self),
        )
        save_request_log_id(log_id, task['id'])

        return wok.template.render('Task', task)
Beispiel #2
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            e = InvalidOperation(
                'WOKAPI0005E', {'resource': get_class_name(self)})
            raise cherrypy.HTTPError(405, str(e))

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        task = create(*args)
        cherrypy.response.status = 202

        # log request
        method = 'POST'
        code = self.getRequestMessage(method)
        reqParams = utf8_dict(self.log_args, params)
        log_id = log_request(
            code,
            reqParams,
            None,
            method,
            cherrypy.response.status,
            class_name=get_class_name(self),
        )
        save_request_log_id(log_id, task['id'])

        return wok.template.render('Task', task)
Beispiel #3
0
        def wrapper(*args, **kwargs):
            # status must be always set in order to request be logged.
            # use 500 as fallback for "exception not handled" cases.
            if protected is not None and protected:
                wokauth()

            details = None
            status = 500

            method = 'POST'
            validate_method(method, self.admin_methods)
            try:
                request = parse_request()
                validate_params(request, self, action_name)
                self.lookup()
                if not self.is_authorized():
                    raise UnauthorizedError('WOKAPI0009E')

                model_args = list(self.model_args)
                if action_args is not None:
                    model_args.extend(
                        request[key] if key in request.keys() else None
                        for key in action_args
                    )

                action_fn = getattr(self.model, model_fn(self, action_name))
                action_result = action_fn(*model_args)
                status = 200

                if destructive is False or (
                    'persistent' in self.info.keys(
                    ) and self.info['persistent'] is True
                ):
                    result = render_fn(self, action_result)
                    status = cherrypy.response.status

                    return result
            except WokException as e:
                details = e
                status = e.getHttpStatusCode()
                raise cherrypy.HTTPError(status, str(e))
            finally:
                # log request
                code = self.getRequestMessage(method, action_name)
                reqParams = utf8_dict(self.log_args, request)
                log_id = log_request(
                    code,
                    reqParams,
                    details,
                    method,
                    status,
                    class_name=get_class_name(self),
                    action_name=action_name,
                )
                if status == 202:
                    save_request_log_id(log_id, action_result['id'])
Beispiel #4
0
    def delete(self):
        try:
            fn = getattr(self.model, model_fn(self, 'delete'))
            task = fn(*self.model_args)
        except AttributeError:
            e = InvalidOperation('WOKAPI0002E', {'resource':
                                                 get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        cherrypy.response.status = 202

        # log request
        method = 'DELETE'
        code = self.getRequestMessage(method)
        reqParams = utf8_dict(self.log_args)
        log_id = log_request(code, reqParams, None, method,
                             cherrypy.response.status)
        save_request_log_id(log_id, task['id'])

        return wok.template.render("Task", task)
Beispiel #5
0
    def index(self, *args, **kwargs):
        # status must be always set in order to request be logged.
        # use 500 as fallback for "exception not handled" cases.
        details = None
        status = 500

        params = {}
        method = validate_method(('GET', 'POST'), self.admin_methods)

        try:
            if method == 'GET':
                params = cherrypy.request.params
                validate_params(params, self, 'get_list')
                return self.get(params)
            elif method == 'POST':
                params = parse_request()
                result = self.create(params, *args)
                status = cherrypy.response.status
                return result
        except WokException as e:
            details = e
            status = e.getHttpStatusCode()
            raise cherrypy.HTTPError(status, str(e))
        except cherrypy.HTTPError as e:
            status = e.status
            raise
        finally:
            if method not in LOG_DISABLED_METHODS and status != 202:
                # log request
                code = self.getRequestMessage(method)
                reqParams = utf8_dict(self.log_args, params)
                log_request(
                    code,
                    reqParams,
                    details,
                    method,
                    status,
                    class_name=get_class_name(self),
                )
Beispiel #6
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            e = InvalidOperation('WOKAPI0005E', {'resource':
                                                 get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        task = create(*args)
        cherrypy.response.status = 202

        # log request
        method = 'POST'
        code = self.getRequestMessage(method)
        reqParams = utf8_dict(self.log_args, params)
        log_id = log_request(code, reqParams, None, method,
                             cherrypy.response.status)
        save_request_log_id(log_id, task['id'])

        return wok.template.render("Task", task)
Beispiel #7
0
                if destructive is False or \
                    ('persistent' in self.info.keys() and
                     self.info['persistent'] is True):
                    result = render_fn(self, action_result)
                    status = cherrypy.response.status

                    return result
            except WokException, e:
                details = e
                status = e.getHttpStatusCode()
                raise cherrypy.HTTPError(status, e.message)
            finally:
                # log request
                code = self.getRequestMessage(method, action_name)
                reqParams = utf8_dict(self.log_args, request)
                log_id = log_request(code, reqParams, details, method, status)
                if status == 202:
                    save_request_log_id(log_id, action_result['id'])

        wrapper.__name__ = action_name
        wrapper.exposed = True
        return wrapper

    def lookup(self):
        try:
            lookup = getattr(self.model, model_fn(self, 'lookup'))
            self.info = lookup(*self.model_args)
        except AttributeError:
            self.info = {}