From abef94b0da968060343173d818a8468e4b7127fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 11 Oct 2018 12:36:04 +0200 Subject: [PATCH] made it possible to have frontend code in symlinked folders that can add routes --- .gitignore | 1 + pkg/api/api.go | 8 +-- pkg/middleware/middleware.go | 7 +++ public/app/app.ts | 6 ++ public/app/extensions/index.ts | 4 -- public/app/extensions/test/test.ts | 3 - public/app/features/admin/index.ts | 19 ------- .../features/admin/partials/licensing.html | 56 ------------------- public/app/routes/registry.ts | 15 +++++ public/app/routes/routes.ts | 9 +-- 10 files changed, 36 insertions(+), 92 deletions(-) delete mode 100644 public/app/extensions/index.ts delete mode 100644 public/app/extensions/test/test.ts delete mode 100644 public/app/features/admin/partials/licensing.html create mode 100644 public/app/routes/registry.ts diff --git a/.gitignore b/.gitignore index 20e8fffb3b1..a78b4a15da5 100644 --- a/.gitignore +++ b/.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 diff --git a/pkg/api/api.go b/pkg/api/api.go index 39b332aeb9f..602f5a8d596 100644 --- a/pkg/api/api.go +++ b/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 diff --git a/pkg/middleware/middleware.go b/pkg/middleware/middleware.go index 475dce089b1..3e83a60f94b 100644 --- a/pkg/middleware/middleware.go +++ b/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{ diff --git a/public/app/app.ts b/public/app/app.ts index 8e30747072e..7fed8d5a44b 100644 --- a/public/app/app.ts +++ b/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 { diff --git a/public/app/extensions/index.ts b/public/app/extensions/index.ts deleted file mode 100644 index d265303a6ee..00000000000 --- a/public/app/extensions/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -let components = (require as any).context('.', true, /\.tsx?/); -components.keys().forEach(key => { - console.log('extension component', components(key)); -}); diff --git a/public/app/extensions/test/test.ts b/public/app/extensions/test/test.ts deleted file mode 100644 index be4fd52ed2d..00000000000 --- a/public/app/extensions/test/test.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class Tester {} - -console.log('Tester'); diff --git a/public/app/features/admin/index.ts b/public/app/features/admin/index.ts index 44628deb94f..7d06155b6f8 100644 --- a/public/app/features/admin/index.ts +++ b/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); -} diff --git a/public/app/features/admin/partials/licensing.html b/public/app/features/admin/partials/licensing.html deleted file mode 100644 index 8ff4836bc4a..00000000000 --- a/public/app/features/admin/partials/licensing.html +++ /dev/null @@ -1,56 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
License Details
License ID{{token.lid}} (View Details)
Licensed URL{{token.sub}}
Company{{token.company}}
Products -
{{product}}
-
Max Users{{token.maxUsers}}
License Issued{{token.nbf*1000 | date:'medium'}}
License Expires{{token.lexp*1000 | date:'medium'}}
Token Details
Token ID{{token.jti}}
Token Issued{{token.iat*1000 | date:'medium'}}
Token Expires{{token.exp*1000 | date:'medium'}}
-
diff --git a/public/app/routes/registry.ts b/public/app/routes/registry.ts new file mode 100644 index 00000000000..19699ca738b --- /dev/null +++ b/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); +} diff --git a/public/app/routes/routes.ts b/public/app/routes/routes.ts index 2ef7efffa85..e94275f6aef 100644 --- a/public/app/routes/routes.ts +++ b/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); }