def project_dashboard(hash_session): (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/private/dashboard/projects") if not created: traffic.interactions += 1 traffic.save() if fk.request.method == 'GET': current_user = UserModel.objects(session=hash_session).first() print fk.request.path if current_user is None: return fk.redirect('http://0.0.0.0:5000/error-401/?action=dashboard_denied') else: allowance = current_user.allowed("%s%s"%(fk.request.headers.get('User-Agent'),fk.request.remote_addr)) print "Allowance: "+allowance if allowance == hash_session: projects = ProjectModel.objects(owner=current_user).order_by('+created_at') summaries = [] for p in projects: project = {"project":json.loads(p.summary_json())} records = RecordModel.objects(project=p) project["activity"] = {"number":len(records), "records":[{"id":str(record.id), "created":str(record.created_at), "updated":str(record.updated_at), "status":str(record.status)} for record in records]} summaries.append(project) return fk.Response(json.dumps({'number':len(summaries), 'projects':summaries}, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.redirect('http://0.0.0.0:5000/error-401/?action=dashboard_failed') else: return fk.redirect('http://0.0.0.0:5000/error-405/')
def public_project_view(project_id): logTraffic(CLOUD_URL, endpoint='/public/project/view/<project_id>') if fk.request.method == 'GET': p = ProjectModel.objects.with_id(project_id) if p == None or (p != None and p.access != 'public'): return fk.redirect('{0}:{1}/error/?code=401'.format( VIEW_HOST, VIEW_PORT)) else: project = {"project": json.loads(p.to_json())} records = RecordModel.objects(project=p) project["activity"] = { "number": len(records), "records": [{ "id": str(record.id), "created": str(record.created_at), "updated": str(record.updated_at), "status": str(record.status) } for record in records] } return fk.Response(json.dumps(project, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.redirect('{0}:{1}/error/?code=405'.format( VIEW_HOST, VIEW_PORT))
def project_view(hash_session, project_id): (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/private/project/view/<project_id>") if not created: traffic.interactions += 1 traffic.save() if fk.request.method == 'GET': current_user = UserModel.objects(session=hash_session).first() print fk.request.path if current_user is None: return fk.redirect('http://0.0.0.0:5000/?action=sync_denied') else: allowance = current_user.allowed("%s%s"%(fk.request.headers.get('User-Agent'),fk.request.remote_addr)) print "Allowance: "+allowance if allowance == hash_session: p = ProjectModel.objects.with_id(project_id) if p == None or (p != None and p.owner != current_user and p.access != 'public'): return fk.redirect('http://0.0.0.0:5000/?action=sync_failed') else: project = {"project":json.loads(p.to_json())} records = RecordModel.objects(project=p) project["activity"] = {"number":len(records), "records":[{"id":str(record.id), "created":str(record.created_at), "updated":str(record.updated_at), "status":str(record.status)} for record in records]} return fk.Response(json.dumps(project, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.redirect('http://0.0.0.0:5000/?action=sync_failed') else: return fk.redirect('http://0.0.0.0:5000/error-405/')
def query_basic(words, page, filtr, current_user): filtrs = filter2filters(filtr) raw = [] if "user" not in filtrs: raw.extend([u for u in UserModel.objects().order_by('+created_at') if all(w in str(u.extended()).lower() for w in words)]) # _users = UserModel.objects(Q(email__in=words)|Q(email__in=words)|) # _users_P = ProfileModel.objects() pagination_logs.append("{0} -- query_basic: {1}".format(datetime.datetime.utcnow(), raw)) if "tool" not in filtrs: raw.extend([u for u in ApplicationModel.objects().order_by('+created_at') if all(w in str(u.extended()).lower() for w in words)]) pagination_logs.append("{0} -- query_basic: {1}".format(datetime.datetime.utcnow(), raw)) if "project" not in filtrs: raw.extend([u for u in ProjectModel.objects().order_by('+created_at') if all(w in str(u.extended()).lower() for w in words) and (u.access == 'public' or current_user and (current_user == u.owner or current_user.group == "admin"))]) pagination_logs.append("{0} -- query_basic: {1}".format(datetime.datetime.utcnow(), raw)) if "record" not in filtrs: raw.extend([u for u in RecordModel.objects().order_by('+created_at') if all(w in str(u.extended()).lower() for w in words) and (u.access == 'public' or (current_user and u.project) and (current_user == u.project.owner or current_user.group == "admin"))]) pagination_logs.append("{0} -- query_basic: {1}".format(datetime.datetime.utcnow(), raw)) if "diff" not in filtrs: raw.extend([u for u in DiffModel.objects().order_by('+created_at') if all(w in str(u.extended()).lower() for w in words) and ((u.record_from.access == 'public' and u.record_to.access == 'public') or (current_user and (current_user.group == "admin" or current_user == u.record_from.project.owner or current_user == u.record_to.project.owner)))]) pagination_logs.append("{0} -- query_basic: {1}".format(datetime.datetime.utcnow(), raw)) if "env" not in filtrs: raw.extend([u for u in EnvironmentModel.objects().order_by('+created_at') if all(w in str(u.extended()).lower() for w in words) and (len(ProjectModel.objects(history=str(u.id))) > 0 and (ProjectModel.objects(history=str(u.id))[0].access == 'public' or current_user and (current_user == ProjectModel.objects(history=str(u.id))[0].owner or current_user.group == "admin")))]) pagination_logs.append("{0} -- query_basic: {1}".format(datetime.datetime.utcnow(), raw)) return raw2dict(raw, page)
def tearDown(self): # Delete all documents # Stop mongodb instance. for traffic in TrafficModel.objects(): traffic.delete() for stat in StatModel.objects(): stat.delete() for bundle in BundleModel.objects(): bundle.delete() for version in VersionModel.objects(): version.delete() for user in UserModel.objects(): user.delete() for file in FileModel.objects(): file.delete() for profile in ProfileModel.objects(): profile.delete() for message in MessageModel.objects(): message.delete() for project in ProjectModel.objects(): project.delete() for comment in CommentModel.objects(): comment.delete() for application in ApplicationModel.objects(): application.delete() for access in AccessModel.objects(): access.delete() for environment in EnvironmentModel.objects(): environment.delete() for record in RecordModel.objects(): record.delete() for record in RecordBodyModel.objects(): record.delete() for diff in DiffModel.objects(): diff.delete()
def public_dashboard_records(project_id): (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/public/dashboard/records/<project_id>") if not created: traffic.interactions += 1 traffic.save() if fk.request.method == 'GET': p = ProjectModel.objects.with_id(project_id) if p.access == 'public': project = {"project":json.loads(p.summary_json())} records = RecordModel.objects(project=p) records_object = [] for record in records: if record.access == 'public': record_object = {"id":str(record.id), "created":str(record.created_at), "updated":str(record.updated_at), "status":str(record.status)} diffs = [] founds = DiffModel.objects(record_from=record) if founds != None: for diff in founds: diffs.append(diff.info()) founds = DiffModel.objects(record_to=record) if founds != None: for diff in founds: diffs.append(diff.info()) record_object['diffs'] = len(diffs) records_object.append(record_object) project["activity"] = {"number":len(records), "records":records_object} return fk.Response(json.dumps(project, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.redirect('http://0.0.0.0:5000/error-401/?action=dashboard_failed') else: return fk.redirect('http://0.0.0.0:5000/error-405/')
def project_edit(project_id): logTraffic(CLOUD_URL, endpoint='/private/project/edit/<project_id>') hash_session = basicAuthSession(fk.request) if fk.request.method == 'POST': access_resp = access_manager.check_cloud(hash_session, ACC_SEC, CNT_SEC) current_user = access_resp[1] if current_user is not None: logAccess(fk, access_resp[1], CLOUD_URL, 'cloud', '/private/project/edit/<project_id>') project = ProjectModel.objects.with_id(project_id) if project == None or (project != None and project.owner != current_user and current_user.group != "admin"): return fk.Response('Unauthorized action on this project.', status.HTTP_401_UNAUTHORIZED) else: if fk.request.data: data = json.loads(fk.request.data) try: description = data.get("description", project.description) goals = data.get("goals", project.goals) group = data.get("group", project.group) access = data.get("access", 'unchanged') tags = data.get("tags", ','.join(project.tags)) environment = data.get("environment", {}) project.description = description project.goals = goals project.group = group if access != "unchanged": project.access = access project.tags = tags.split(',') if len(environment) != 0: environment_model = EnvironmentModel.objects.with_id(environment['id']) if environment_model is not None: system = environment.get('system', environment_model.system) version = environment.get('version', environment_model.version) specifics = environment.get('specifics', environment_model.specifics) group = environment.get('group', environment_model.group) remote_bundle = environment.get('bundle', '') environment_model.system = system environment_model.version = version environment_model.specifics = specifics environment_model.group = group if remote_bundle != '' and environment_model.bundle['scope'] != 'local': environment_model.bundle['location'] = remote_bundle environment_model.save() project.save() if access != "unchanged": for record in RecordModel.objects(project=project): record.access = access record.save() return fk.Response('Project updated', status.HTTP_200_OK) except: print(str(traceback.print_exc())) return fk.Response('Failure to process. Contact admin if it persists.', status.HTTP_500_INTERNAL_SERVER_ERROR) else: return fk.Response('No content provided for the update.', status.HTTP_204_NO_CONTENT) else: return fk.Response('Unauthorized action on this project.', status.HTTP_401_UNAUTHORIZED) else: return fk.Response('Endpoint does not support this HTTP method.', status.HTTP_405_METHOD_NOT_ALLOWED)
def public_records(): logTraffic(endpoint='/admin/records') if fk.request.method == 'GET': records = RecordModel.objects() records_dict = {'total_records':len(records), 'records':[]} for record in records: records_dict['records'].append(record.extended()) return api_response(200, 'Records list', records_dict) else: return api_response(405, 'Method not allowed', 'This endpoint supports only a GET method.')
def public_project_view(project_id): logTraffic(CLOUD_URL, endpoint='/public/project/view/<project_id>') if fk.request.method == 'GET': p = ProjectModel.objects.with_id(project_id) if p == None or (p != None and p.access != 'public'): return fk.redirect('{0}:{1}/error/?code=401'.format(VIEW_HOST, VIEW_PORT)) else: project = {"project":json.loads(p.to_json())} records = RecordModel.objects(project=p) project["activity"] = {"number":len(records), "records":[{"id":str(record.id), "created":str(record.created_at), "updated":str(record.updated_at), "status":str(record.status)} for record in records]} return fk.Response(json.dumps(project, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.redirect('{0}:{1}/error/?code=405'.format(VIEW_HOST, VIEW_PORT))
def public_project_records(project_id): logTraffic(endpoint='/admin/project/records/<project_id>') if fk.request.method == 'GET': project = ProjectModel.objects.with_id(project_id) if project == None: return api_response(404, 'Request suggested an empty response', 'Unable to find this project.') else: records = RecordModel.objects(project=project) records_dict = {'total_records':len(records), 'records':[]} for record in records: records_dict['records'].append(record.extended()) return api_response(200, 'Project [%s] Records list'%project.name, records_dict) else: return api_response(405, 'Method not allowed', 'This endpoint supports only a GET method.')
def public_project_view(project_id): (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/public/project/view/<project_id>") if not created: traffic.interactions += 1 traffic.save() if fk.request.method == 'GET': p = ProjectModel.objects.with_id(project_id) if p == None or (p != None and p.access != 'public'): return fk.redirect('http://0.0.0.0:5000/?action=sync_failed') else: project = {"project":json.loads(p.to_json())} records = RecordModel.objects(project=p) project["activity"] = {"number":len(records), "records":[{"id":str(record.id), "created":str(record.created_at), "updated":str(record.updated_at), "status":str(record.status)} for record in records]} return fk.Response(json.dumps(project, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.redirect('http://0.0.0.0:5000/error-405/')
def project_sync(project_id): logTraffic(CLOUD_URL, endpoint='/private/project/sync/<project_id>') hash_session = basicAuthSession(fk.request) if fk.request.method == 'GET': access_resp = access_manager.check_cloud(hash_session, ACC_SEC, CNT_SEC) current_user = access_resp[1] if current_user is None: return fk.redirect('{0}:{1}/error/?code=401'.format(VIEW_HOST, VIEW_PORT)) else: logAccess(fk, access_resp[1], CLOUD_URL, 'cloud', '/private/project/sync/<project_id>') p = ProjectModel.objects.with_id(project_id) if p == None or (p != None and p.owner != current_user and p.access != 'public' and current_user.group != "admin"): return fk.redirect('{0}:{1}/error/?code=401'.format(VIEW_HOST, VIEW_PORT)) else: project = {"project":json.loads(p.summary_json())} records = RecordModel.objects(project=p).order_by('-updated_at') project["activity"] = {"number":len(records), "records":[{"id":str(record.id), "created":str(record.created_at), "updated":str(record.updated_at), "status":str(record.status)} for record in records]} return fk.Response(json.dumps(project, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.redirect('{0}:{1}/error/?code=405'.format(VIEW_HOST, VIEW_PORT))
def project_view(project_id): logTraffic(CLOUD_URL, endpoint='/private/project/view/<project_id>') hash_session = basicAuthSession(fk.request) if fk.request.method == 'GET': access_resp = access_manager.check_cloud(hash_session, ACC_SEC, CNT_SEC) current_user = access_resp[1] if current_user is None: return fk.Response('Unauthorized action on this project.', status.HTTP_401_UNAUTHORIZED) else: logAccess(CLOUD_URL, 'cloud', '/private/project/view/<project_id>') p = ProjectModel.objects.with_id(project_id) if p == None or (p != None and p.owner != current_user and p.access != 'public' and current_user.group != "admin"): return fk.redirect('{0}:{1}/error/?code=401'.format(VIEW_HOST, VIEW_PORT)) else: project = {"project":json.loads(p.to_json())} records = RecordModel.objects(project=p) project["activity"] = {"number":len(records), "records":[{"id":str(record.id), "created":str(record.created_at), "updated":str(record.updated_at), "status":str(record.status)} for record in records]} return fk.Response(json.dumps(project, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.Response('Endpoint does not support this HTTP method.', status.HTTP_405_METHOD_NOT_ALLOWED)
def public_project_dashboard(): (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/public/dashboard/projects") if not created: traffic.interactions += 1 traffic.save() if fk.request.method == 'GET': projects = ProjectModel.objects.order_by('+created_at') summaries = [] for p in projects: if project.access == 'public': project = {"project":json.loads(p.summary_json())} records = [] for r in RecordModel.objects(project=p): if r.access == 'public': records.append(r) project["activity"] = {"number":len(records), "records":[{"id":str(record.id), "created":str(record.created_at), "updated":str(record.updated_at), "status":str(record.status)} for record in records]} summaries.append(project) return fk.Response(json.dumps({'number':len(summaries), 'projects':summaries}, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.redirect('http://0.0.0.0:5000/error-405/')
def dashboard_records(hash_session, project_id): (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/private/dashboard/records/<project_id>") if not created: traffic.interactions += 1 traffic.save() if fk.request.method == 'GET': current_user = UserModel.objects(session=hash_session).first() print fk.request.path if current_user is None: return fk.redirect('http://0.0.0.0:5000/error-401/?action=dashboard_denied') else: allowance = current_user.allowed("%s%s"%(fk.request.headers.get('User-Agent'),fk.request.remote_addr)) print "Allowance: "+allowance if allowance == hash_session: p = ProjectModel.objects.with_id(project_id) project = {"project":json.loads(p.summary_json())} records = RecordModel.objects(project=p) records_object = [] for record in records: record_object = {"id":str(record.id), "created":str(record.created_at), "updated":str(record.updated_at), "status":str(record.status)} diffs = [] founds = DiffModel.objects(record_from=record) if founds != None: for diff in founds: diffs.append(diff.info()) founds = DiffModel.objects(record_to=record) if founds != None: for diff in founds: diffs.append(diff.info()) record_object['diffs'] = len(diffs) records_object.append(record_object) project["activity"] = {"number":len(records), "records":records_object} return fk.Response(json.dumps(project, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.redirect('http://0.0.0.0:5000/error-401/?action=dashboard_failed') else: return fk.redirect('http://0.0.0.0:5000/error-405/')
def project_view(hash_session, project_id): logTraffic(CLOUD_URL, endpoint='/private/<hash_session>/project/view/<project_id>') if fk.request.method == 'GET': access_resp = access_manager.check_cloud(hash_session) current_user = access_resp[1] if current_user is None: return fk.Response('Unauthorized action on this project.', status.HTTP_401_UNAUTHORIZED) else: logAccess(CLOUD_URL, 'cloud', '/private/<hash_session>/project/view/<project_id>') p = ProjectModel.objects.with_id(project_id) if p == None or (p != None and p.owner != current_user and p.access != 'public'): return fk.redirect('{0}:{1}/error/?code=401'.format( VIEW_HOST, VIEW_PORT)) else: project = {"project": json.loads(p.to_json())} records = RecordModel.objects(project=p) project["activity"] = { "number": len(records), "records": [{ "id": str(record.id), "created": str(record.created_at), "updated": str(record.updated_at), "status": str(record.status) } for record in records] } return fk.Response(json.dumps(project, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.Response('Endpoint does not support this HTTP method.', status.HTTP_405_METHOD_NOT_ALLOWED)
def user_home(): (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/public/user/home") if not created: traffic.interactions += 1 traffic.save() if fk.request.method == 'GET': users = UserModel.objects() projects = ProjectModel.objects() records = RecordModel.objects() environments = EnvironmentModel.objects() print fk.request.path users_stat = {"number":len(users)} users_stat["history"] = [json.loads(stat.to_json()) for stat in StatModel.objects(category="user")] projects_stat = {"number":len(projects)} projects_stat["history"] = [json.loads(stat.to_json()) for stat in StatModel.objects(category="project")] storage_stat = {} storage_stat["history"] = [json.loads(stat.to_json()) for stat in StatModel.objects(category="storage")] amount = 0 for user in users: try: amount += user.quota except: amount += 0 storage_stat["size"] = size(amount) records_stat = {"number":len(records)} records_stat["history"] = [json.loads(stat.to_json()) for stat in StatModel.objects(category="record")] return fk.Response(json.dumps({'users':users_stat, 'projects':projects_stat, 'records':records_stat, 'storage':storage_stat}, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.make_response('Method not allowed.', status.HTTP_405_METHOD_NOT_ALLOWED)
def user_dashboard(hash_session): (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/private/user/dashboard/<hash_session>") if not created: traffic.interactions += 1 traffic.save() if fk.request.method == 'GET': user_model = UserModel.objects(session=hash_session).first() print fk.request.path if user_model is None: return fk.redirect('http://0.0.0.0:5000/?action=logout_denied') else: profile_model = ProfileModel.objects(user=user_model).first() # print "Connected_at: %s"%str(user_model.connected_at) allowance = user_model.allowed("%s%s"%(fk.request.headers.get('User-Agent'),fk.request.remote_addr)) print "Allowance: "+allowance # print "Connected_at: %s"%str(user_model.connected_at) if allowance == hash_session: dashboard = {} projects = ProjectModel.objects(owner=user_model) if profile_model is not None: dashboard["profile"] = {'fname':profile_model.fname, 'lname':profile_model.lname, 'organisation':profile_model.organisation, 'about':profile_model.about, 'picture':profile_model.picture} dashboard["records_total"] = 0 dashboard["projects_total"] = len(projects) dashboard["records_total"] = 0 dashboard["environments_total"] = 0 dashboard["projects"] = [] for project in projects: project_dash = {"name":project.name, "records":{"January":{"number":0, "size":0}, "February":{"number":0, "size":0}, "March":{"number":0, "size":0}, "April":{"number":0, "size":0}, "May":{"number":0, "size":0}, "June":{"number":0, "size":0}, "July":{"number":0, "size":0}, "August":{"number":0, "size":0}, "September":{"number":0, "size":0}, "October":{"number":0, "size":0}, "November":{"number":0, "size":0}, "December":{"number":0, "size":0}}} records = RecordModel.objects(project=project) dashboard["records_total"] += len(records) for record in records: environment = record.environment size = 0 try: size = environment.bundle["size"] except: size = 0 dashboard["environments_total"] += size month = str(record.created_at).split("-")[1] if month == "01": project_dash["records"]["January"]["number"] += 1 project_dash["records"]["January"]["size"] += size if month == "02": project_dash["records"]["February"]["number"] += 1 project_dash["records"]["February"]["size"] += size if month == "03": project_dash["records"]["March"]["number"] += 1 project_dash["records"]["March"]["size"] += size if month == "04": project_dash["records"]["April"]["number"] += 1 project_dash["records"]["April"]["size"] += size if month == "05": project_dash["records"]["May"]["number"] += 1 project_dash["records"]["May"]["size"] += size if month == "06": project_dash["records"]["June"]["number"] += 1 project_dash["records"]["June"]["size"] += size if month == "07": project_dash["records"]["July"]["number"] += 1 project_dash["records"]["July"]["size"] += size if month == "08": project_dash["records"]["August"]["number"] += 1 project_dash["records"]["August"]["size"] += size if month == "09": project_dash["records"]["September"]["number"] += 1 project_dash["records"]["September"]["size"] += size if month == "10": project_dash["records"]["October"]["number"] += 1 project_dash["records"]["October"]["size"] += size if month == "11": project_dash["records"]["November"]["number"] += 1 project_dash["records"]["November"]["size"] += size if month == "12": project_dash["records"]["December"]["number"] += 1 project_dash["records"]["December"]["size"] += size dashboard["projects"].append(project_dash) return fk.Response(json.dumps(dashboard, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.redirect('http://0.0.0.0:5000/?action=dashboard_failed') else: return fk.make_response('Method not allowed.', status.HTTP_405_METHOD_NOT_ALLOWED)
def fetchDependencies(name, obj, offset, leftover, filtrs): deps = {} size = 0 if name == "user": # profiles, size, offset, leftover = paginate(ProfileModel.objects(user=obj), offset, leftover, size) # deps["profile"] = profiles if "file" not in filtrs: files, size, offset, leftover = paginate(FileModel.objects(owner=obj), offset, leftover, size) deps["file"] = files if "project" not in filtrs: projects, size, offset, leftover = paginate(ProjectModel.objects(owner=obj), offset, leftover, size) deps["project"] = projects if "tool" not in filtrs: tools, size, offset, leftover = paginate(ApplicationModel.objects(developer=obj), offset, leftover, size) deps["tool"] = tools # elif name == "version": # if "env" not in filtrs: # envs, size, offset, leftover = paginate(EnvironmentModel.objects(version=obj), offset, leftover, size) # deps["env"] = envs elif name == "record": if "diff" not in filtrs: diffs_from, size, offset, leftover = paginate(DiffModel.objects(record_from=obj), offset, leftover, size) deps["diff"] = diffs_from diffs_to = [el for el in DiffModel.objects(record_to=obj)] diffs_more = [] for rec in diffs_to: if rec not in deps["diff"]: diffs_more.append(rec) diffs_more, size, offset, leftover = paginate(diffs_more, offset, leftover, size) deps["diff"].extend(diffs_more) elif name == "project": if "record" not in filtrs: records, size, offset, leftover = paginate(RecordModel.objects(project=obj), offset, leftover, size) deps["record"] = records # elif name == "file": # projects = [pr for pr in ProjectModel.objects() if str(obj.id) in pr.resources] # logo_projects = [el for el in ProjectModel.objects(logo=obj)] # for pr in logo_projects: # if pr not in projects: # projects.append(pr) # projects, size, offset, leftover = paginate(projects, offset, leftover, size) # deps["project"] = projects # records = [rec for rec in RecordModel.objects() if str(obj.id) in rec.resources] # records, size, offset, leftover = paginate(records, offset, leftover, size) # deps["record"] = records # tools, size, offset, leftover = paginate(ApplicationModel.objects(logo=obj), offset, leftover, size) # deps["tool"] = tools # envs = [env for env in EnvironmentModel.objects() if str(obj.id) in env.resources] # envs, size, offset, leftover = paginate(envs, offset, leftover, size) # deps["env"] = envs # diffs = [dff for dff in DiffModel.objects() if str(obj.id) in dff.resources] # diffs, size, offset, leftover = paginate(diffs, offset, leftover, size) # deps["diff"] = diffs # profiles, size, offset, leftover = paginate(ProfileModel.objects(picture=obj), offset, leftover, size) # deps["profile"] = profiles elif name == "env": if "record" not in filtrs: records, size, offset, leftover = paginate(RecordModel.objects(environment=obj), offset, leftover, size) deps["record"] = records if "project" not in filtrs: projects = [pr for pr in ProjectModel.objects if str(obj.id) in pr.history] projects, size, offset, leftover = paginate(projects, offset, leftover, size) deps["project"] = projects # elif name == "bundle": # envs, size, offset, leftover = paginate(EnvironmentModel.objects(bundle=obj), offset, leftover, size) # deps["env"] = envs pagination_logs.append("{0} -- fetchDependencies: {1}, {2}, {3}, {4}".format(datetime.datetime.utcnow(), size, offset, leftover)) return deps, size, offset, leftover
def fetchDependencies(name, obj): deps = {} if name == "user": profiles = [el for el in ProfileModel.objects(user=obj)] deps["profile"] = profiles files = [el for el in FileModel.objects(owner=obj)] deps["file"] = files projects = [el for el in ProjectModel.objects(owner=obj)] deps["project"] = projects tools = [el for el in ApplicationModel.objects(developer=obj)] deps["tool"] = tools elif name == "version": envs = [el for el in EnvironmentModel.objects(version=obj)] deps["env"] = envs elif name == "record": diffs_from = [el for el in DiffModel.objects(record_from=obj)] deps["diff"] = diffs_from diffs_to = [el for el in DiffModel.objects(record_to=obj)] for rec in diffs_to: if rec not in deps["diff"]: deps["diff"].append(rec) elif name == "project": records = [el for el in RecordModel.objects(project=obj)] deps["record"] = records elif name == "file": projects = [ pr for pr in ProjectModel.objects() if str(obj.id) in pr.resources ] logo_projects = [el for el in ProjectModel.objects(logo=obj)] for pr in logo_projects: if pr not in projects: projects.append(pr) deps["project"] = projects records = [ rec for rec in RecordModel.objects() if str(obj.id) in rec.resources ] deps["record"] = records tools = [el for el in ApplicationModel.objects(logo=obj)] deps["tool"] = tools envs = [ env for env in EnvironmentModel.objects() if str(obj.id) in env.resources ] deps["env"] = envs diffs = [ dff for dff in DiffModel.objects() if str(obj.id) in dff.resources ] deps["diff"] = diffs profiles = [el for el in ProfileModel.objects(picture=obj)] deps["profile"] = profiles elif name == "env": records = [el for el in RecordModel.objects(environment=obj)] deps["record"] = records projects = [ pr for pr in ProjectModel.objects() if str(obj.id) in pr.history ] deps["project"] = projects elif name == "bundle": envs = [el for el in EnvironmentModel.objects(bundle=obj)] deps["env"] = envs return deps
def public_search(): (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/public/dashboard/search") if not created: traffic.interactions += 1 traffic.save() if fk.request.method == 'GET': if fk.request.args: query = fk.request.args.get("query").split(" ") #single word for now. users = [] for user in UserModel.objects(): profile = ProfileModel.objects(user=user) where = [] if query in user.email: where.append("email") if query in profile.fname: where.append("fname") if query in profile.lname: where.append("lname") if query in profile.organisation: where.append("organisation") if query in profile.about: where.append("about") if len(where) != 0: users.append({"id":str(user.id), "email":user.email, "fname":profile.fname, "lname":profile.lname, "organisation":profile.organisation, "about":profile.about}) projects = [] records = [] for project in ProjectModel.objects(): if project.access == 'public': where_project = [] if query in project.name: where_project.append("name") if query in project.goals: where_project.append("goals") if query in project.description: where_project.append("description") if query in project.group: where_project.append("group") if len(where_project) != 0: projects.append({"user":str(project.owner.id), "id":str(project.id), "name":project.name, "created":str(project.created_at), "duration":str(project.duration)}) for record in RecordModel.objects(project=project): if record.access == 'public': body = record.body where_record = [] if query in record.label: where_record.append("label") if query in str(json.dumps(record.system)): where_record.append("system") if query in str(json.dumps(record.program)): where_record.append("program") if query in str(json.dumps(record.inputs)): where_record.append("inputs") if query in str(json.dumps(record.outputs)): where_record.append("outputs") if query in str(json.dumps(record.dependencies)): where_record.append("dependencies") if query in record.status: where_record.append("status") if query in str(json.dumps(body.data)): where_record.append("data") if len(where_record) != 0: records.append({"user":str(record.project.owner.id), "project":str(record.project.id), "id":str(record.id), "label":record.label, "created":str(record.created_at), "status":record.status}) diffs = [] for diff in DiffModel.objects(): if diff.record_from.access == 'public' and diff.record_to.access == 'public': where = [] if query in str(json.dumps(diff.diff)): where.append("diff") if query in diff.proposition: where.append("proposition") if query in diff.status: where.append("status") if query in str(json.dumps(diff.comments)): where.append("comments") if len(where) != 0: diffs.append({"id":str(diff.id), "from":str(diff.record_from.id), "to":str(diff.record_to.id), "sender":str(diff.sender.id), "targeted":str(diff.targeted.id), "proposition":diff.proposition, "status":diff.status}) return fk.Response(json.dumps({'users':{'count':len(users), 'result':users}, 'projects':{'count':len(projects), 'result':projects}, 'records':{'count':len(records), 'result':records}, 'diffs':{'count':len(diffs), 'result':diffs}}, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json') else: return fk.redirect('http://0.0.0.0:5000/error-400/') else: return fk.redirect('http://0.0.0.0:5000/error-405/')