mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(invite): progress on invite feature, #2353
This commit is contained in:
@@ -22,7 +22,7 @@ func Register(r *macaron.Macaron) {
|
||||
r.Post("/login", bind(dtos.LoginCommand{}), wrap(LoginPost))
|
||||
r.Get("/login/:name", OAuthLogin)
|
||||
r.Get("/login", LoginView)
|
||||
r.Get("/invite", Index)
|
||||
r.Get("/invite/:code", Index)
|
||||
|
||||
// authed views
|
||||
r.Get("/profile/", reqSignedIn, Index)
|
||||
|
||||
@@ -10,9 +10,10 @@ type AddInviteForm struct {
|
||||
}
|
||||
|
||||
type InviteInfo struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username"`
|
||||
InvitedBy string `json:"invitedBy"`
|
||||
}
|
||||
|
||||
type CompleteInviteForm struct {
|
||||
|
||||
@@ -78,7 +78,7 @@ func AddOrgInvite(c *middleware.Context, inviteDto dtos.AddInviteForm) Response
|
||||
"OrgName": c.OrgName,
|
||||
"Email": c.Email,
|
||||
"LinkUrl": setting.ToAbsUrl("invite/" + cmd.Code),
|
||||
"InvitedBy": util.StringsFallback2(c.Name, c.Email),
|
||||
"InvitedBy": util.StringsFallback3(c.Name, c.Email, c.Login),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -114,13 +114,14 @@ func GetInviteInfoByCode(c *middleware.Context) Response {
|
||||
return ApiError(500, "Failed to get invite", err)
|
||||
}
|
||||
|
||||
info := dtos.InviteInfo{
|
||||
Email: query.Result.Email,
|
||||
Name: query.Result.Name,
|
||||
Username: query.Result.Email,
|
||||
}
|
||||
invite := query.Result
|
||||
|
||||
return Json(200, &info)
|
||||
return Json(200, dtos.InviteInfo{
|
||||
Email: invite.Email,
|
||||
Name: invite.Name,
|
||||
Username: invite.Email,
|
||||
InvitedBy: util.StringsFallback3(invite.InvitedByName, invite.InvitedByLogin, invite.InvitedByEmail),
|
||||
})
|
||||
}
|
||||
|
||||
func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteForm) Response {
|
||||
|
||||
@@ -70,18 +70,21 @@ type GetTempUsersForOrgQuery struct {
|
||||
type GetTempUserByCodeQuery struct {
|
||||
Code string
|
||||
|
||||
Result *TempUser
|
||||
Result *TempUserDTO
|
||||
}
|
||||
|
||||
type TempUserDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Role string `json:"role"`
|
||||
InvitedBy string `json:"invitedBy"`
|
||||
Code string `json:"code"`
|
||||
Url string `json:"url"`
|
||||
EmailSent bool `json:"emailSent"`
|
||||
EmailSentOn time.Time `json:"emailSentOn"`
|
||||
Created time.Time `json:"createdOn"`
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Role string `json:"role"`
|
||||
InvitedByLogin string `json:"invitedByLogin"`
|
||||
InvitedByEmail string `json:"invitedByEmail"`
|
||||
InvitedByName string `json:"invitedByName"`
|
||||
Code string `json:"code"`
|
||||
Status TempUserStatus `json:"status"`
|
||||
Url string `json:"url"`
|
||||
EmailSent bool `json:"emailSent"`
|
||||
EmailSentOn time.Time `json:"emailSentOn"`
|
||||
Created time.Time `json:"createdOn"`
|
||||
}
|
||||
|
||||
@@ -56,10 +56,13 @@ func GetTempUsersForOrg(query *m.GetTempUsersForOrgQuery) error {
|
||||
tu.name as name,
|
||||
tu.role as role,
|
||||
tu.code as code,
|
||||
tu.status as status,
|
||||
tu.email_sent as email_sent,
|
||||
tu.email_sent_on as email_sent_on,
|
||||
tu.created as created,
|
||||
u.login as invited_by
|
||||
u.login as invited_by_login,
|
||||
u.name as invited_by_name,
|
||||
u.email as invited_by_email
|
||||
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=? AND tu.status =? ORDER BY tu.created desc`
|
||||
@@ -71,8 +74,26 @@ func GetTempUsersForOrg(query *m.GetTempUsersForOrgQuery) error {
|
||||
}
|
||||
|
||||
func GetTempUserByCode(query *m.GetTempUserByCodeQuery) error {
|
||||
var user m.TempUser
|
||||
has, err := x.Table("temp_user").Where("code=?", query.Code).Get(&user)
|
||||
var rawSql = `SELECT
|
||||
tu.id as id,
|
||||
tu.email as email,
|
||||
tu.name as name,
|
||||
tu.role as role,
|
||||
tu.code as code,
|
||||
tu.status as status,
|
||||
tu.email_sent as email_sent,
|
||||
tu.email_sent_on as email_sent_on,
|
||||
tu.created as created,
|
||||
u.login as invited_by_login,
|
||||
u.name as invited_by_name,
|
||||
u.email as invited_by_email
|
||||
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.code=?`
|
||||
|
||||
var tempUser m.TempUserDTO
|
||||
sess := x.Sql(rawSql, query.Code)
|
||||
has, err := sess.Get(&tempUser)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -80,6 +101,6 @@ func GetTempUserByCode(query *m.GetTempUserByCodeQuery) error {
|
||||
return m.ErrTempUserNotFound
|
||||
}
|
||||
|
||||
query.Result = &user
|
||||
query.Result = &tempUser
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -32,6 +32,14 @@ func TestTempUserCommandsAndQueries(t *testing.T) {
|
||||
So(len(query.Result), ShouldEqual, 1)
|
||||
})
|
||||
|
||||
Convey("Should be able to get temp users by code", func() {
|
||||
query := m.GetTempUserByCodeQuery{Code: "asd"}
|
||||
err = GetTempUserByCode(&query)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(query.Result.Name, ShouldEqual, "hello")
|
||||
})
|
||||
|
||||
Convey("Should be able update status", func() {
|
||||
cmd2 := m.UpdateTempUserStatusCommand{Code: "asd", Status: m.TmpUserRevoked}
|
||||
err := UpdateTempUserStatus(&cmd2)
|
||||
|
||||
@@ -6,3 +6,13 @@ func StringsFallback2(val1 string, val2 string) string {
|
||||
}
|
||||
return val2
|
||||
}
|
||||
|
||||
func StringsFallback3(val1 string, val2 string, val3 string) string {
|
||||
if val1 != "" {
|
||||
return val1
|
||||
}
|
||||
if val2 != "" {
|
||||
return val2
|
||||
}
|
||||
return val3
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user