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({})
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})
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({})
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]})
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({})
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'] })
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]})
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({})
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})
async def get(self, request): is_admin(request) async with get_conn() as conn: replicas = await Replica(conn).get_all() return UJSONResponse({'data': replicas})