Пример #1
0
    async def delete(self, request):
        is_admin(request)
        replica_id = int(request.path_params['id'])

        async with get_conn() as conn:
            await Replica(conn).delete(replica_id)

        return UJSONResponse({})
Пример #2
0
    async def post(self, request):
        is_admin(request)
        data = await request.json()

        async with get_conn() as conn:
            result = await Users(conn).new_pswd(data['id'])

        return UJSONResponse({'password': result})
Пример #3
0
    async def post(self, request):
        is_admin(request)
        data = await request.json()

        async with get_conn() as conn:
            await Users(conn).deactivate(data['id'])

        return UJSONResponse({})
Пример #4
0
    async def get(self, request):
        is_admin(request)
        offset = request.path_params.get('offset')
        limit = request.path_params.get('limit')

        async with get_conn() as conn:
            data = await Log(conn).get_logs(offset=offset, limit=limit)
        return UJSONResponse({'data': [dict(u) for u in data]})
Пример #5
0
    async def post(self, request):
        is_admin(request)
        data = await request.json()
        replica_id = int(request.path_params['id'])

        async with get_conn() as conn:
            if 'master' in data:
                await Replica(conn).set_master(replica_id)
            if 'delay' in data:
                await Replica(conn).update_delay(replica_id, data['delay'])

        return UJSONResponse({})
Пример #6
0
    async def post(self, request):
        is_admin(request)
        data = await request.json()

        async with get_conn() as conn:
            result = await Users(conn).add_user(data['username'],
                                                data['admin'])

        return UJSONResponse({
            'password': result['password'],
            'username': data['username']
        })
Пример #7
0
    async def get(self, request):
        is_admin(request)
        q = request.path_params.get('q')
        offset = request.path_params.get('offset')
        limit = request.path_params.get('limit')

        async with get_conn() as conn:
            data = await Users(conn).get_users(offset=offset,
                                               limit=limit,
                                               username=q)

        return UJSONResponse({'data': [Users.to_json(u) for u in data]})
Пример #8
0
    async def delete(self, request):
        is_admin(request)
        async with get_conn() as conn:
            async with conn.transaction():
                master = await Replica(conn).master()
                if not master:
                    return api_error('No master set')

                file = await get_file_by_id(request)
                storage = await Storage.get(master)
                await storage.delete(file)

                await Files(conn).delete(file['id'], master['id'])
        return UJSONResponse({})
Пример #9
0
    async def post(self, request):
        is_admin(request)
        data = await request.json()

        async with get_conn() as conn:
            async with conn.transaction():
                replica = Replica(conn)
                result = await replica.add(data['type'], data)

                master = await replica.master()
                if not master:
                    master_id = result
                    await replica.set_master(result)
                else:
                    master_id = master['id']

                await ReplicaFiles(conn).add_replica(result, master_id)

        return UJSONResponse({'id': result})
Пример #10
0
    async def get(self, request):
        is_admin(request)
        async with get_conn() as conn:
            replicas = await Replica(conn).get_all()

        return UJSONResponse({'data': replicas})