feat(invite): small progress

This commit is contained in:
Torkel Ödegaard 2015-07-17 14:42:49 +02:00
parent 0ffcce1b5d
commit 2724cf5db8
7 changed files with 36 additions and 12 deletions

View File

@ -30,6 +30,7 @@ func AddOrgInvite(c *middleware.Context, inviteDto dtos.AddInviteForm) Response
cmd.IsInvite = true cmd.IsInvite = true
cmd.InvitedByUserId = c.UserId cmd.InvitedByUserId = c.UserId
cmd.Code = util.GetRandomString(30) cmd.Code = util.GetRandomString(30)
cmd.Role = inviteDto.Role
if err := bus.Dispatch(&cmd); err != nil { if err := bus.Dispatch(&cmd); err != nil {
return ApiError(500, "Failed to save invite to database", err) return ApiError(500, "Failed to save invite to database", err)

View File

@ -17,7 +17,7 @@ type TempUser struct {
Version int Version int
Email string Email string
Name string Name string
Role string Role RoleType
IsInvite bool IsInvite bool
InvitedByUserId int64 InvitedByUserId int64
@ -39,6 +39,7 @@ type CreateTempUserCommand struct {
IsInvite bool IsInvite bool
InvitedByUserId int64 InvitedByUserId int64
Code string Code string
Role RoleType
Result *TempUser Result *TempUser
} }
@ -54,6 +55,7 @@ type TempUserDTO struct {
Name string `json:"name"` Name string `json:"name"`
Email string `json:"email"` Email string `json:"email"`
Role string `json:"role"` Role string `json:"role"`
InvitedBy string `json:"invitedBy"`
EmailSent bool `json:"emailSent"` EmailSent bool `json:"emailSent"`
EmailSentOn time.Time `json:"emailSentOn"` EmailSentOn time.Time `json:"emailSentOn"`
Created time.Time `json:"createdOn"` Created time.Time `json:"createdOn"`

View File

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

View File

@ -21,6 +21,7 @@ func CreateTempUser(cmd *m.CreateTempUserCommand) error {
Name: cmd.Name, Name: cmd.Name,
OrgId: cmd.OrgId, OrgId: cmd.OrgId,
Code: cmd.Code, Code: cmd.Code,
Role: cmd.Role,
IsInvite: cmd.IsInvite, IsInvite: cmd.IsInvite,
InvitedByUserId: cmd.InvitedByUserId, InvitedByUserId: cmd.InvitedByUserId,
Created: time.Now(), Created: time.Now(),
@ -39,10 +40,21 @@ func CreateTempUser(cmd *m.CreateTempUserCommand) error {
} }
func GetTempUsersForOrg(query *m.GetTempUsersForOrgQuery) error { func GetTempUsersForOrg(query *m.GetTempUsersForOrgQuery) error {
query.Result = make([]*m.TempUserDTO, 0) var rawSql = `SELECT
sess := x.Table("temp_user") tu.id as id,
sess.Where("org_id=?", query.OrgId) 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) err := sess.Find(&query.Result)
return err return err
} }

View File

@ -44,10 +44,15 @@ function (angular) {
}; };
$scope.openInviteModal = function() { $scope.openInviteModal = function() {
var modalScope = $scope.$new();
modalScope.invitesSent = function() {
$scope.get();
};
$scope.appEvent('show-modal', { $scope.appEvent('show-modal', {
src: './app/features/org/partials/invite.html', src: './app/features/org/partials/invite.html',
modalClass: 'modal-no-header invite-modal', modalClass: 'modal-no-header invite-modal',
scope: $scope.$new() scope: modalScope
}); });
}; };

View File

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

View File

@ -7,7 +7,7 @@ function (angular, _) {
var module = angular.module('grafana.controllers'); var module = angular.module('grafana.controllers');
module.controller('UserInviteCtrl', function($scope, backendSrv) { module.controller('UserInviteCtrl', function($scope, backendSrv, $q) {
$scope.invites = [ $scope.invites = [
{name: '', email: '', role: 'Editor'}, {name: '', email: '', role: 'Editor'},
@ -27,8 +27,12 @@ function (angular, _) {
$scope.sendInvites = function() { $scope.sendInvites = function() {
if (!$scope.inviteForm.$valid) { return; } if (!$scope.inviteForm.$valid) { return; }
_.each($scope.invites, function(invite) { var promises = _.map($scope.invites, function(invite) {
backendSrv.post('/api/org/invites', invite); return backendSrv.post('/api/org/invites', invite);
});
$q.all(promises).then(function() {
$scope.invitesSent();
}); });
$scope.dismiss(); $scope.dismiss();