Просмотр исходного кода

fix: dont show settings for viewers

Torkel Ödegaard 8 лет назад
Родитель
Сommit
d1e0e36996

+ 2 - 0
public/app/features/dashboard/dashboard_model.ts

@@ -117,6 +117,8 @@ export class DashboardModel {
     meta.canSave = meta.canSave !== false;
     meta.canStar = meta.canStar !== false;
     meta.canEdit = meta.canEdit !== false;
+    meta.showSettings = meta.canEdit;
+    meta.canMakeEditable = meta.canSave && !this.editable;
 
     if (!this.editable) {
       meta.canEdit = false;

+ 1 - 1
public/app/features/dashboard/dashnav/dashnav.html

@@ -37,7 +37,7 @@
 			<i class="fa fa-link"></i>
 		</button>
 
-		<button class="btn navbar-button navbar-button--settings" ng-click="ctrl.toggleSettings()" bs-tooltip="'Settings'" data-placement="bottom">
+		<button class="btn navbar-button navbar-button--settings" ng-click="ctrl.toggleSettings()" bs-tooltip="'Settings'" data-placement="bottom" ng-show="ctrl.dashboard.meta.showSettings">
 			<i class="fa fa-cog"></i>
 		</button>
 	</div>

+ 6 - 3
public/app/features/dashboard/settings/settings.ts

@@ -35,6 +35,7 @@ export class SettingsCtrl {
 
   buildSectionList() {
     this.sections = [];
+
     if (this.dashboard.meta.canEdit) {
       this.sections.push({ title: 'General', id: 'settings', icon: 'gicon gicon-preferences' });
       this.sections.push({ title: 'Annotations', id: 'annotations', icon: 'gicon gicon-annotation' });
@@ -46,9 +47,8 @@ export class SettingsCtrl {
       this.sections.push({ title: 'Versions', id: 'versions', icon: 'fa fa-fw fa-history' });
     }
 
-    if (contextSrv.isEditor && !this.dashboard.editable) {
+    if (this.dashboard.meta.canMakeEditable) {
       this.sections.push({ title: 'Make Editable', icon: 'fa fa-fw fa-edit', id: 'make_editable' });
-      this.viewId = 'make_editable';
     }
 
     this.sections.push({ title: 'View JSON', id: 'view_json', icon: 'gicon gicon-json' });
@@ -69,11 +69,14 @@ export class SettingsCtrl {
       this.json = JSON.stringify(this.dashboard.getSaveModelClone(), null, 2);
     }
 
+    if (this.viewId === 'settings' && this.dashboard.meta.canMakeEditable) {
+      this.viewId = 'make_editable';
+    }
+
     const currentSection = _.find(this.sections, { id: this.viewId });
     if (!currentSection) {
       this.sections.unshift({ title: 'Not found', id: '404', icon: 'fa fa-fw fa-warning' });
       this.viewId = '404';
-      return;
     }
   }