Example #1
0
 def get_thumbnail_list(users):
     rv = []
     for uuid in users:
         try:
             user = CaliopeUser.index.get(uuid=uuid)
             get_thumbnail(os.path.join(current_app.config['STATIC_PATH'], user.avatar))
         except DoesNotExist as e:
             current_app.logger.info('CaliopeUser with uuid: ' + uuid + 'not found')
             pass
     return rv
Example #2
0
 def get_thumbnail_list(users):
     rv = []
     for uuid in users:
         try:
             user = CaliopeUser.index.get(uuid=uuid)
             get_thumbnail(
                 os.path.join(current_app.config['STATIC_PATH'],
                              user.avatar))
         except DoesNotExist as e:
             current_app.logger.info('CaliopeUser with uuid: ' + uuid +
                                     'not found')
             pass
     return rv
Example #3
0
    def authenticate(username, password, domain=None):
        try:
            #: TODO: Add support to domain
            userNode = CaliopeUser.index.get(username=username)
            if userNode.password == password:
                session_uuid = str(uuid4()).decode('utf-8')

                g.connection_thread_pool_id[g.connection_thread_id] = session_uuid
                current_app.storekv.put(prefix_session_manager + session_uuid, username)
                PubSub().subscribe_uuid(userNode.uuid)
                PubSub().register_uuid_and_thread_id(userNode.uuid)
                PubSub().publish_command(userNode.uuid, userNode.uuid, 'message',
                                         {'msg': 'Bienvenido', 'type': 'success'}, loopback=True)

                return {
                    'login': True,
                    'session_uuid': {'value': session_uuid},
                    'user_uuid': {'value': userNode.uuid},
                    'user': {'value': username},
                    "first_name": {'value': userNode.first_name},
                    "last_name": {'value': userNode.last_name},
                    "image": get_thumbnail(os.path.join(current_app.config['STATIC_PATH'], userNode.avatar))
                }
            else:
                return {'login': False}
        except DoesNotExist:
            return {'login': False}
        except Exception as e:
            raise JSONRPCInternalError(e)
Example #4
0
    def get_data(cls, uuids):
        rv = list()

        storage_setup = current_app.config['storage']

        if 'local' in storage_setup and 'absolut_path' in storage_setup[
                'local']:
            STORAGE = storage_setup['local']['absolut_path']

        for uuid in uuids:
            vnode = CaliopeDocument.pull(uuid)
            filename = os.path.join(STORAGE, vnode.uuid)
            size = os.stat(filename).st_size
            data = {
                'result':
                'ok',
                'name':
                vnode.filename,
                'size':
                human_readable_size(size),
                'mime':
                vnode.mimetype,
                'id':
                vnode.uuid,
                'thumbnail':
                get_thumbnail(filename,
                              field_name='data',
                              mimetype=vnode.mimetype)
            }
            rv.append(data)

        return rv
Example #5
0
 def get_thumbnail(user):
     rv = {
         "image":
         get_thumbnail(
             os.path.join(current_app.config['STATIC_PATH'], user.avatar))
     }
     return rv
Example #6
0
 def get_user_node_data(user_node):
     rv = {}
     data = user_node._get_node_data()
     for k, v in data.items():
         if not isinstance(v, unicode):
             v = unicode(v)
         data[k] = {'value': v}
     data['name'] = {
         'value':
         data['first_name']['value'] + ' ' + data['last_name']['value']
     }
     rv = {
         u'name':
         data['name'],
         u'username':
         data['username'],
         u'first_name':
         data['first_name'],
         u'last_name':
         data['last_name'],
         u'uuid':
         data['uuid'],
         u'image':
         get_thumbnail(
             os.path.join(current_app.config['STATIC_PATH'],
                          data['avatar']['value']))
     }
     return rv
Example #7
0
def uploader():
    if request.method == 'POST':
        #print request.form['id']
        #print str(request.form.viewitems())
        attachment_params = {k: v[0] for k, v in [x for x in request.form.viewitems()]}
        if 'session_uuid' in request.form:
            if LoginManager().check_with_uuid(request.form['session_uuid']):
                print "OK"
            else:
                return "unrecheable"
        else:
            return "unrecheable"

        app = current_app
        storage_setup = app.config['storage']

        if 'local' in storage_setup and 'absolut_path' in storage_setup['local']:
            UPLOAD_FOLDER = storage_setup['local']['absolut_path']

        if 'local' in storage_setup and 'allowed_extensions' in storage_setup['local']:
            ALLOWED_EXTENSIONS = storage_setup['local']['allowed_extensions']

        rv = []
        for uploaded_file in request.files.getlist('files[]'):
            filename = secure_filename(uploaded_file.filename)
            if uploaded_file and allowed_file(uploaded_file.filename, ALLOWED_EXTENSIONS):
                model = FormManager().get_empty_model('CaliopeDocument', data=True)
                idfile = model['data']['uuid']['value']
                uploaded_file.save(os.path.join(UPLOAD_FOLDER, idfile))

                mimetype = mimetypes.guess_type(filename)[0]
                if mimetype is None:
                    mimetype = 'application/octet-stream'

                CaliopeServices().update_field(idfile, 'mimetype', mimetype)
                CaliopeServices().update_field(idfile, 'filename', filename)
                CaliopeServices().update_field(idfile, 'url', local_document_url('', idfile, ''))
                #DocumentProcess().enqueue(doc)

                result = {
                    'result': 'ok',
                    'name': filename,
                    'size': human_readable_size(uploaded_file.tell()),
                    'id': idfile,
                    'thumbnail': get_thumbnail(os.path.join(UPLOAD_FOLDER, idfile), mimetype=mimetype,
                                               field_name='data')
                }
                CaliopeServices().update_relationship(attachment_params['uuid'], attachment_params['field'], idfile)
            else:
                result = {
                    'result': 'error',
                    'name': filename
                }
            rv.append(result);

        return json.dumps(rv)
    return "unrecheable"
Example #8
0
    def authenticate(username, password, domain=None):
        try:
            #: TODO: Add support to domain
            userNode = CaliopeUser.index.get(username=username)
            if userNode.password == password:
                session_uuid = str(uuid4()).decode('utf-8')

                g.connection_thread_pool_id[
                    g.connection_thread_id] = session_uuid
                current_app.storekv.put(prefix_session_manager + session_uuid,
                                        username)
                PubSub().subscribe_uuid(userNode.uuid)
                PubSub().register_uuid_and_thread_id(userNode.uuid)
                PubSub().publish_command(userNode.uuid,
                                         userNode.uuid,
                                         'message', {
                                             'msg': 'Bienvenido',
                                             'type': 'success'
                                         },
                                         loopback=True)

                return {
                    'login':
                    True,
                    'session_uuid': {
                        'value': session_uuid
                    },
                    'user_uuid': {
                        'value': userNode.uuid
                    },
                    'user': {
                        'value': username
                    },
                    "first_name": {
                        'value': userNode.first_name
                    },
                    "last_name": {
                        'value': userNode.last_name
                    },
                    "image":
                    get_thumbnail(
                        os.path.join(current_app.config['STATIC_PATH'],
                                     userNode.avatar))
                }
            else:
                return {'login': False}
        except DoesNotExist:
            return {'login': False}
        except Exception as e:
            raise JSONRPCInternalError(e)
Example #9
0
 def get_user_node_data(user_node):
     rv = {}
     data = user_node._get_node_data()
     for k, v in data.items():
         if not isinstance(v, unicode):
             v = unicode(v)
         data[k] = {'value': v}
     data['name'] = {'value': data['first_name']['value'] + ' ' + data['last_name']['value']}
     rv = {u'name': data['name'],
           u'username': data['username'],
           u'first_name': data['first_name'],
           u'last_name': data['last_name'],
           u'uuid': data['uuid'],
           u'image': get_thumbnail(os.path.join(current_app.config['STATIC_PATH'], data['avatar']['value']))
     }
     return rv
Example #10
0
 def authenticate_with_uuid(session_uuid, domain=None):
     if session_uuid is not None:
         if current_app.storekv.__contains__(prefix_session_manager +
                                             session_uuid):
             try:
                 username = current_app.storekv.get(prefix_session_manager +
                                                    session_uuid)
                 g.connection_thread_pool_id[
                     g.connection_thread_id] = session_uuid
                 userNode = CaliopeUser.index.get(username=username)
                 PubSub().subscribe_uuid(userNode.uuid)
                 PubSub().register_uuid_and_thread_id(userNode.uuid)
                 PubSub().publish_command(userNode.uuid,
                                          userNode.uuid,
                                          'message', {
                                              'msg': 'Bienvenido',
                                              'type': 'success'
                                          },
                                          loopback=True)
                 return {
                     'login':
                     True,
                     'session_uuid': {
                         'value': session_uuid
                     },
                     'user_uuid': {
                         'value': userNode.uuid
                     },
                     'user': {
                         'value': username
                     },
                     "first_name": {
                         'value': userNode.first_name
                     },
                     "last_name": {
                         'value': userNode.last_name
                     },
                     "image":
                     get_thumbnail(
                         os.path.join(current_app.config['STATIC_PATH'],
                                      userNode.avatar))
                 }
             except Exception as e:
                 raise JSONRPCInternalError(e)
                 #: if not returned is not a  valid session
     return {'login': False}
Example #11
0
    def get_all_with_thumbnails(cls, context=None, thumbnails=False):
        rv = cls.get_all(context=context, recursive=False)

        # TODO: move to DocumentServices
        user_node = CaliopeUser.index.get(username=LoginManager().get_user())

        storage_setup = current_app.config["storage"]
        if "local" in storage_setup and "absolut_path" in storage_setup["local"]:
            STORAGE = storage_setup["local"]["absolut_path"]

        for form in rv[0]["instances"]:
            # TODO: optimize
            results, metadata = user_node.cypher(
                """
                START form=node:CaliopeStorage(uuid='{uuid}')
                MATCH  pa=(form)-[*1..2]-(file)<-[CALIOPE_DOCUMENT]-(),p_none=(file)<-[?:PARENT*]-()
                WHERE p_none = null and has(file.url)
                return distinct file
                 """.format(
                    uuid=form["uuid"]
                )
            )

            # TODO: use cache to thumbnails
            attachments = list()
            for row in results:
                attachment = row[0]
                file_uuid = attachment["uuid"]
                node = CaliopeDocument.pull(file_uuid)
                if thumbnails:
                    filename = os.path.join(STORAGE, file_uuid)
                    size = os.stat(filename).st_size
                    data = {
                        "uuid": file_uuid,
                        "name": node.filename,
                        "size": human_readable_size(size),
                        "thumbnail": get_thumbnail(filename, field_name="data", mimetype=node.mimetype),
                    }
                else:
                    data = {"uuid": file_uuid, "name": node.filename}
                attachments.append(data)
            form["attachments"] = attachments

        return rv
Example #12
0
    def get_all_with_thumbnails(cls, context=None, thumbnails=False):
        rv = cls.get_all(context=context, recursive=False)

        #TODO: move to DocumentServices
        user_node = CaliopeUser.index.get(username=LoginManager().get_user())

        storage_setup = current_app.config['storage']
        if 'local' in storage_setup and 'absolut_path' in storage_setup['local']:
            STORAGE = storage_setup['local']['absolut_path']

        for form in rv[0]['instances']:
            #TODO: optimize
            results, metadata = user_node.cypher("""
                START form=node:CaliopeStorage(uuid='{uuid}')
                MATCH  pa=(form)-[*1..2]-(file)<-[CALIOPE_DOCUMENT]-(),p_none=(file)<-[?:PARENT*]-()
                WHERE p_none = null and has(file.url)
                return distinct file
                 """.format(uuid=form['uuid']))

            #TODO: use cache to thumbnails
            attachments = list()
            for row in results:
                attachment = row[0]
                file_uuid = attachment['uuid']
                node = CaliopeDocument.pull(file_uuid)
                if thumbnails:
                    filename = os.path.join(STORAGE, file_uuid)
                    size = os.stat(filename).st_size
                    data = {
                        'uuid': file_uuid,
                        'name': node.filename,
                        'size': human_readable_size(size),
                        'thumbnail': get_thumbnail(filename, field_name='data', mimetype=node.mimetype)
                    }
                else:
                    data = {
                        'uuid': file_uuid,
                        'name': node.filename
                    }
                attachments.append(data)
            form['attachments'] = attachments

        return rv
Example #13
0
    def get_data(cls, uuids):
        rv = list()

        storage_setup = current_app.config["storage"]

        if "local" in storage_setup and "absolut_path" in storage_setup["local"]:
            STORAGE = storage_setup["local"]["absolut_path"]

        for uuid in uuids:
            vnode = CaliopeDocument.pull(uuid)
            filename = os.path.join(STORAGE, vnode.uuid)
            size = os.stat(filename).st_size
            data = {
                "result": "ok",
                "name": vnode.filename,
                "size": human_readable_size(size),
                "mime": vnode.mimetype,
                "id": vnode.uuid,
                "thumbnail": get_thumbnail(filename, field_name="data", mimetype=vnode.mimetype),
            }
            rv.append(data)

        return rv
Example #14
0
 def authenticate_with_uuid(session_uuid, domain=None):
     if session_uuid is not None:
         if current_app.storekv.__contains__(prefix_session_manager + session_uuid):
             try:
                 username = current_app.storekv.get(prefix_session_manager + session_uuid)
                 g.connection_thread_pool_id[g.connection_thread_id] = session_uuid
                 userNode = CaliopeUser.index.get(username=username)
                 PubSub().subscribe_uuid(userNode.uuid)
                 PubSub().register_uuid_and_thread_id(userNode.uuid)
                 PubSub().publish_command(userNode.uuid, userNode.uuid, 'message',
                                      {'msg': 'Bienvenido', 'type': 'success'}, loopback=True)
                 return {'login': True,
                         'session_uuid': {'value': session_uuid},
                         'user_uuid': {'value': userNode.uuid},
                         'user': {'value': username},
                         "first_name": {'value': userNode.first_name},
                         "last_name": {'value': userNode.last_name},
                         "image": get_thumbnail(
                             os.path.join(current_app.config['STATIC_PATH'], userNode.avatar))
                 }
             except Exception as e:
                 raise JSONRPCInternalError(e)
                 #: if not returned is not a  valid session
     return {'login': False}
Example #15
0
 def get_thumbnail(user):
     rv = {
         "image":
             get_thumbnail(os.path.join(current_app.config['STATIC_PATH'], user.avatar))
     }
     return rv
Example #16
0
def uploader():
    if request.method == 'POST':
        #print request.form['id']
        #print str(request.form.viewitems())
        attachment_params = {
            k: v[0]
            for k, v in [x for x in request.form.viewitems()]
        }
        if 'session_uuid' in request.form:
            if LoginManager().check_with_uuid(request.form['session_uuid']):
                print "OK"
            else:
                return "unrecheable"
        else:
            return "unrecheable"

        app = current_app
        storage_setup = app.config['storage']

        if 'local' in storage_setup and 'absolut_path' in storage_setup[
                'local']:
            UPLOAD_FOLDER = storage_setup['local']['absolut_path']

        if 'local' in storage_setup and 'allowed_extensions' in storage_setup[
                'local']:
            ALLOWED_EXTENSIONS = storage_setup['local']['allowed_extensions']

        rv = []
        for uploaded_file in request.files.getlist('files[]'):
            filename = secure_filename(uploaded_file.filename)
            if uploaded_file and allowed_file(uploaded_file.filename,
                                              ALLOWED_EXTENSIONS):
                model = FormManager().get_empty_model('CaliopeDocument',
                                                      data=True)
                idfile = model['data']['uuid']['value']
                uploaded_file.save(os.path.join(UPLOAD_FOLDER, idfile))

                mimetype = mimetypes.guess_type(filename)[0]
                if mimetype is None:
                    mimetype = 'application/octet-stream'

                CaliopeServices().update_field(idfile, 'mimetype', mimetype)
                CaliopeServices().update_field(idfile, 'filename', filename)
                CaliopeServices().update_field(
                    idfile, 'url', local_document_url('', idfile, ''))
                #DocumentProcess().enqueue(doc)

                result = {
                    'result':
                    'ok',
                    'name':
                    filename,
                    'size':
                    human_readable_size(uploaded_file.tell()),
                    'id':
                    idfile,
                    'thumbnail':
                    get_thumbnail(os.path.join(UPLOAD_FOLDER, idfile),
                                  mimetype=mimetype,
                                  field_name='data')
                }
                CaliopeServices().update_relationship(
                    attachment_params['uuid'], attachment_params['field'],
                    idfile)
            else:
                result = {'result': 'error', 'name': filename}
            rv.append(result)

        return json.dumps(rv)
    return "unrecheable"