| |
@@ -55,6 +55,19 @@
|
| |
def data_caching_condition():
|
| |
return jsonify({"visits_required_every_n_days": app.config["ACTIVITY_REQUIRED"]})
|
| |
|
| |
+ @app.route('/api/v1/packager_dashboard/package/<package>', methods=['GET'])
|
| |
+ def route_dashboard_package_data(package):
|
| |
+ package = dashboard_helpers.clean_fas_username(package)
|
| |
+ static_info = {'status': 200, 'data': dashboard_data_static(item=package, kind="package"),
|
| |
+ 'last_synced': datetime.utcnow().isoformat()}
|
| |
+
|
| |
+ dashboard_helpers.update_package_access_time(package)
|
| |
+
|
| |
+ prs = dashboard_data_prs(package, kind="package")
|
| |
+ bzs = dashboard_data_bzs(package, kind="package", authenticated=is_packager())
|
| |
+
|
| |
+ return jsonify({'static_info': static_info, 'prs': prs, 'bzs': bzs})
|
| |
+
|
| |
@app.route('/api/v1/packager_dashboard/<user>', methods=['GET'])
|
| |
def route_dashboard_user_data(user):
|
| |
if user == 'orphan':
|
| |
@@ -63,36 +76,30 @@
|
| |
# Cleanup the username to follow FAS naming restrictions
|
| |
user = dashboard_helpers.clean_fas_username(user)
|
| |
|
| |
- packages_promise = CACHE.async_get('packager-dashboard_user_data_static', 'high', user)
|
| |
- last_synced = CACHE.get_refreshed_time('packager-dashboard_user_data_static', user)
|
| |
+ packages_promise = CACHE.async_get('packager-dashboard_data_static', 'high', user)
|
| |
+ last_synced = CACHE.get_refreshed_time('packager-dashboard_data_static', user)
|
| |
if packages_promise == cache_utils.RefresherNotRegistered:
|
| |
static_info = {'status': 404, 'data': None, 'last_synced': None}
|
| |
elif (packages_promise == cache_utils.AsyncRefreshInProgress or
|
| |
(last_synced and (last_synced + timedelta(seconds=app.config["STATIC_INFO_ROT_AFTER"]) <= datetime.utcnow()))):
|
| |
- celery_utils.plan_celery_refresh('high', 'packager-dashboard_user_data_static', user)
|
| |
+ celery_utils.plan_celery_refresh('high', 'packager-dashboard_data_static', user)
|
| |
static_info = {'status': 204, 'data': None, 'last_synced': last_synced}
|
| |
else:
|
| |
static_info = {'status': 200, 'data': packages_promise, 'last_synced': last_synced.isoformat()}
|
| |
if len(static_info["data"]["packages"]) > 0:
|
| |
dashboard_helpers.update_user_access_time(user)
|
| |
|
| |
- prs = dashboard_user_data_prs(user)
|
| |
- try:
|
| |
- fas_groups = current_user.fas_groups or []
|
| |
- except AttributeError:
|
| |
- # Hit when user isn't logged in
|
| |
- fas_groups = []
|
| |
-
|
| |
- if "packager" in fas_groups:
|
| |
- bzs = dashboard_user_data_bzs(user, authenticated=True)
|
| |
- else:
|
| |
- bzs = dashboard_user_data_bzs(user, authenticated=False)
|
| |
+ prs = dashboard_data_prs(user, kind="user")
|
| |
+ bzs = dashboard_data_bzs(user, kind="user", authenticated=is_packager())
|
| |
|
| |
return jsonify({'static_info': static_info, 'prs': prs, 'bzs': bzs})
|
| |
|
| |
|
| |
- def dashboard_user_data_static(user):
|
| |
- packages = pagure.get_packages(user, CACHE.get('packages_owners_json'), CACHE.get('pagure_groups'))
|
| |
+ def dashboard_data_static(item, kind="user"):
|
| |
+ if kind == "user":
|
| |
+ packages = pagure.get_packages(item, CACHE.get('packages_owners_json'), CACHE.get('pagure_groups'))
|
| |
+ else:
|
| |
+ packages = {"combined": [item], "group": [], "primary": [item]}
|
| |
# Just throw out empty lists and dicts for users without any packages
|
| |
if len(packages["combined"]) == 0:
|
| |
return {
|
| |
@@ -120,26 +127,32 @@
|
| |
'package_versions': versions.get_packages_versions(packages["combined"])
|
| |
}
|
| |
|
| |
-
|
| |
- def dashboard_user_data_prs(user):
|
| |
- data = CACHE.async_get('packager-dashboard_user_data_static', 'low', user)
|
| |
- if data in [cache_utils.RefresherNotRegistered, cache_utils.AsyncRefreshInProgress]:
|
| |
- return {"status": 204, "data": None}
|
| |
+ def dashboard_data_prs(item, kind="user"):
|
| |
+ if kind == "user":
|
| |
+ data = CACHE.async_get('packager-dashboard_data_static', 'low', item)
|
| |
+ if data in [cache_utils.RefresherNotRegistered, cache_utils.AsyncRefreshInProgress]:
|
| |
+ return {"status": 204, "data": None}
|
| |
+ packages = data["packages"]
|
| |
+ else:
|
| |
+ packages = [item]
|
| |
|
| |
status = 200
|
| |
- data, load_status = CACHE.async_get_batch('packager-dashboard_pull_requests', data["packages"], 'low')
|
| |
+ data, load_status = CACHE.async_get_batch('packager-dashboard_pull_requests', packages, 'low')
|
| |
if load_status in [cache_utils.RefresherNotRegistered, cache_utils.AsyncRefreshInProgress]:
|
| |
status = 202
|
| |
return {"status": status, "data": data}
|
| |
|
| |
|
| |
- def dashboard_user_data_bzs(user, authenticated=False):
|
| |
- data = CACHE.async_get('packager-dashboard_user_data_static', 'low', user)
|
| |
- if data in [cache_utils.RefresherNotRegistered, cache_utils.AsyncRefreshInProgress]:
|
| |
- return {"status": 204, "data": None}
|
| |
+ def dashboard_data_bzs(item, kind="user", authenticated=False):
|
| |
+ if kind == "user":
|
| |
+ data = CACHE.async_get('packager-dashboard_data_static', 'low', item)
|
| |
+ if data in [cache_utils.RefresherNotRegistered, cache_utils.AsyncRefreshInProgress]:
|
| |
+ return {"status": 204, "data": None}
|
| |
+ packages = data["packages"]
|
| |
+ else:
|
| |
+ packages = [item]
|
| |
|
| |
status = 200
|
| |
- packages = data["packages"]
|
| |
|
| |
data, load_status = CACHE.async_get_batch('packager-dashboard_bugs', packages, 'low')
|
| |
if load_status in [cache_utils.RefresherNotRegistered, cache_utils.AsyncRefreshInProgress]:
|
| |
@@ -160,6 +173,16 @@
|
| |
|
| |
return {"status": status, "data": data}
|
| |
|
| |
+
|
| |
+ def is_packager():
|
| |
+ try:
|
| |
+ fas_groups = current_user.fas_groups or []
|
| |
+ except AttributeError:
|
| |
+ # Hit when user isn't logged in
|
| |
+ fas_groups = []
|
| |
+
|
| |
+ return "packager" in fas_groups
|
| |
+
|
| |
@app.route('/api/v1/package_versions/<package>', methods=['GET'])
|
| |
def route_package_versions(package):
|
| |
return(jsonify(versions.get_package_versions(package)))
|
| |