|
@@ -9,12 +9,12 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// GET /api/user (current authenticated user)
|
|
// GET /api/user (current authenticated user)
|
|
|
-func GetSignedInUser(c *m.Context) Response {
|
|
|
|
|
|
|
+func GetSignedInUser(c *m.ReqContext) Response {
|
|
|
return getUserUserProfile(c.UserId)
|
|
return getUserUserProfile(c.UserId)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GET /api/users/:id
|
|
// GET /api/users/:id
|
|
|
-func GetUserById(c *m.Context) Response {
|
|
|
|
|
|
|
+func GetUserById(c *m.ReqContext) Response {
|
|
|
return getUserUserProfile(c.ParamsInt64(":id"))
|
|
return getUserUserProfile(c.ParamsInt64(":id"))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -32,7 +32,7 @@ func getUserUserProfile(userId int64) Response {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GET /api/users/lookup
|
|
// GET /api/users/lookup
|
|
|
-func GetUserByLoginOrEmail(c *m.Context) Response {
|
|
|
|
|
|
|
+func GetUserByLoginOrEmail(c *m.ReqContext) Response {
|
|
|
query := m.GetUserByLoginQuery{LoginOrEmail: c.Query("loginOrEmail")}
|
|
query := m.GetUserByLoginQuery{LoginOrEmail: c.Query("loginOrEmail")}
|
|
|
if err := bus.Dispatch(&query); err != nil {
|
|
if err := bus.Dispatch(&query); err != nil {
|
|
|
if err == m.ErrUserNotFound {
|
|
if err == m.ErrUserNotFound {
|
|
@@ -54,7 +54,7 @@ func GetUserByLoginOrEmail(c *m.Context) Response {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// POST /api/user
|
|
// POST /api/user
|
|
|
-func UpdateSignedInUser(c *m.Context, cmd m.UpdateUserCommand) Response {
|
|
|
|
|
|
|
+func UpdateSignedInUser(c *m.ReqContext, cmd m.UpdateUserCommand) Response {
|
|
|
if setting.AuthProxyEnabled {
|
|
if setting.AuthProxyEnabled {
|
|
|
if setting.AuthProxyHeaderProperty == "email" && cmd.Email != c.Email {
|
|
if setting.AuthProxyHeaderProperty == "email" && cmd.Email != c.Email {
|
|
|
return ApiError(400, "Not allowed to change email when auth proxy is using email property", nil)
|
|
return ApiError(400, "Not allowed to change email when auth proxy is using email property", nil)
|
|
@@ -68,13 +68,13 @@ func UpdateSignedInUser(c *m.Context, cmd m.UpdateUserCommand) Response {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// POST /api/users/:id
|
|
// POST /api/users/:id
|
|
|
-func UpdateUser(c *m.Context, cmd m.UpdateUserCommand) Response {
|
|
|
|
|
|
|
+func UpdateUser(c *m.ReqContext, cmd m.UpdateUserCommand) Response {
|
|
|
cmd.UserId = c.ParamsInt64(":id")
|
|
cmd.UserId = c.ParamsInt64(":id")
|
|
|
return handleUpdateUser(cmd)
|
|
return handleUpdateUser(cmd)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//POST /api/users/:id/using/:orgId
|
|
//POST /api/users/:id/using/:orgId
|
|
|
-func UpdateUserActiveOrg(c *m.Context) Response {
|
|
|
|
|
|
|
+func UpdateUserActiveOrg(c *m.ReqContext) Response {
|
|
|
userId := c.ParamsInt64(":id")
|
|
userId := c.ParamsInt64(":id")
|
|
|
orgId := c.ParamsInt64(":orgId")
|
|
orgId := c.ParamsInt64(":orgId")
|
|
|
|
|
|
|
@@ -107,12 +107,12 @@ func handleUpdateUser(cmd m.UpdateUserCommand) Response {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GET /api/user/orgs
|
|
// GET /api/user/orgs
|
|
|
-func GetSignedInUserOrgList(c *m.Context) Response {
|
|
|
|
|
|
|
+func GetSignedInUserOrgList(c *m.ReqContext) Response {
|
|
|
return getUserOrgList(c.UserId)
|
|
return getUserOrgList(c.UserId)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GET /api/user/:id/orgs
|
|
// GET /api/user/:id/orgs
|
|
|
-func GetUserOrgList(c *m.Context) Response {
|
|
|
|
|
|
|
+func GetUserOrgList(c *m.ReqContext) Response {
|
|
|
return getUserOrgList(c.ParamsInt64(":id"))
|
|
return getUserOrgList(c.ParamsInt64(":id"))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -145,7 +145,7 @@ func validateUsingOrg(userId int64, orgId int64) bool {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// POST /api/user/using/:id
|
|
// POST /api/user/using/:id
|
|
|
-func UserSetUsingOrg(c *m.Context) Response {
|
|
|
|
|
|
|
+func UserSetUsingOrg(c *m.ReqContext) Response {
|
|
|
orgId := c.ParamsInt64(":id")
|
|
orgId := c.ParamsInt64(":id")
|
|
|
|
|
|
|
|
if !validateUsingOrg(c.UserId, orgId) {
|
|
if !validateUsingOrg(c.UserId, orgId) {
|
|
@@ -162,7 +162,7 @@ func UserSetUsingOrg(c *m.Context) Response {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GET /profile/switch-org/:id
|
|
// GET /profile/switch-org/:id
|
|
|
-func ChangeActiveOrgAndRedirectToHome(c *m.Context) {
|
|
|
|
|
|
|
+func ChangeActiveOrgAndRedirectToHome(c *m.ReqContext) {
|
|
|
orgId := c.ParamsInt64(":id")
|
|
orgId := c.ParamsInt64(":id")
|
|
|
|
|
|
|
|
if !validateUsingOrg(c.UserId, orgId) {
|
|
if !validateUsingOrg(c.UserId, orgId) {
|
|
@@ -178,7 +178,7 @@ func ChangeActiveOrgAndRedirectToHome(c *m.Context) {
|
|
|
c.Redirect(setting.AppSubUrl + "/")
|
|
c.Redirect(setting.AppSubUrl + "/")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func ChangeUserPassword(c *m.Context, cmd m.ChangeUserPasswordCommand) Response {
|
|
|
|
|
|
|
+func ChangeUserPassword(c *m.ReqContext, cmd m.ChangeUserPasswordCommand) Response {
|
|
|
if setting.LdapEnabled || setting.AuthProxyEnabled {
|
|
if setting.LdapEnabled || setting.AuthProxyEnabled {
|
|
|
return ApiError(400, "Not allowed to change password when LDAP or Auth Proxy is enabled", nil)
|
|
return ApiError(400, "Not allowed to change password when LDAP or Auth Proxy is enabled", nil)
|
|
|
}
|
|
}
|
|
@@ -210,7 +210,7 @@ func ChangeUserPassword(c *m.Context, cmd m.ChangeUserPasswordCommand) Response
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GET /api/users
|
|
// GET /api/users
|
|
|
-func SearchUsers(c *m.Context) Response {
|
|
|
|
|
|
|
+func SearchUsers(c *m.ReqContext) Response {
|
|
|
query, err := searchUser(c)
|
|
query, err := searchUser(c)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return ApiError(500, "Failed to fetch users", err)
|
|
return ApiError(500, "Failed to fetch users", err)
|
|
@@ -220,7 +220,7 @@ func SearchUsers(c *m.Context) Response {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GET /api/users/search
|
|
// GET /api/users/search
|
|
|
-func SearchUsersWithPaging(c *m.Context) Response {
|
|
|
|
|
|
|
+func SearchUsersWithPaging(c *m.ReqContext) Response {
|
|
|
query, err := searchUser(c)
|
|
query, err := searchUser(c)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return ApiError(500, "Failed to fetch users", err)
|
|
return ApiError(500, "Failed to fetch users", err)
|
|
@@ -229,7 +229,7 @@ func SearchUsersWithPaging(c *m.Context) Response {
|
|
|
return Json(200, query.Result)
|
|
return Json(200, query.Result)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func searchUser(c *m.Context) (*m.SearchUsersQuery, error) {
|
|
|
|
|
|
|
+func searchUser(c *m.ReqContext) (*m.SearchUsersQuery, error) {
|
|
|
perPage := c.QueryInt("perpage")
|
|
perPage := c.QueryInt("perpage")
|
|
|
if perPage <= 0 {
|
|
if perPage <= 0 {
|
|
|
perPage = 1000
|
|
perPage = 1000
|
|
@@ -257,7 +257,7 @@ func searchUser(c *m.Context) (*m.SearchUsersQuery, error) {
|
|
|
return query, nil
|
|
return query, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func SetHelpFlag(c *m.Context) Response {
|
|
|
|
|
|
|
+func SetHelpFlag(c *m.ReqContext) Response {
|
|
|
flag := c.ParamsInt64(":id")
|
|
flag := c.ParamsInt64(":id")
|
|
|
|
|
|
|
|
bitmask := &c.HelpFlags1
|
|
bitmask := &c.HelpFlags1
|
|
@@ -275,7 +275,7 @@ func SetHelpFlag(c *m.Context) Response {
|
|
|
return Json(200, &util.DynMap{"message": "Help flag set", "helpFlags1": cmd.HelpFlags1})
|
|
return Json(200, &util.DynMap{"message": "Help flag set", "helpFlags1": cmd.HelpFlags1})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func ClearHelpFlags(c *m.Context) Response {
|
|
|
|
|
|
|
+func ClearHelpFlags(c *m.ReqContext) Response {
|
|
|
cmd := m.SetUserHelpFlagCommand{
|
|
cmd := m.SetUserHelpFlagCommand{
|
|
|
UserId: c.UserId,
|
|
UserId: c.UserId,
|
|
|
HelpFlags1: m.HelpFlags1(0),
|
|
HelpFlags1: m.HelpFlags1(0),
|