feat(invite): more work on invite, basic creation works, added new tab directive from angular-ui and made new tab style, #2353
This commit is contained in:
@@ -89,6 +89,10 @@ func Register(r *macaron.Macaron) {
|
||||
r.Get("/users", wrap(GetOrgUsersForCurrentOrg))
|
||||
r.Patch("/users/:userId", bind(m.UpdateOrgUserCommand{}), wrap(UpdateOrgUserForCurrentOrg))
|
||||
r.Delete("/users/:userId", wrap(RemoveOrgUserForCurrentOrg))
|
||||
|
||||
// invites
|
||||
r.Get("/invites", wrap(GetPendingOrgInvites))
|
||||
r.Post("/invites", bind(dtos.AddInviteForm{}), wrap(AddOrgInvite))
|
||||
}, regOrgAdmin)
|
||||
|
||||
// create new org
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package dtos
|
||||
|
||||
import m "github.com/grafana/grafana/pkg/models"
|
||||
|
||||
type AddInviteForm struct {
|
||||
Email string `json:"email" binding:"Required"`
|
||||
Name string `json:"name"`
|
||||
Role m.RoleType `json:"role" binding:"Required"`
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
func GetPendingOrgInvites(c *middleware.Context) Response {
|
||||
query := m.GetTempUsersForOrgQuery{OrgId: c.OrgId}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
return ApiError(500, "Failed to get invites from db", err)
|
||||
}
|
||||
|
||||
return Json(200, query.Result)
|
||||
}
|
||||
|
||||
func AddOrgInvite(c *middleware.Context, inviteDto dtos.AddInviteForm) Response {
|
||||
if !inviteDto.Role.IsValid() {
|
||||
return ApiError(400, "Invalid role specified", nil)
|
||||
}
|
||||
|
||||
cmd := m.CreateTempUserCommand{}
|
||||
cmd.OrgId = c.OrgId
|
||||
cmd.Email = inviteDto.Email
|
||||
cmd.Name = inviteDto.Name
|
||||
cmd.IsInvite = true
|
||||
cmd.InvitedByUserId = c.UserId
|
||||
cmd.Code = util.GetRandomString(30)
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
return ApiError(500, "Failed to save invite to database", err)
|
||||
}
|
||||
|
||||
return ApiSuccess("ok, done!")
|
||||
}
|
||||
+15
-13
@@ -10,15 +10,16 @@ var (
|
||||
ErrTempUserNotFound = errors.New("User not found")
|
||||
)
|
||||
|
||||
// TempUser holds data for org invites and new sign ups
|
||||
// TempUser holds data for org invites and unconfirmed sign ups
|
||||
type TempUser struct {
|
||||
Id int64
|
||||
OrgId int64
|
||||
Version int
|
||||
Email string
|
||||
Name string
|
||||
Role string
|
||||
IsInvite bool
|
||||
Id int64
|
||||
OrgId int64
|
||||
Version int
|
||||
Email string
|
||||
Name string
|
||||
Role string
|
||||
IsInvite bool
|
||||
InvitedByUserId int64
|
||||
|
||||
EmailSent bool
|
||||
EmailSentOn time.Time
|
||||
@@ -32,11 +33,12 @@ type TempUser struct {
|
||||
// COMMANDS
|
||||
|
||||
type CreateTempUserCommand struct {
|
||||
Email string
|
||||
Name string
|
||||
OrgId int64
|
||||
IsInvite bool
|
||||
Code string
|
||||
Email string
|
||||
Name string
|
||||
OrgId int64
|
||||
IsInvite bool
|
||||
InvitedByUserId int64
|
||||
Code string
|
||||
|
||||
Result *TempUser
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func addTempUserMigrations(mg *Migrator) {
|
||||
{Name: "role", Type: DB_NVarchar, Length: 20, Nullable: true},
|
||||
{Name: "code", Type: DB_NVarchar, Length: 255},
|
||||
{Name: "is_invite", Type: DB_Bool},
|
||||
{Name: "invited_by", Type: DB_NVarchar, Length: 255, Nullable: true},
|
||||
{Name: "invited_by_user_id", Type: DB_BigInt, Nullable: true},
|
||||
{Name: "email_sent", Type: DB_Bool},
|
||||
{Name: "email_sent_on", Type: DB_DateTime, Nullable: true},
|
||||
{Name: "created", Type: DB_DateTime},
|
||||
@@ -28,7 +28,7 @@ func addTempUserMigrations(mg *Migrator) {
|
||||
}
|
||||
|
||||
// create table
|
||||
mg.AddMigration("create temp user table v1", NewAddTableMigration(tempUserV1))
|
||||
mg.AddMigration("create temp user table v1-3", NewAddTableMigration(tempUserV1))
|
||||
|
||||
addTableIndicesMigrations(mg, "v1-1", tempUserV1)
|
||||
addTableIndicesMigrations(mg, "v1-3", tempUserV1)
|
||||
}
|
||||
|
||||
@@ -17,13 +17,14 @@ func CreateTempUser(cmd *m.CreateTempUserCommand) error {
|
||||
|
||||
// create user
|
||||
user := &m.TempUser{
|
||||
Email: cmd.Email,
|
||||
Name: cmd.Name,
|
||||
OrgId: cmd.OrgId,
|
||||
Code: cmd.Code,
|
||||
IsInvite: cmd.IsInvite,
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
Email: cmd.Email,
|
||||
Name: cmd.Name,
|
||||
OrgId: cmd.OrgId,
|
||||
Code: cmd.Code,
|
||||
IsInvite: cmd.IsInvite,
|
||||
InvitedByUserId: cmd.InvitedByUserId,
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
}
|
||||
|
||||
sess.UseBool("is_invite")
|
||||
|
||||
Reference in New Issue
Block a user