diff --git a/public/app/features/dashboard/dashboardNavCtrl.js b/public/app/features/dashboard/dashboardNavCtrl.js index 11595e30479..d2cf8d29c12 100644 --- a/public/app/features/dashboard/dashboardNavCtrl.js +++ b/public/app/features/dashboard/dashboardNavCtrl.js @@ -119,6 +119,8 @@ function (angular, _) { $scope.saveDashboardAs = function() { var newScope = $rootScope.$new(); newScope.clone = $scope.dashboard.getSaveModelClone(); + newScope.clone.editable = true; + newScope.clone.hideControls = false; $scope.appEvent('show-modal', { src: './app/features/dashboard/partials/saveDashboardAs.html', diff --git a/public/app/features/dashboard/dashboardSrv.js b/public/app/features/dashboard/dashboardSrv.js index 73a36ed3da8..9324f18e33b 100644 --- a/public/app/features/dashboard/dashboardSrv.js +++ b/public/app/features/dashboard/dashboardSrv.js @@ -66,6 +66,8 @@ function (angular, $, kbn, _, moment) { if (!this.editable) { meta.canEdit = false; meta.canDelete = false; + meta.canSave = false; + this.hideControls = true; } this.meta = meta; diff --git a/public/app/features/dashboard/partials/dashboardTopNav.html b/public/app/features/dashboard/partials/dashboardTopNav.html index 711fb1f34ba..6f85d6b4e02 100644 --- a/public/app/features/dashboard/partials/dashboardTopNav.html +++ b/public/app/features/dashboard/partials/dashboardTopNav.html @@ -27,7 +27,7 @@
  • -
  • +
  • Templating
  • Export
  • View JSON
  • -
  • Save As...
  • +
  • Save As...
  • Delete dashboard
  • diff --git a/public/app/routes/dashLoadControllers.js b/public/app/routes/dashLoadControllers.js index ba33dc7e73a..ee36ef72117 100644 --- a/public/app/routes/dashLoadControllers.js +++ b/public/app/routes/dashLoadControllers.js @@ -59,12 +59,15 @@ function (angular, _, kbn, moment, $) { $location.path(''); return; } - $scope.initDashboard({meta: {}, model: window.grafanaImportDashboard }, $scope); + $scope.initDashboard({ + meta: { canShare: false, canStar: false }, + model: window.grafanaImportDashboard + }, $scope); }); module.controller('NewDashboardCtrl', function($scope) { $scope.initDashboard({ - meta: {}, + meta: { canStar: false, canShare: false }, model: { title: "New dashboard", rows: [{ height: '250px', panels:[] }] @@ -93,7 +96,10 @@ function (angular, _, kbn, moment, $) { }; file_load($routeParams.jsonFile).then(function(result) { - $scope.initDashboard({meta: {fromFile: true}, model: result}, $scope); + $scope.initDashboard({ + meta: { canSave: false, canDelete: false }, + model: result + }, $scope); }); }); @@ -138,7 +144,10 @@ function (angular, _, kbn, moment, $) { }; script_load($routeParams.jsFile).then(function(result) { - $scope.initDashboard({meta: {fromScript: true, canDelete: false}, model: result.data}, $scope); + $scope.initDashboard({ + meta: {fromScript: true, canDelete: false, canSave: false}, + model: result.data + }, $scope); }); }); diff --git a/public/app/services/contextSrv.js b/public/app/services/contextSrv.js index c615e0baf8c..99bbcccf156 100644 --- a/public/app/services/contextSrv.js +++ b/public/app/services/contextSrv.js @@ -18,13 +18,6 @@ function (angular, _, store, config) { } } - this.version = config.buildInfo.version; - this.lightTheme = false; - this.user = new User(); - this.isSignedIn = this.user.isSignedIn; - this.isGrafanaAdmin = this.user.isGrafanaAdmin; - this.sidemenu = store.getBool('grafana.sidemenu'); - // events $rootScope.$on('toggle-sidemenu', function() { self.toggleSideMenu(); @@ -47,6 +40,12 @@ function (angular, _, store, config) { }, 50); }; + this.version = config.buildInfo.version; + this.lightTheme = false; + this.user = new User(); + this.isSignedIn = this.user.isSignedIn; + this.isGrafanaAdmin = this.user.isGrafanaAdmin; + this.sidemenu = store.getBool('grafana.sidemenu'); + this.isEditor = this.hasRole('Editor') || this.hasRole('Admin'); }); - }); diff --git a/public/test/specs/dashboardSrv-specs.js b/public/test/specs/dashboardSrv-specs.js index 19f81f1cc01..35d248888c7 100644 --- a/public/test/specs/dashboardSrv-specs.js +++ b/public/test/specs/dashboardSrv-specs.js @@ -185,10 +185,26 @@ define([ expect(model.annotations.list.length).to.be(0); expect(model.templating.list.length).to.be(0); }); - }); + describe('Given editable false dashboard', function() { + var model; + + beforeEach(function() { + model = _dashboardSrv.create({ + editable: false, + }); + }); + + it('Should set meta canEdit and canSave to false', function() { + expect(model.meta.canSave).to.be(false); + expect(model.meta.canEdit).to.be(false); + }); + + it('getSaveModelClone should remove meta', function() { + var clone = model.getSaveModelClone(); + expect(clone.meta).to.be(undefined); + }); + }); }); - - });