diff --git a/pkg/api/org_invite.go b/pkg/api/org_invite.go index 25740d00f1b..d0477c33355 100644 --- a/pkg/api/org_invite.go +++ b/pkg/api/org_invite.go @@ -30,6 +30,7 @@ func AddOrgInvite(c *middleware.Context, inviteDto dtos.AddInviteForm) Response cmd.IsInvite = true cmd.InvitedByUserId = c.UserId cmd.Code = util.GetRandomString(30) + cmd.Role = inviteDto.Role if err := bus.Dispatch(&cmd); err != nil { return ApiError(500, "Failed to save invite to database", err) diff --git a/pkg/models/temp_user.go b/pkg/models/temp_user.go index a1dd69a98e7..8e06ade3cb2 100644 --- a/pkg/models/temp_user.go +++ b/pkg/models/temp_user.go @@ -17,7 +17,7 @@ type TempUser struct { Version int Email string Name string - Role string + Role RoleType IsInvite bool InvitedByUserId int64 @@ -39,6 +39,7 @@ type CreateTempUserCommand struct { IsInvite bool InvitedByUserId int64 Code string + Role RoleType Result *TempUser } @@ -54,6 +55,7 @@ type TempUserDTO struct { Name string `json:"name"` Email string `json:"email"` Role string `json:"role"` + InvitedBy string `json:"invitedBy"` EmailSent bool `json:"emailSent"` EmailSentOn time.Time `json:"emailSentOn"` Created time.Time `json:"createdOn"` diff --git a/pkg/services/sqlstore/sqlstore.goconvey b/pkg/services/sqlstore/sqlstore.goconvey index 92feb5268a5..8ca30789e4a 100644 --- a/pkg/services/sqlstore/sqlstore.goconvey +++ b/pkg/services/sqlstore/sqlstore.goconvey @@ -1 +1 @@ --timeout=10s +-timeout=20s diff --git a/pkg/services/sqlstore/temp_user.go b/pkg/services/sqlstore/temp_user.go index 511cc1b1afc..c80e015fa0f 100644 --- a/pkg/services/sqlstore/temp_user.go +++ b/pkg/services/sqlstore/temp_user.go @@ -21,6 +21,7 @@ func CreateTempUser(cmd *m.CreateTempUserCommand) error { Name: cmd.Name, OrgId: cmd.OrgId, Code: cmd.Code, + Role: cmd.Role, IsInvite: cmd.IsInvite, InvitedByUserId: cmd.InvitedByUserId, Created: time.Now(), @@ -39,10 +40,21 @@ func CreateTempUser(cmd *m.CreateTempUserCommand) error { } func GetTempUsersForOrg(query *m.GetTempUsersForOrgQuery) error { - query.Result = make([]*m.TempUserDTO, 0) - sess := x.Table("temp_user") - sess.Where("org_id=?", query.OrgId) + var rawSql = `SELECT + tu.id as id, + tu.email as email, + tu.name as name, + tu.role as role, + tu.email_sent as email_sent, + tu.email_sent_on as email_sent_on, + tu.created as created, + u.login as invited_by + FROM ` + dialect.Quote("temp_user") + ` as tu + LEFT OUTER JOIN ` + dialect.Quote("user") + ` as u on u.id = tu.invited_by_user_id + WHERE tu.org_id=? ORDER BY tu.created desc` + query.Result = make([]*m.TempUserDTO, 0) + sess := x.Sql(rawSql, query.OrgId) err := sess.Find(&query.Result) return err } diff --git a/public/app/features/org/orgUsersCtrl.js b/public/app/features/org/orgUsersCtrl.js index 1a743c9713e..ea3d97d7337 100644 --- a/public/app/features/org/orgUsersCtrl.js +++ b/public/app/features/org/orgUsersCtrl.js @@ -44,10 +44,15 @@ function (angular) { }; $scope.openInviteModal = function() { + var modalScope = $scope.$new(); + modalScope.invitesSent = function() { + $scope.get(); + }; + $scope.appEvent('show-modal', { src: './app/features/org/partials/invite.html', modalClass: 'modal-no-header invite-modal', - scope: $scope.$new() + scope: modalScope }); }; diff --git a/public/app/features/org/partials/orgUsers.html b/public/app/features/org/partials/orgUsers.html index d8422502407..7c8c7e1dbc9 100644 --- a/public/app/features/org/partials/orgUsers.html +++ b/public/app/features/org/partials/orgUsers.html @@ -45,15 +45,15 @@ Email Name Role - Created on - Invited by + Invited on + By {{invite.email}} {{invite.name}} {{invite.role}} - {{invite.createdOn | date:'medium'}} + {{invite.createdOn | date:'shortDate'}} {{invite.invitedBy}} diff --git a/public/app/features/org/userInviteCtrl.js b/public/app/features/org/userInviteCtrl.js index 26ec89ddc94..63f7fcc00a3 100644 --- a/public/app/features/org/userInviteCtrl.js +++ b/public/app/features/org/userInviteCtrl.js @@ -7,7 +7,7 @@ function (angular, _) { var module = angular.module('grafana.controllers'); - module.controller('UserInviteCtrl', function($scope, backendSrv) { + module.controller('UserInviteCtrl', function($scope, backendSrv, $q) { $scope.invites = [ {name: '', email: '', role: 'Editor'}, @@ -27,8 +27,12 @@ function (angular, _) { $scope.sendInvites = function() { if (!$scope.inviteForm.$valid) { return; } - _.each($scope.invites, function(invite) { - backendSrv.post('/api/org/invites', invite); + var promises = _.map($scope.invites, function(invite) { + return backendSrv.post('/api/org/invites', invite); + }); + + $q.all(promises).then(function() { + $scope.invitesSent(); }); $scope.dismiss();