Add ability to download logs
This commit is contained in:
parent
52bee66c9f
commit
59046b2e79
5 changed files with 14 additions and 6 deletions
|
@ -1058,13 +1058,12 @@ def delete_webhook(namespace_name, repository_name, public_id):
|
|||
webhook.delete_instance()
|
||||
return webhook
|
||||
|
||||
def list_logs(user_or_organization_name, repository = None):
|
||||
week_ago = datetime.today() - timedelta(7) # One week
|
||||
def list_logs(user_or_organization_name, start_time, repository = None):
|
||||
joined = LogEntry.select().join(User)
|
||||
if repository:
|
||||
joined = joined.where(LogEntry.repository == repository)
|
||||
|
||||
return joined.where(User.username == user_or_organization_name, LogEntry.datetime >= week_ago).order_by(LogEntry.datetime.desc())
|
||||
return joined.where(User.username == user_or_organization_name, LogEntry.datetime >= start_time).order_by(LogEntry.datetime.desc())
|
||||
|
||||
def log_action(kind_name, user_or_organization_name, performer=None, repository=None,
|
||||
access_token=None, ip=None, metadata={}, timestamp=None):
|
||||
|
|
|
@ -28,7 +28,7 @@ from auth.permissions import (ReadRepositoryPermission,
|
|||
from endpoints import registry
|
||||
from endpoints.web import common_login
|
||||
from util.cache import cache_control
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
store = app.config['STORAGE']
|
||||
user_files = app.config['USERFILES']
|
||||
|
@ -1727,8 +1727,10 @@ def log_view(log):
|
|||
def org_logs_api(orgname):
|
||||
permission = AdministerOrganizationPermission(orgname)
|
||||
if permission.can():
|
||||
logs = model.list_logs(orgname)
|
||||
week_ago = datetime.today() - timedelta(7) # One week
|
||||
logs = model.list_logs(orgname, week_ago)
|
||||
return jsonify({
|
||||
'start_time': week_ago,
|
||||
'logs': [log_view(log) for log in logs]
|
||||
})
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ html, body {
|
|||
font-size: 22px;
|
||||
padding: 6px;
|
||||
cursor: pointer;
|
||||
color: black;
|
||||
}
|
||||
|
||||
i.toggle-icon:hover {
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
<span class="right">
|
||||
<i class="fa fa-bar-chart-o toggle-icon" ng-class="chartVisible ? 'active' : ''"
|
||||
ng-click="toggleChart()" title="Toggle Chart" bs-tooltip="tooltip.title"></i>
|
||||
<a href="{{ logsPath }}" download="usage-log.json" target="_new">
|
||||
<i class="fa fa-download toggle-icon" title="Download Logs" bs-tooltip="tooltip.title"></i>
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -686,6 +686,7 @@ quayApp.directive('logsView', function () {
|
|||
$scope.logs = null;
|
||||
$scope.kindsAllowed = null;
|
||||
$scope.chartVisible = true;
|
||||
$scope.logsPath = '';
|
||||
|
||||
var logDescriptions = {
|
||||
'account_change_plan': 'Change plan',
|
||||
|
@ -781,9 +782,11 @@ quayApp.directive('logsView', function () {
|
|||
if ($scope.repository) {
|
||||
url = getRestUrl('repository', $scope.repository.namespace, $scope.repository.name, 'logs');
|
||||
}
|
||||
|
||||
|
||||
var loadLogs = Restangular.one(url);
|
||||
loadLogs.customGET().then(function(resp) {
|
||||
$scope.logsPath = '/api/' + url;
|
||||
|
||||
if (!$scope.chart) {
|
||||
$scope.chart = new LogUsageChart(logKinds);
|
||||
$($scope.chart).bind('filteringChanged', function(e) {
|
||||
|
|
Reference in a new issue