Пример #1
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from bootstrap import application, manager

from web import models
from web.views.api.v1 import processors
from web.views.api.v1.common import url_prefix

blueprint_organization = manager.create_api_blueprint(
    models.Organization,
    url_prefix=url_prefix,
    methods=['GET', 'POST', 'PUT', 'DELETE'],
    preprocessors=dict(POST=[processors.auth_func],
                       PUT=[processors.auth_func],
                       DELETE=[processors.auth_func]))
Пример #2
0
# -*- coding: utf-8 -*-

from bootstrap import manager

from web import models
from web.views.api.v1 import processors
from web.views.api.v1.common import url_prefix


def pre_get_single(search_params=None, **kw):
    pass


def pre_get_many(search_params=None, **kw):
    filters = [
        dict(name='public_profile', op='eq', val=True),
        dict(name='is_api', op='eq', val=False)
    ]
    # Check if there are any filters there already.
    if 'filters' not in search_params:
        search_params['filters'] = []
    search_params['filters'].extend(filters)


blueprint_user = manager.create_api_blueprint(
    models.User,
    url_prefix=url_prefix,
    include_columns=['login'],
    methods=['GET'],
    preprocessors={'GET_MANY': [pre_get_many]})
Пример #3
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from bootstrap import application, manager

from web import models
from web.views.api.v1 import processors
from web.views.api.v1.common import url_prefix

blueprint_log = manager.create_api_blueprint(
    models.Log,
    url_prefix=url_prefix,
    methods=['GET'],
    preprocessors=dict(GET=[processors.auth_func],
                       GET_MANY=[processors.auth_func]))
Пример #4
0
        try:
            feed = FeedController(current_user.id).get(id=data["feed_id"])
        except NotFound:
            raise ProcessingException(description='No such feed.', code=404)
        self.is_authorized(current_user, feed)

        data["category_id"] = feed.category_id

    def delete_preprocessor(self, instance_id=None, **kw):
        try:
            article = ArticleController(current_user.id).get(id=instance_id)
        except NotFound:
            raise ProcessingException(description='No such article.', code=404)
        self.is_authorized(current_user, article)


article_processor = ArticleProcessor()

blueprint_article = manager.create_api_blueprint(
    models.Article,
    url_prefix=url_prefix,
    methods=['GET', 'POST', 'PUT', 'DELETE'],
    preprocessors=dict(
        GET_SINGLE=[auth_func, article_processor.get_single_preprocessor],
        GET_MANY=[auth_func, article_processor.get_many_preprocessor],
        POST=[auth_func, article_processor.post_preprocessor],
        PUT_SINGLE=[auth_func, article_processor.put_single_preprocessor],
        PUT_MANY=[auth_func, article_processor.put_many_preprocessor],
        DELETE=[auth_func, article_processor.delete_preprocessor]))
application.register_blueprint(blueprint_article)
Пример #5
0
            raise ProcessingException(description='No such feed.', code=404)
        self.is_authorized(current_user, feed)

        data["category_id"] = feed.category_id

    def delete_preprocessor(self, instance_id=None, **kw):
        try:
            article = ArticleController(current_user.id).get(id=instance_id)
        except NotFound:
            raise ProcessingException(description='No such article.', code=404)
        self.is_authorized(current_user, article)

article_processor = ArticleProcessor()

blueprint_article = manager.create_api_blueprint(models.Article,
        url_prefix=url_prefix,
        methods=['GET', 'POST', 'PUT', 'DELETE'],
        preprocessors=dict(GET_SINGLE=[auth_func,
                                    article_processor.get_single_preprocessor],
                            GET_MANY=[auth_func,
                                    article_processor.get_many_preprocessor],
                            POST=[auth_func,
                                    article_processor.post_preprocessor],
                            PUT_SINGLE=[auth_func,
                                    article_processor.put_single_preprocessor],
                            PUT_MANY=[auth_func,
                                    article_processor.put_many_preprocessor],
                            DELETE=[auth_func,
                                    article_processor.delete_preprocessor]))
application.register_blueprint(blueprint_article)
Пример #6
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from bootstrap import manager

from web import models
from web.views.api.v1 import processors
from web.views.api.v1.common import url_prefix

blueprint_tag = manager.create_api_blueprint(models.Tag,
                                             url_prefix=url_prefix,
                                             methods=['GET'])
Пример #7
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from bootstrap import manager

from web import models
from web.views.api.v1 import processors
from web.views.api.v1.common import url_prefix

blueprint_release = manager.create_api_blueprint(models.Release,
                                                 url_prefix=url_prefix,
                                                 methods=['GET'])
Пример #8
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from bootstrap import manager

from web import models
from web.views.api.v1 import processors
from web.views.api.v1.common import url_prefix

blueprint_cve = manager.create_api_blueprint(models.CVE,
                                             url_prefix=url_prefix,
                                             methods=['GET'])
Пример #9
0
Файл: feed.py Проект: JARR/JARR
from flask_login import current_user
from web import models
from bootstrap import application, manager
from web.controllers import FeedController
from web.views.api.v3.common import AbstractProcessor
from web.views.api.v3.common import url_prefix, auth_func

class FeedProcessor(AbstractProcessor):
    """Concrete processors for the Feed Web service.
    """

    def get_single_preprocessor(self, instance_id=None, **kw):
        # Check if the user is authorized to modify the specified
        # instance of the model.
        feed = FeedController(current_user.id).get(id=instance_id)
        self.is_authorized(current_user, feed)

feed_processor = FeedProcessor()

blueprint_feed = manager.create_api_blueprint(models.Feed,
        url_prefix=url_prefix,
        methods=['GET', 'POST', 'PUT', 'DELETE'],
        preprocessors=dict(GET_SINGLE=[auth_func,
                                    feed_processor.get_single_preprocessor],
                           GET_MANY=[auth_func,
                                    feed_processor.get_many_preprocessor],
                           PUT_SINGLE=[auth_func],
                           POST=[auth_func],
                           DELETE=[auth_func]))
application.register_blueprint(blueprint_feed)
Пример #10
0
from web import models
from bootstrap import application, manager
from web.controllers import FeedController
from web.views.api.v3.common import AbstractProcessor
from web.views.api.v3.common import url_prefix, auth_func


class FeedProcessor(AbstractProcessor):
    """Concrete processors for the Feed Web service.
    """
    def get_single_preprocessor(self, instance_id=None, **kw):
        # Check if the user is authorized to modify the specified
        # instance of the model.
        feed = FeedController(current_user.id).get(id=instance_id)
        self.is_authorized(current_user, feed)


feed_processor = FeedProcessor()

blueprint_feed = manager.create_api_blueprint(
    models.Feed,
    url_prefix=url_prefix,
    methods=['GET', 'POST', 'PUT', 'DELETE'],
    preprocessors=dict(
        GET_SINGLE=[auth_func, feed_processor.get_single_preprocessor],
        GET_MANY=[auth_func, feed_processor.get_many_preprocessor],
        PUT_SINGLE=[auth_func],
        POST=[auth_func],
        DELETE=[auth_func]))
application.register_blueprint(blueprint_feed)
Пример #11
0
#
#
# ***** END LICENSE BLOCK *****

from bootstrap import app, manager

from web import models
from web import processors


# 'User' Web service
blueprint_user = manager.create_api_blueprint(models.User,
                    exclude_columns=['pwdhash'],
                    methods=['GET', 'POST', 'PUT', 'DELETE'],
                    preprocessors=dict(
                            GET_SINGLE=[processors.auth_func],
                            GET_MANY=[processors.auth_func],
                            POST=[processors.auth_func,
                                processors.shelter_POST_preprocessor],
                            DELETE=[processors.auth_func]))


# 'Shelter' Web service
blueprint_shelter = manager.create_api_blueprint(models.Shelter,
                    exclude_columns=['user_id', 'responsible.pwdhash',
                                    'responsible.email'],
                    methods=['GET', 'POST', 'PUT', 'DELETE'],
                    preprocessors=dict(
                            POST=[processors.auth_func,
                                processors.shelter_POST_preprocessor],
                            DELETE=[processors.auth_func]))
Пример #12
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from bootstrap import application, manager

from web import models
from web.views.api.v1 import processors
from web.views.api.v1.common import url_prefix

blueprint_project = manager.create_api_blueprint(
    models.Project,
    url_prefix=url_prefix,
    methods=['GET', 'POST', 'PUT', 'DELETE'],
    exclude_columns=['requests', 'notification_email'],
    preprocessors=dict(POST=[processors.auth_func],
                       PUT=[processors.auth_func],
                       DELETE=[processors.auth_func]))
Пример #13
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from bootstrap import application, manager

from web import models
from web.views.api.v1 import processors
from web.views.api.v1.common import url_prefix

blueprint_request = manager.create_api_blueprint(
    models.Request,
    url_prefix=url_prefix,
    methods=['POST'],
    preprocessors={'POST': [processors.post_preprocessor]},
    postprocessors={'POST': [processors.post_postprocessor]})
Пример #14
0
#
#
# ***** END LICENSE BLOCK *****

from bootstrap import app, manager

from web import models
from web import processors


# 'User' Web service
blueprint_user = manager.create_api_blueprint(models.User,
                    exclude_columns=['pwdhash'],
                    methods=['GET', 'POST', 'PUT', 'DELETE'],
                    preprocessors=dict(
                            GET_SINGLE=[processors.auth_func],
                            GET_MANY=[processors.auth_func],
                            POST=[processors.auth_func,
                                processors.shelter_POST_preprocessor],
                            DELETE=[processors.auth_func]))


# 'Shelter' Web service
blueprint_shelter = manager.create_api_blueprint(models.Shelter,
                    exclude_columns=['user_id', 'responsible.pwdhash',
                                    'responsible.email'],
                    methods=['GET', 'POST', 'PUT', 'DELETE'],
                    preprocessors=dict(
                            POST=[processors.auth_func,
                                processors.shelter_POST_preprocessor],
                            DELETE=[processors.auth_func]))