From 737c29ec8c650589be5bbebbf92fc3d6bf059e45 Mon Sep 17 00:00:00 2001 From: Dan Cech Date: Fri, 17 Mar 2017 16:35:05 -0400 Subject: [PATCH 1/2] disable inviting new users to orgs if login form is disabled --- pkg/api/frontendsettings.go | 1 + pkg/api/login.go | 4 ++ pkg/api/org_invite.go | 4 ++ public/app/features/org/org_users_ctrl.ts | 15 +++-- public/app/features/org/partials/addUser.html | 55 +++++++++++++++++++ .../app/features/org/partials/orgUsers.html | 10 +++- 6 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 public/app/features/org/partials/addUser.html diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index c0e27897ff4..328b8abbc5f 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -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, diff --git a/pkg/api/login.go b/pkg/api/login.go index 8fbe414c08c..8ab76c7b48d 100644 --- a/pkg/api/login.go +++ b/pkg/api/login.go @@ -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, diff --git a/pkg/api/org_invite.go b/pkg/api/org_invite.go index 8d916677ed2..9e85808950f 100644 --- a/pkg/api/org_invite.go +++ b/pkg/api/org_invite.go @@ -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) } diff --git a/public/app/features/org/org_users_ctrl.ts b/public/app/features/org/org_users_ctrl.ts index 9e70328f345..d6b594037b6 100644 --- a/public/app/features/org/org_users_ctrl.ts +++ b/public/app/features/org/org_users_ctrl.ts @@ -1,8 +1,8 @@ /// -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); diff --git a/public/app/features/org/partials/addUser.html b/public/app/features/org/partials/addUser.html new file mode 100644 index 00000000000..53fe7884df9 --- /dev/null +++ b/public/app/features/org/partials/addUser.html @@ -0,0 +1,55 @@ + diff --git a/public/app/features/org/partials/orgUsers.html b/public/app/features/org/partials/orgUsers.html index 36b00b3bc03..f40a8484337 100644 --- a/public/app/features/org/partials/orgUsers.html +++ b/public/app/features/org/partials/orgUsers.html @@ -6,10 +6,14 @@

Organization users

- +
-
+
From 6f324cd7942df3165d02aeeb025151b2e3e509ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 20 Mar 2017 11:18:29 +0100 Subject: [PATCH 2/2] refactor: minor refactorings of #7876 --- public/app/features/org/org_users_ctrl.ts | 21 +++++++------------ .../partials/{addUser.html => add_user.html} | 0 .../app/features/org/partials/orgUsers.html | 12 ++++------- 3 files changed, 12 insertions(+), 21 deletions(-) rename public/app/features/org/partials/{addUser.html => add_user.html} (100%) diff --git a/public/app/features/org/org_users_ctrl.ts b/public/app/features/org/org_users_ctrl.ts index d6b594037b6..6181edddc9a 100644 --- a/public/app/features/org/org_users_ctrl.ts +++ b/public/app/features/org/org_users_ctrl.ts @@ -10,6 +10,7 @@ export class OrgUsersCtrl { users: any; pendingInvites: any; editor: any; + showInviteUI: boolean; /** @ngInject */ constructor(private $scope, private $http, private backendSrv) { @@ -17,10 +18,10 @@ export class OrgUsersCtrl { loginOrEmail: '', role: 'Viewer', }; + this.get(); this.editor = { index: 0 }; - - $scope.disableInvites = config.disableLoginForm; + this.showInviteUI = config.disableLoginForm === false; } get() { @@ -52,17 +53,13 @@ export class OrgUsersCtrl { removeUserConfirmed(user) { this.backendSrv.delete('/api/org/users/' + user.userId) - .then(() => { - this.get(); - }); + .then(this.get.bind(this)); } revokeInvite(invite, evt) { evt.stopPropagation(); this.backendSrv.patch('/api/org/invites/' + invite.code + '/revoke') - .then(() => { - this.get(); - }); + .then(this.get.bind(this)); } copyInviteToClipboard(evt) { @@ -71,13 +68,11 @@ export class OrgUsersCtrl { openInviteModal() { var modalScope = this.$scope.$new(); - modalScope.invitesSent = () => { - this.get(); - }; + modalScope.invitesSent = this.get.bind(this); - var src = !this.$scope.disableInvites + var src = this.showInviteUI ? 'public/app/features/org/partials/invite.html' - : 'public/app/features/org/partials/addUser.html'; + : 'public/app/features/org/partials/add_user.html'; this.$scope.appEvent('show-modal', { src: src, diff --git a/public/app/features/org/partials/addUser.html b/public/app/features/org/partials/add_user.html similarity index 100% rename from public/app/features/org/partials/addUser.html rename to public/app/features/org/partials/add_user.html diff --git a/public/app/features/org/partials/orgUsers.html b/public/app/features/org/partials/orgUsers.html index f40a8484337..8d348721301 100644 --- a/public/app/features/org/partials/orgUsers.html +++ b/public/app/features/org/partials/orgUsers.html @@ -6,13 +6,9 @@

Organization users

- -
-
+