Exemplo n.º 1
0
from werkzeug.datastructures import FileStorage
from file_management.extensions import Namespace
from file_management.extensions.custom_exception import PathUploadNotFound, UserNotFoundException
from . import responses
from file_management import helpers
from ..helpers.check_role import user_required
from ..repositories.files import utils
from file_management.helpers.check_role import check_insert_privilege

__author__ = 'Dang'

from ..repositories.user import find_one_by_email

_logger = logging.getLogger(__name__)

ns = Namespace('upload', description='Upload files')

_upload_res = ns.model('upload_res', responses.file_uploaded_res)


@ns.route('/', methods=['PUT'])
class Upload(flask_restplus.Resource):
    parser = reqparse.RequestParser()
    parser.add_argument('in_file', type=FileStorage, location='files')
    parser.add_argument('parent_id', type=str, help='parent_id')

    @ns.expect(parser, validate=True)
    @user_required
    def put(self):
        try:
            email = get_jwt_identity()
# coding=utf-8
import logging

import flask_restplus

from file_management.extensions import Namespace
from file_management.services.notification import get_notification
from . import responses

_logger = logging.getLogger(__name__)

ns = Namespace('notifications', description='Notify to user')

_change_res = ns.model('notifications_res', responses.notification_field)

@ns.route('/<user_id>', methods=['GET'])
class Get_notification(flask_restplus.Resource):
    @ns.marshal_list_with(_change_res)
    def get(self):
        """ Notify to user """
        return get_notification(user_id)
Exemplo n.º 3
0
import flask_restplus
from flask import request

from file_management import services
from file_management.extensions import Namespace
from file_management.extensions.custom_exception import InvalidLoginTokenException
from . import responses, requests

__author__ = 'longhb'

from ..services.user import get_details_by_ids

_logger = logging.getLogger(__name__)

ns = Namespace('users', description='User operations')

_user_res = ns.model('user_res', responses.user_res)


@ns.route('/get_status', methods=['GET'])
class UserStatus(flask_restplus.Resource):
    # @ns.marshal_with(_user_res)
    def get(self):
        "fetch user status by checking jwt token"
        from file_management.constant.user import Constant_user
        try:
            email = services.token.check_jwt_token()
        except:
            raise InvalidLoginTokenException()
        if (email == None):
Exemplo n.º 4
0
import logging
import os
import flask_restplus
from flask import send_from_directory, send_file
from file_management import repositories, services
from file_management.extensions import Namespace
from file_management.extensions.custom_exception import CannotDownloadFile
from . import requests
from ..repositories.files import utils
from file_management.constant import pathconst
from file_management.helpers.check_role import viewable_check

__author__ = 'Dang'
_logger = logging.getLogger(__name__)

ns = Namespace('download', description='Download files')

_download_req = ns.model('download_req', requests.download_file_req)


@ns.route('/<file_id>', methods=['GET'])
class Download(flask_restplus.Resource):
    def get(self, file_id):
        try:
            viewable_check(file_id)
            data = repositories.files.utils.get_file(file_id)
            true_name = data["file_title"]
            owner = data['owner']
            UPLOAD_DIRECTORY = pathconst.DOWNLOAD
            folders = utils.get_ancestors(owner)
            file_path = '/'.join(folders)
Exemplo n.º 5
0
import flask_restplus
from flask import request

from file_management import services
from file_management.api.schema import requests
from file_management.extensions import Namespace

__author__ = 'jian'

from file_management.helpers.transformer import format_details_args
from file_management.services.file import delete_all_file_in_trash

_logger = logging.getLogger(__name__)

ns = Namespace('files', description='File operations')

_file_details_req = ns.model('file_details_request', requests.file_details_req)


@ns.route('/details', methods=['POST'])
class GetFiles(flask_restplus.Resource):
    @ns.expect(_file_details_req, validate=True)
    def post(self):
        args = request.args or request.json
        format_details_args(args)
        return services.file.search(args)


_status_res = ns.model(
    'Status Response', {
Exemplo n.º 6
0
import logging

import flask_restplus
from flask import request

from file_management import services
from file_management.extensions import Namespace
from file_management.helpers import decode_token
from file_management.services.pending_register import send_confirm_email
# from file_management.api import requests, responses
from . import requests, responses

__author__ = 'LongHB'
_logger = logging.getLogger(__name__)

ns = Namespace('register', description='Register operations')

_register_req = ns.model('register_req', requests.register_user_req)
_register_res = ns.model('register_res', responses.pending_register_res)


@ns.route('/', methods=['GET', 'POST'])
class Registers(flask_restplus.Resource):
    @ns.expect(_register_req, validate=True)
    @ns.marshal_with(_register_res)
    def post(self):
        "validate register data, add data to pending register table and send confirm email"
        data = request.args or request.json
        pending_register = services.pending_register.create_pending_register(**data)
        send_confirm_email(**data)
        return pending_register
Exemplo n.º 7
0
# coding=utf-8
import logging

import flask_restplus

from file_management.extensions import Namespace
from file_management.services.log import get_all_log
from . import responses

_logger = logging.getLogger(__name__)

ns = Namespace('logs',
               description='Log about create edit remove file in folder')

_change_res = ns.model('logs_res', responses.log_field)


@ns.route('/<folder_id>', methods=['GET'])
class Get_log(flask_restplus.Resource):
    @ns.marshal_list_with(_change_res)
    def get(self):
        """ Log about create edit remove file in folder """
        return get_all_log(folder_id)
Exemplo n.º 8
0
# coding=utf-8
import logging

import flask_restplus
from flask import request

from file_management import services
from file_management.extensions import Namespace
from file_management.services.user import check_permission
from . import requests, responses

__author__ = 'LongHB'
_logger = logging.getLogger(__name__)

ns = Namespace('profile', description='Profile operations')

_change_req = ns.model('change_password_req', requests.change_password_req)
_change_res = ns.model('change_password_res', responses.user_res)


@ns.route('/change_password', methods=['GET', 'POST'])
class Change_password(flask_restplus.Resource):
    @ns.expect(_change_req, validate=True)
    @ns.marshal_with(_change_res)
    def post(self):
        "validate user by current password and jwt token and set new password"
        data = request.args or request.json
        email = data.get('email')
        check_permission(email)
        new_user = services.password.change_password(**data)
        return new_user
Exemplo n.º 9
0
# coding=utf-8
import logging

from flask_restplus import Resource, reqparse, fields
from flask import request

from file_management.extensions import Namespace
from file_management.services.admin import search_users, block_user, \
    un_block_user
from file_management.helpers.check_role import admin_required
from . import requests, responses

__author__ = 'Dat'
_logger = logging.getLogger(__name__)

ns = Namespace('admin', description='Admin operations')

_user_res = ns.model('user_response', responses.user_res)
_users_list_res = ns.model('users list response',
                           {'users': fields.List(fields.Nested(_user_res))})

_search_users_parser = reqparse.RequestParser()
_search_users_parser.add_argument('username')
_search_users_parser.add_argument('page', type=int)
_search_users_parser.add_argument('ipp', type=int)


@ns.route('/search_users', methods=['GET'])
class SearchUsers(Resource):
    @ns.expect(_search_users_parser)
    @ns.marshal_with(_users_list_res)
Exemplo n.º 10
0
import flask_restplus
from flask import send_file

from file_management import repositories
from file_management.constant import mime
from file_management.extensions import Namespace
from file_management.helpers.check_role import viewable_check
from file_management.services import preview
from ..repositories.files import utils

__author__ = 'LongHB'

_logger = logging.getLogger(__name__)

ns = Namespace('preview', description='Get docs, zip, image preview')


@ns.route('/<file_id>', methods=['GET'])
class Get_preview(flask_restplus.Resource):
    def get(self, file_id):
        "Get docs, zip, image preview. return path to files image or json or pdf"
        viewable_check(file_id)
        data = repositories.files.utils.get_file(file_id)
        mime_type = data["file_type"]
        folders = utils.get_ancestors(data['owner'])
        file_path = '/'.join(folders) + '/' + file_id
        print(file_path)
        if sum([x in mime_type for x in mime.image]):
            return send_file("../" + file_path, mimetype=mime_type)
        elif sum([x in mime_type for x in mime.zip]):
Exemplo n.º 11
0
# coding=utf-8
import logging

import flask_restplus
from flask import request

from file_management import services
from file_management.extensions import Namespace
from file_management.services.notification import get_notification
from file_management.helpers.check_role import user_required
from file_management.api.schema import requests

_logger = logging.getLogger(__name__)

ns = Namespace('notifications', description='Notify to user')

_change_res = ns.model('notifications_req', requests.notification_viewed_req)


@ns.route('/viewed', methods=['POST'])
class UpdateNotificationViewd(flask_restplus.Resource):
    @user_required
    @ns.expect(_change_res, validate=True)
    def post(self):
        """ Mark as read """
        args = request.args or request.json
        return services.notification.marked_as_readed(args.get('ids'))
Exemplo n.º 12
0
# coding=utf-8
import logging
import flask_restplus
from flask import request

__author__ = 'LongHB'

from file_management import services
from file_management.api.schema import requests
from file_management.extensions import Namespace
from file_management.helpers.transformer import format_details_args

_logger = logging.getLogger(__name__)

ns = Namespace('folder', description='Folder operations')

_folder_details_req = ns.model('folder details', requests.folder_details_req)
_folder_create_req = ns.model('folder create', requests.folder_create_req)


@ns.route('/details', methods=['POST'])
class GetFolders(flask_restplus.Resource):
    @ns.expect(_folder_details_req, validate=True)
    def post(self):
        args = request.args or request.json
        format_details_args(args)
        return services.folder.folder_details(args)


@ns.route('/create', methods=['POST'])
class CreateFolder(flask_restplus.Resource):