Bläddra i källkod

feat(invite): small progress

Torkel Ödegaard 10 år sedan
förälder
incheckning
2724cf5db8

+ 1 - 0
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)

+ 3 - 1
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"`

+ 1 - 1
pkg/services/sqlstore/sqlstore.goconvey

@@ -1 +1 @@
--timeout=10s
+-timeout=20s

+ 15 - 3
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
 }

+ 6 - 1
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
       });
     };
 

+ 3 - 3
public/app/features/org/partials/orgUsers.html

@@ -45,15 +45,15 @@
 						<th>Email</th>
 						<th>Name</th>
 						<th>Role</th>
-						<th>Created on</th>
-						<th>Invited by</th>
+						<th>Invited on</th>
+						<th>By</th>
 						<th></th>
 					</tr>
 					<tr ng-repeat="invite in pendingInvites">
 						<td>{{invite.email}}</td>
 						<td>{{invite.name}}</td>
 						<td>{{invite.role}}</td>
-						<td>{{invite.createdOn | date:'medium'}}</td>
+						<td>{{invite.createdOn | date:'shortDate'}}</td>
 						<td>{{invite.invitedBy}}</td>
 						<td style="width: 1%">
 							<a ng-click="removeInvite(invite)" class="btn btn-danger btn-mini">

+ 7 - 3
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();