Ejemplo n.º 1
0
from flask_restless.views import ValidationError

from app import api_manager, app
from src.main.dto.flagged_user import exclude_columns
from src.main.http.cros_headers import add_cors_headers
from src.main.model.flagged_user import FlaggedUser as FlaggedUserModel
from src.main.security.authorization import role_admin, role_police_officer
from src.main.security.authentication import auth_func
from src.main.service.flagged_user import flagged_user_count

# Flagged API object
flagged_user_api = api_manager.create_api_blueprint(
    FlaggedUserModel,
    collection_name='flagged-user',
    methods=['GET', 'POST'],
    exclude_columns=exclude_columns(),
    validation_exceptions=[ValidationError],
    allow_functions=True,
    preprocessors=dict(GET_SINGLE=[auth_func, role_admin],
                       GET_MANY=[auth_func, role_admin],
                       POST=[auth_func, role_police_officer],
                       PUT_SINGLE=[auth_func, role_admin]),
    postprocessors=dict(POST=[flagged_user_count]))

flagged_user_api.after_request(add_cors_headers)
app.register_blueprint(flagged_user_api)
Ejemplo n.º 2
0
from flask_restless.views import ValidationError

from app import api_manager, app
from src.main.dto.project_category import exclude_columns
from src.main.http.cros_headers import add_cors_headers
from src.main.security.authentication import auth_func
from src.main.model.project_category import ProjectCategory

project_category_api = api_manager.create_api_blueprint(
    ProjectCategory,
    collection_name='project-category',
    methods=['GET', 'POST', 'PUT', 'PATCH'],
    validation_exceptions=[ValidationError],
    exclude_columns=exclude_columns(),
    allow_functions=True,
    preprocessors=dict(POST=[auth_func],
                       PUT_SINGLE=[auth_func],
                       PUT_MANY=[auth_func],
                       PATCH_SINGLE=[auth_func],
                       PATCH_MANY=[auth_func]))

project_category_api.after_request(add_cors_headers)
app.register_blueprint(project_category_api)
Ejemplo n.º 3
0
from flask_restless.views import ValidationError

from app import api_manager, app
from src.main.dto.comment import exclude_columns
from src.main.http.cros_headers import add_cors_headers
from src.main.model.comment import Comment as CommentModel
from src.main.security.authentication import auth_func

# Comment API object
from src.main.service.comment import send_email

comment_api = api_manager.create_api_blueprint(
    CommentModel,
    methods=['GET', 'POST'],
    exclude_columns=exclude_columns(),
    validation_exceptions=[ValidationError],
    allow_functions=True,
    preprocessors=dict(
        GET_SINGLE=[auth_func],
        GET_MANY=[auth_func],
        POST=[auth_func]
    ),
    postprocessors=dict(
        POST=[send_email]
    )
)

comment_api.after_request(add_cors_headers)
app.register_blueprint(comment_api)
Ejemplo n.º 4
0
from flask_restless.views import ValidationError

from app import api_manager, app
from src.main.dto.role import exclude_columns
from src.main.http.cros_headers import add_cors_headers
from src.main.security.authentication import auth_func
from src.main.model.role import Role

# Role API object
role_api = api_manager.create_api_blueprint(
    Role,
    methods=['GET', 'POST', 'PUT', 'PATCH'],
    validation_exceptions=[ValidationError],
    exclude_columns=exclude_columns(),
    preprocessors=dict(POST=[auth_func],
                       GET_SINGLE=[auth_func],
                       GET_MANY=[auth_func],
                       PUT_SINGLE=[auth_func],
                       PUT_MANY=[auth_func],
                       PATCH_SINGLE=[auth_func],
                       PATCH_MANY=[auth_func]))

role_api.after_request(add_cors_headers)
app.register_blueprint(role_api)
Ejemplo n.º 5
0
    get_complaint_count_by_responded_by as get_complaint_count_by_responded_by_service
from src.main.service.complaint import \
    get_complaint_count_by_complaint_by as get_complaint_count_by_complaint_by_service
from src.main.util.file_upload import get_uploaded_file as get_uploaded_file_service

# Complaint API object
complaint_api = api_manager.create_api_blueprint(
    ComplaintModel,
    methods=['GET', 'POST', 'PUT', 'PATCH'],
    exclude_columns=exclude_columns(),
    validation_exceptions=[ValidationError],
    allow_functions=True,
    preprocessors=dict(
        POST=[auth_func],
        GET_SINGLE=[auth_func],
        GET_MANY=[auth_func],
        PUT_SINGLE=[auth_func, role_police_officer],
        PUT_MANY=[auth_func, role_admin],
        PATCH_SINGLE=[auth_func, role_police_officer],
        PATCH_MANY=[auth_func, role_admin]
    ),
    postprocessors=dict(
        PATCH_SINGLE=[send_email]
    )
)

complaint_api.after_request(add_cors_headers)
app.register_blueprint(complaint_api)


# Complaint File upload API
Ejemplo n.º 6
0
from flask_restless.views import ValidationError

from app import api_manager, app
from src.main.http.cros_headers import add_cors_headers
from src.main.model.proposal_author import ProposalAuthor as ProposalAuthorModel
from src.main.security.authentication import auth_func
from src.main.security.authorization import role_admin, role_first_level, role_second_level


proposal_author_api = api_manager.create_api_blueprint(
    ProposalAuthorModel,
    collection_name='proposal-author',
    methods=['GET', 'POST', 'PUT', 'PATCH'],
    validation_exceptions=[ValidationError],
    allow_functions=True,
    preprocessors=dict(
        GET_SINGLE=[auth_func, role_first_level],
        GET_MANY=[auth_func, role_first_level],
        PUT_SINGLE=[auth_func, role_second_level],
        PUT_MANY=[auth_func, role_second_level],
        PATCH_SINGLE=[auth_func, role_admin],
        PATCH_MANY=[auth_func, role_admin]
    )
)

proposal_author_api.after_request(add_cors_headers)
app.register_blueprint(proposal_author_api)
Ejemplo n.º 7
0
from flask_restless.views import ValidationError

from app import api_manager, app
from src.main.dto.email_log import exclude_columns
from src.main.http.cros_headers import add_cors_headers
from src.main.model.email_log import EmailLog as EmailLogModel
from src.main.service.email_log import send_email as send_email_service
from src.main.security.authentication import auth_func
from src.main.security.authorization import role_first_level, role_second_level

email_log_api = api_manager.create_api_blueprint(
    EmailLogModel,
    collection_name='email-log',
    methods=['GET', 'POST'],
    exclude_columns=exclude_columns(),
    validation_exceptions=[ValidationError],
    allow_functions=True,
    preprocessors=dict(GET_SINGLE=[auth_func, role_first_level],
                       GET_MANY=[auth_func, role_first_level],
                       POST=[auth_func, role_second_level]),
    postprocessors=dict(POST=[send_email_service]))

email_log_api.after_request(add_cors_headers)
app.register_blueprint(email_log_api)
Ejemplo n.º 8
0
from flask_restless.views import ValidationError

from app import api_manager, app
from src.main.http.cros_headers import add_cors_headers
from src.main.model.student import Student as StudentModel
from src.main.security.authentication import auth_func
from src.main.security.authorization import role_admin, role_first_level, role_second_level

student_api = api_manager.create_api_blueprint(
    StudentModel,
    methods=['GET', 'POST', 'PUT', 'PATCH'],
    validation_exceptions=[ValidationError],
    allow_functions=True,
    preprocessors=dict(GET_SINGLE=[auth_func, role_first_level],
                       GET_MANY=[auth_func, role_first_level],
                       PUT_SINGLE=[auth_func, role_second_level],
                       PUT_MANY=[auth_func, role_second_level],
                       PATCH_SINGLE=[auth_func, role_admin],
                       PATCH_MANY=[auth_func, role_admin]))

student_api.after_request(add_cors_headers)
app.register_blueprint(student_api)
Ejemplo n.º 9
0
from flask_restless.views import ValidationError

from app import api_manager, app
from src.main.dto.comment import exclude_columns
from src.main.http.cros_headers import add_cors_headers
from src.main.model.comment import Comment as CommentModel
from src.main.security.authentication import auth_func
from src.main.security.authorization import role_first_level, role_second_level
from src.main.service.comment import update_project_or_student_status

comment_api = api_manager.create_api_blueprint(
    CommentModel,
    methods=['GET', 'POST'],
    exclude_columns=exclude_columns(),
    validation_exceptions=[ValidationError],
    allow_functions=True,
    preprocessors=dict(GET_SINGLE=[auth_func, role_first_level],
                       GET_MANY=[auth_func, role_first_level],
                       POST=[auth_func, role_second_level]),
    postprocessors=dict(POST=[update_project_or_student_status]))

comment_api.after_request(add_cors_headers)
app.register_blueprint(comment_api)
Ejemplo n.º 10
0
from src.main.dto.staff import exclude_columns
from src.main.http.cros_headers import add_cors_headers
from src.main.security.authentication import auth_func
from src.main.model.staff import Staff as StaffModel
from src.main.security.authorization import role_admin
from src.main.service.staff import get_staff_count_for_roles as get_staff_count_for_roles_service


staff_api = api_manager.create_api_blueprint(
    StaffModel,
    methods=['GET', 'POST', 'PUT', 'PATCH'],
    exclude_columns=exclude_columns(),
    validation_exceptions=[ValidationError],
    allow_functions=True,
    preprocessors=dict(
        POST=[auth_func, role_admin],
        GET_SINGLE=[auth_func],
        GET_MANY=[auth_func, role_admin],
        PUT_SINGLE=[auth_func],
        PUT_MANY=[auth_func, role_admin],
        PATCH_SINGLE=[auth_func],
        PATCH_MANY=[auth_func, role_admin]
    )
)

staff_api.after_request(add_cors_headers)
app.register_blueprint(staff_api)


@app.route('/api/staff/role/count', methods=['GET'])
@auth_required
def get_staff_count_for_roles():
Ejemplo n.º 11
0
from flask_restless.views import ValidationError

from app import api_manager, app
from src.main.dto.user import exclude_columns
from src.main.http.cros_headers import add_cors_headers
from src.main.security.authentication import auth_func
from src.main.model.user import User as UserModel
from src.main.security.authorization import role_admin, role_police_officer

user_api = api_manager.create_api_blueprint(
    UserModel,
    methods=['GET', 'POST', 'PUT', 'PATCH'],
    exclude_columns=exclude_columns(),
    validation_exceptions=[ValidationError],
    preprocessors=dict(POST=[auth_func, role_admin],
                       GET_SINGLE=[auth_func],
                       GET_MANY=[auth_func, role_police_officer],
                       PUT_SINGLE=[auth_func],
                       PUT_MANY=[auth_func, role_admin],
                       PATCH_SINGLE=[auth_func],
                       PATCH_MANY=[auth_func, role_admin]))

user_api.after_request(add_cors_headers)
app.register_blueprint(user_api)