ソースを参照

made it possible to have frontend code in symlinked folders that can add routes

Torkel Ödegaard 7 年 前
コミット
abef94b0da

+ 1 - 0
.gitignore

@@ -54,6 +54,7 @@ profile.cov
 /pkg/cmd/grafana-server/grafana-server
 /pkg/cmd/grafana-server/debug
 /pkg/extensions
+/public/app/enterprise
 debug.test
 /examples/*/dist
 /packaging/**/*.rpm

+ 4 - 4
pkg/api/api.go

@@ -10,10 +10,10 @@ import (
 )
 
 func (hs *HTTPServer) registerRoutes() {
-	reqSignedIn := middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true})
-	reqGrafanaAdmin := middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true, ReqGrafanaAdmin: true})
-	reqEditorRole := middleware.RoleAuth(m.ROLE_EDITOR, m.ROLE_ADMIN)
-	reqOrgAdmin := middleware.RoleAuth(m.ROLE_ADMIN)
+	reqSignedIn := middleware.ReqSignedIn
+	reqGrafanaAdmin := middleware.ReqGrafanaAdmin
+	reqEditorRole := middleware.ReqEditorRole
+	reqOrgAdmin := middleware.ReqOrgAdmin
 	redirectFromLegacyDashboardURL := middleware.RedirectFromLegacyDashboardURL()
 	redirectFromLegacyDashboardSoloURL := middleware.RedirectFromLegacyDashboardSoloURL()
 	quota := middleware.Quota

+ 7 - 0
pkg/middleware/middleware.go

@@ -14,6 +14,13 @@ import (
 	"github.com/grafana/grafana/pkg/util"
 )
 
+var (
+	ReqGrafanaAdmin = Auth(&AuthOptions{ReqSignedIn: true, ReqGrafanaAdmin: true})
+	ReqSignedIn     = Auth(&AuthOptions{ReqSignedIn: true})
+	ReqEditorRole   = RoleAuth(m.ROLE_EDITOR, m.ROLE_ADMIN)
+	ReqOrgAdmin     = RoleAuth(m.ROLE_ADMIN)
+)
+
 func GetContextHandler() macaron.Handler {
 	return func(c *macaron.Context) {
 		ctx := &m.ReqContext{

+ 6 - 0
public/app/app.ts

@@ -29,6 +29,12 @@ _.move = (array, fromIndex, toIndex) => {
 import { coreModule, registerAngularDirectives } from './core/core';
 import { setupAngularRoutes } from './routes/routes';
 
+// import enterprise frontend
+const enterpriseIndex = (require as any).context('.', true, /enterprise\/index.ts/);
+enterpriseIndex.keys().forEach(key => {
+  enterpriseIndex(key);
+});
+
 declare var System: any;
 
 export class GrafanaApp {

+ 0 - 4
public/app/extensions/index.ts

@@ -1,4 +0,0 @@
-let components = (require as any).context('.', true, /\.tsx?/);
-components.keys().forEach(key => {
-  console.log('extension component', components(key));
-});

+ 0 - 3
public/app/extensions/test/test.ts

@@ -1,3 +0,0 @@
-export class Tester {}
-
-console.log('Tester');

+ 0 - 19
public/app/features/admin/index.ts

@@ -4,7 +4,6 @@ import AdminListOrgsCtrl from './AdminListOrgsCtrl';
 import AdminEditOrgCtrl from './AdminEditOrgCtrl';
 import StyleGuideCtrl from './StyleGuideCtrl';
 
-import config from 'app/core/config';
 import coreModule from 'app/core/core_module';
 
 class AdminSettingsCtrl {
@@ -36,21 +35,3 @@ coreModule.controller('AdminEditOrgCtrl', AdminEditOrgCtrl);
 coreModule.controller('AdminSettingsCtrl', AdminSettingsCtrl);
 coreModule.controller('AdminHomeCtrl', AdminHomeCtrl);
 coreModule.controller('StyleGuideCtrl', StyleGuideCtrl);
-
-if (config.buildInfo.isEnterprise) {
-  class AdminLicensingCtrl {
-    navModel: any;
-
-    /** @ngInject */
-    constructor($scope, backendSrv, navModelSrv) {
-      this.navModel = navModelSrv.getNav('cfg', 'admin', 'licensing', 1);
-
-      backendSrv.get('/api/licensing/token').then(token => {
-        token.maxUsers = token.max_users >= 0 ? token.max_users : 'Unlimited';
-        $scope.token = token;
-      });
-    }
-  }
-
-  coreModule.controller('AdminLicensingCtrl', AdminLicensingCtrl);
-}

+ 0 - 56
public/app/features/admin/partials/licensing.html

@@ -1,56 +0,0 @@
-<page-header model="ctrl.navModel"></page-header>
-
-<div class="page-container page-body">
-	<table class="filter-table form-inline">
-		<tbody>
-			<tr>
-				<td colspan="2" class="admin-settings-section">License Details</td>
-			</tr>
-			<tr>
-				<td>License ID</td>
-				<td>{{token.lid}} (<a href="{{token.iss}}/licenses/{{token.lid}}" target="_blank" rel="noopener noreferer">View Details</a>)</td>
-			</tr>
-			<tr>
-				<td>Licensed URL</td>
-				<td><a href="{{token.sub}}" target="_blank" rel="noopener noreferer">{{token.sub}}</a></td>
-			</tr>
-			<tr>
-				<td>Company</td>
-				<td>{{token.company}}</td>
-			</tr>
-			<tr>
-				<td>Products</td>
-				<td>
-					<div ng-repeat="product in token.prod">{{product}}</div>
-				</td>
-			</tr>
-			<tr>
-				<td>Max Users</td>
-				<td>{{token.maxUsers}}</td>
-			</tr>
-			<tr>
-				<td>License Issued</td>
-				<td>{{token.nbf*1000 | date:'medium'}}</td>
-			</tr>
-			<tr>
-				<td>License Expires</td>
-				<td>{{token.lexp*1000 | date:'medium'}}</td>
-			</tr>
-			<tr>
-				<td colspan="2" class="admin-settings-section">Token Details</td>
-			</tr>
-			<tr>
-				<td>Token ID</td>
-				<td>{{token.jti}}</td>
-			</tr>
-			<tr>
-				<td>Token Issued</td>
-				<td>{{token.iat*1000 | date:'medium'}}</td>
-			</tr>
-			<tr>
-				<td>Token Expires</td>
-				<td>{{token.exp*1000 | date:'medium'}}</td>
-			</tr>
-		</tbody>
-	</table>
-</div>

+ 15 - 0
public/app/routes/registry.ts

@@ -0,0 +1,15 @@
+interface RegisterRoutesHandler {
+  ($routeProvider): any;
+}
+
+const handlers: RegisterRoutesHandler[] = [];
+
+export function applyRouteRegistrationHandlers($routeProvider) {
+  for (const handler of handlers) {
+    handler($routeProvider);
+  }
+}
+
+export function addRouteRegistrationHandler(fn: RegisterRoutesHandler) {
+  handlers.push(fn);
+}

+ 3 - 6
public/app/routes/routes.ts

@@ -1,6 +1,6 @@
 import './dashboard_loaders';
 import './ReactContainer';
-import '../extensions';
+import { applyRouteRegistrationHandlers } from './registry';
 
 import ServerStats from 'app/features/admin/ServerStats';
 import AlertRuleList from 'app/features/alerting/AlertRuleList';
@@ -226,11 +226,6 @@ export function setupAngularRoutes($routeProvider, $locationProvider) {
         component: () => ServerStats,
       },
     })
-    .when('/admin/licensing', {
-      templateUrl: 'public/app/features/admin/partials/licensing.html',
-      controller: 'AdminLicensingCtrl',
-      controllerAs: 'ctrl',
-    })
     // LOGIN / SIGNUP
     .when('/login', {
       templateUrl: 'public/app/partials/login.html',
@@ -312,4 +307,6 @@ export function setupAngularRoutes($routeProvider, $locationProvider) {
       templateUrl: 'public/app/partials/error.html',
       controller: 'ErrorCtrl',
     });
+
+  applyRouteRegistrationHandlers($routeProvider);
 }