From a1772d26b5de78f431f27b645835742daca62601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 29 Jul 2014 09:45:07 +0200 Subject: [PATCH] New global option in config.js to specify admin password (useful to hinder some users from accidentally making changes), Closes #606 --- CHANGELOG.md | 13 ++++++------ src/app/components/settings.js | 3 ++- src/app/controllers/dashLoader.js | 2 -- src/app/partials/dashLoader.html | 11 +---------- src/app/partials/dasheditor.html | 10 ++-------- src/app/partials/search.html | 3 +-- src/app/services/elasticsearch/es-client.js | 22 ++++++++++++++++++++- src/config.sample.js | 6 ++++++ 8 files changed, 40 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86ee2dd3e0f..0555cbd5f61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,23 +1,24 @@ # 1.7.0 (unreleased) **New features or improvements** -- [Issue #511](https://github.com/grafana/grafana/issues/511). Allow [[..]] filter notation in all text panels (markdown/html/text) -- [Issue #136](https://github.com/grafana/grafana/issues/136). New legend display option "Align as table" -- [Issue #556](https://github.com/grafana/grafana/issues/556). New legend display option "Right side", will show legend to the right of the graph +- [Issue #511](https://github.com/grafana/grafana/issues/511). Text panel: Allow [[..]] filter notation in all text panels (markdown/html/text) +- [Issue #136](https://github.com/grafana/grafana/issues/136). Chart: New legend display option "Align as table" +- [Issue #556](https://github.com/grafana/grafana/issues/556). Chart: New legend display option "Right side", will show legend to the right of the graph +- [Issue #604](https://github.com/grafana/grafana/issues/604). Chart: New axis format, 'bps' (SI unit in steps of 1000) useful for network gear metics - [Issue #525](https://github.com/grafana/grafana/issues/525). InfluxDB: Enhanced series aliasing (legend names) with pattern replacements - [Issue #581](https://github.com/grafana/grafana/issues/581). InfluxDB: Add continuous query in series results (series typeahead). - [Issue #584](https://github.com/grafana/grafana/issues/584). InfluxDB: Support for alias & alias patterns when using raw query mode - [Issue #394](https://github.com/grafana/grafana/issues/394). InfluxDB: Annotation support - [Issue #610](https://github.com/grafana/grafana/issues/610). InfluxDB: Support for InfluxdB v0.8 list series response schemea (series typeahead) -- [Issue #604](https://github.com/grafana/grafana/issues/604). Chart: New axis format, 'bps' (SI unit in steps of 1000) useful for network gear metics - [Issue #266](https://github.com/grafana/grafana/issues/266). Graphite: New option cacheTimeout to override graphite default memcache timeout +- [Issue #606](https://github.com/grafana/grafana/issues/606). General: New global option in config.js to specify admin password (useful to hinder users from accidentally make changes) **Changes** - [Issue #536](https://github.com/grafana/grafana/issues/536). Graphite: Use unix epoch for Graphite from/to for absolute time ranges **Fixes** -- [Issue #545](https://github.com/grafana/grafana/issues/545). Fix formatting negative values -- [Issue #460](https://github.com/grafana/grafana/issues/460). fix for max legend value when max value is zero +- [Issue #545](https://github.com/grafana/grafana/issues/545). Chart: Fix formatting negative values (axis formats, legend values) +- [Issue #460](https://github.com/grafana/grafana/issues/460). Chart: fix for max legend value when max value is zero # 1.6.1 (2014-06-24) diff --git a/src/app/components/settings.js b/src/app/components/settings.js index ad9429f4b3f..5ee209734d0 100644 --- a/src/app/components/settings.js +++ b/src/app/components/settings.js @@ -26,7 +26,8 @@ function (_, crypto) { grafana_index : 'grafana-dash', elasticsearch_all_disabled : false, playlist_timespan : "1m", - unsaved_changes_warning : true + unsaved_changes_warning : true, + admin: {} }; // This initializes a new hash on purpose, to avoid adding parameters to diff --git a/src/app/controllers/dashLoader.js b/src/app/controllers/dashLoader.js index e782dd3ddb8..16ee360c4dc 100644 --- a/src/app/controllers/dashLoader.js +++ b/src/app/controllers/dashLoader.js @@ -12,8 +12,6 @@ function (angular, _, moment) { module.controller('dashLoader', function($scope, $rootScope, $http, alertSrv, $location, playlistSrv, elastic) { $scope.init = function() { - $scope.gist_pattern = /(^\d{5,}$)|(^[a-z0-9]{10,}$)|(gist.github.com(\/*.*)\/[a-z0-9]{5,}\/*$)/; - $scope.gist = $scope.gist || {}; $scope.elasticsearch = $scope.elasticsearch || {}; $scope.onAppEvent('save-dashboard', function() { diff --git a/src/app/partials/dashLoader.html b/src/app/partials/dashLoader.html index 7ac413282ca..6900af96758 100644 --- a/src/app/partials/dashLoader.html +++ b/src/app/partials/dashLoader.html @@ -49,15 +49,6 @@
  • Share temp copy
  • -
  • -
    Gist
    -
    - - -

    - Last gist: {{gist.last}} -
  • - @@ -73,4 +64,4 @@ Stop playlist - \ No newline at end of file + diff --git a/src/app/partials/dasheditor.html b/src/app/partials/dasheditor.html index 5524352cf17..db6343470d0 100644 --- a/src/app/partials/dasheditor.html +++ b/src/app/partials/dasheditor.html @@ -72,19 +72,13 @@
    Save to
    -
    - -
    Load from
    -
    - -
    -
    +
    @@ -143,4 +137,4 @@ -
    \ No newline at end of file +
    diff --git a/src/app/partials/search.html b/src/app/partials/search.html index 55eeb8e211a..a3eaba3a6dc 100644 --- a/src/app/partials/search.html +++ b/src/app/partials/search.html @@ -77,7 +77,7 @@ - + @@ -92,7 +92,6 @@ -
  • diff --git a/src/app/services/elasticsearch/es-client.js b/src/app/services/elasticsearch/es-client.js index 4489aef77e0..5898bf8743f 100644 --- a/src/app/services/elasticsearch/es-client.js +++ b/src/app/services/elasticsearch/es-client.js @@ -7,7 +7,7 @@ function(angular, config) { var module = angular.module('grafana.services'); - module.service('elastic', function($http) { + module.service('elastic', function($http, $q) { this._request = function(method, url, data) { var options = { @@ -40,6 +40,8 @@ function(angular, config) { }; this.deleteDashboard = function(id) { + if (!this.isAdmin()) { return $q.reject("Invalid admin password"); } + return this._request('DELETE', '/dashboard/' + id) .then(function(result) { return result.data._id; @@ -72,7 +74,25 @@ function(angular, config) { }); }; + this.passwordCache = function(pwd) { + if (!window.sessionStorage) { return null; } + if (!pwd) { return window.sessionStorage["grafanaAdminPassword"]; } + window.sessionStorage["grafanaAdminPassword"] = pwd; + }; + + this.isAdmin = function() { + if (!config.admin || !config.admin.password) { return true; } + if (this.passwordCache() === config.admin.password) { return true; } + + var password = window.prompt("Admin password", ""); + this.passwordCache(password); + + return password === config.admin.password; + }; + this.saveDashboard = function(dashboard, title) { + if (!this.isAdmin()) { return $q.reject("Invalid admin password"); } + var dashboardClone = angular.copy(dashboard); title = dashboardClone.title = title ? title : dashboard.title; diff --git a/src/config.sample.js b/src/config.sample.js index e151a6c311d..6d421855e5b 100644 --- a/src/config.sample.js +++ b/src/config.sample.js @@ -42,6 +42,12 @@ function (Settings) { // Example: "1m", "1h" playlist_timespan: "1m", + // If you want to specify password before saving, please specify it bellow + // The purpose of this password is not security, but to stop some users from accidentally changing dashboards + admin: { + password: '' + }, + // Add your own custom pannels plugins: { panels: []