Commit 64b7b2df authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

hide logout button if no authenticated user or no auth configured

parent 06e422b5
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -4,7 +4,8 @@ import javax.inject.Inject

import controllers.auth.AuthenticationModule
import elastic.ElasticClient
import models.{CerebroResponse, ElasticServer}
import models.CerebroResponse
import play.api.libs.json.{JsObject, Json}

import scala.concurrent.ExecutionContext.Implicits.global

@@ -13,7 +14,10 @@ class NavbarController @Inject()(val authentication: AuthenticationModule,

  def index = process { request =>
    client.clusterHealth(request.target).map { response =>
      CerebroResponse(response.status, response.body)
      val body = request.user.fold(response.body) { user =>
        response.body.as[JsObject] ++ Json.obj("username" -> user.name)
      }
      CerebroResponse(response.status, body)
    }
  }

+5 −5
Original line number Diff line number Diff line
@@ -35,11 +35,11 @@ auth {
//      method  = "simple"
//      user-domain = "domain.com"
//    }
  type: basic
  settings: {
    username = "admin"
    password = "1234"
  }
//  type: basic
//  settings: {
//    username = "admin"
//    password = "1234"
//  }
}

# Logger
+2 −0
Original line number Diff line number Diff line
@@ -651,6 +651,7 @@ angular.module('cerebro').controller('NavbarController', ['$scope', '$http',
    $scope.status = undefined;
    $scope.cluster_name = undefined;
    $scope.host = undefined;
    $scope.username = undefined;

    $scope.$watch(
      function() {
@@ -661,6 +662,7 @@ angular.module('cerebro').controller('NavbarController', ['$scope', '$http',
          function(data) {
            $scope.status = data.status;
            $scope.cluster_name = data.cluster_name;
            $scope.username = data.username;
            $scope.host = DataService.getHost();
            PageService.setup($scope.cluster_name, $scope.status);
          },
+4 −4
Original line number Diff line number Diff line
@@ -64,17 +64,17 @@
      <ul class="nav navbar-nav navbar-right">
        <li class="hidden-xs">
          <a class="nav-item nav-link">
            <span ng-hide="host"><i>Not connected</i></span>
            <span ng-show="host">{{host}}</span>
          </a>
        </li>
        <li>
          <a href="#connect" class="nav-item nav-link hidden-xs"><i class="fa fa-plug"></i></a>
          <a href="#connect" class="nav-item nav-link visible-xs">connect...</a>
        </li>
        <li>
          <form action="/auth/logout" method="POST">
            <button class="btn btn-lg btn-link" type="submit"><i class="fa fa-power-off"></i></button>
          <form action="/auth/logout" method="POST" ng-show="username">
            <button class="btn btn-lg btn-link" type="submit">
              <i class="fa fa-power-off"></i>
            </button>
          </form>
        </li>
      </ul>
+2 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ angular.module('cerebro').controller('NavbarController', ['$scope', '$http',
    $scope.status = undefined;
    $scope.cluster_name = undefined;
    $scope.host = undefined;
    $scope.username = undefined;

    $scope.$watch(
      function() {
@@ -15,6 +16,7 @@ angular.module('cerebro').controller('NavbarController', ['$scope', '$http',
          function(data) {
            $scope.status = data.status;
            $scope.cluster_name = data.cluster_name;
            $scope.username = data.username;
            $scope.host = DataService.getHost();
            PageService.setup($scope.cluster_name, $scope.status);
          },