Commit 737c29ec by Dan Cech

disable inviting new users to orgs if login form is disabled

parent 38cab50a
......@@ -142,6 +142,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
"ldapEnabled": setting.LdapEnabled,
"alertingEnabled": setting.AlertingEnabled,
"googleAnalyticsId": setting.GoogleAnalyticsId,
"disableLoginForm": setting.DisableLoginForm,
"buildInfo": map[string]interface{}{
"version": setting.BuildVersion,
"commit": setting.BuildCommit,
......
......@@ -94,6 +94,10 @@ func LoginApiPing(c *middleware.Context) {
}
func LoginPost(c *middleware.Context, cmd dtos.LoginCommand) Response {
if setting.DisableLoginForm {
return ApiError(401, "Login is disabled", nil)
}
authQuery := login.LoginUserQuery{
Username: cmd.User,
Password: cmd.Password,
......
......@@ -38,6 +38,10 @@ func AddOrgInvite(c *middleware.Context, inviteDto dtos.AddInviteForm) Response
if err != m.ErrUserNotFound {
return ApiError(500, "Failed to query db for existing user check", err)
}
if setting.DisableLoginForm {
return ApiError(401, "User could not be found", nil)
}
} else {
return inviteExistingUserToOrg(c, userQuery.Result, &inviteDto)
}
......
///<reference path="../../headers/common.d.ts" />
import angular from 'angular';
import config from 'app/core/config';
import _ from 'lodash';
import coreModule from '../../core/core_module';
import coreModule from 'app/core/core_module';
export class OrgUsersCtrl {
......@@ -19,6 +19,8 @@ export class OrgUsersCtrl {
};
this.get();
this.editor = { index: 0 };
$scope.disableInvites = config.disableLoginForm;
}
get() {
......@@ -69,17 +71,20 @@ export class OrgUsersCtrl {
openInviteModal() {
var modalScope = this.$scope.$new();
modalScope.invitesSent = function() {
modalScope.invitesSent = () => {
this.get();
};
var src = !this.$scope.disableInvites
? 'public/app/features/org/partials/invite.html'
: 'public/app/features/org/partials/addUser.html';
this.$scope.appEvent('show-modal', {
src: 'public/app/features/org/partials/invite.html',
src: src,
modalClass: 'invite-modal',
scope: modalScope
});
}
}
coreModule.controller('OrgUsersCtrl', OrgUsersCtrl);
<div class="modal-body" ng-controller="UserInviteCtrl" ng-init="init()">
<div class="modal-header">
<h2 class="modal-header-title">
Add Users
</h2>
<a class="modal-header-close" ng-click="dismiss();">
<i class="fa fa-remove"></i>
</a>
</div>
<div class="modal-content">
<div class="modal-tagline p-b-2">
Add existing Grafana users to the organization
<span class="highlight-word">{{contextSrv.user.orgName}}</span>
</div>
<form name="inviteForm">
<div class="gf-form-group">
<div class="gf-form-inline" ng-repeat="invite in invites">
<div class="gf-form max-width-21">
<span class="gf-form-label">Email or Username</span>
<input type="text" ng-model="invite.loginOrEmail" required class="gf-form-input" placeholder="email@test.com">
</div>
<div class="gf-form max-width-10">
<span class="gf-form-label">Role</span>
<select ng-model="invite.role" class="gf-form-input" ng-options="f for f in ['Viewer', 'Editor', 'Read Only Editor', 'Admin']">
</select>
</div>
<div class="gf-form gf-size-auto">
<a class="gf-form-label pointer" tabindex="1" ng-click="removeInvite(invite)">
<i class="fa fa-remove"></i>
</a>
</div>
</div>
</div>
<div class="gf-form-inline gf-form-group">
<div class="gf-form">
<a class="btn btn-inverse btn-small" ng-click="addInvite()">
<i class="fa fa-plus"></i>
Add another
</a>
</div>
</div>
<div class="gf-form-button-row">
<button type="submit" class="btn btn-success" ng-click="sendInvites();">Add Users</button>
<a class="btn-text" ng-click="dismiss()">Cancel</a>
</div>
<div class="clearfix"></div>
</form>
</div>
</div>
......@@ -6,10 +6,14 @@
<h1>Organization users</h1>
<div class="page-header-tabs">
<button class="btn btn-success" ng-click="ctrl.openInviteModal()">
<button class="btn btn-success" ng-click="ctrl.openInviteModal()" ng-show="!disableInvites">
<i class="fa fa-plus"></i>
Add or Invite
</button>
<button class="btn btn-success" ng-click="ctrl.openInviteModal()" ng-show="!!disableInvites">
<i class="fa fa-plus"></i>
Add
</button>
<ul class="gf-tabs">
<li class="gf-tabs-item">
......@@ -17,7 +21,7 @@
Users ({{ctrl.users.length}})
</a>
</li>
<li class="gf-tabs-item">
<li class="gf-tabs-item" ng-show="!disableInvites">
<a class="gf-tabs-link" ng-click="ctrl.editor.index = 1" ng-class="{active: ctrl.editor.index === 1}">
Pending Invitations ({{ctrl.pendingInvites.length}})
</a>
......@@ -52,7 +56,7 @@
</table>
</div>
<div ng-if="ctrl.editor.index === 1" >
<div ng-if="ctrl.editor.index === 1 && !disableInvites">
<table class="filter-table form-inline">
<thead>
<tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment