2015-01-15 19:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								package  api  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
									
										
										
										
											2020-08-13 20:38:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"errors" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"fmt" 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"net/http" 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"strconv" 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-13 20:38:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-02-10 22:36:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/api/dtos" 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/api/response" 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 06:35:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/infra/metrics" 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-21 19:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/models" 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 20:32:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/user" 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-23 18:24:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/util" 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/web" 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-15 19:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route POST /admin/users admin_users adminCreateUser
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Create new user.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// If you are running Grafana Enterprise and have Fine-grained access control enabled, you need to have a permission with action `users:create`.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Note that OrgId is an optional parameter that can be used to assign a new user to a different organization when `auto_assign_org` is set to `true`.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: adminCreateUserResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 412: preconditionFailedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  AdminCreateUser ( c  * models . ReqContext )  response . Response  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									form  :=  dtos . AdminCreateUserForm { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & form ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 20:32:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd  :=  user . CreateUserCommand { 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-10 22:36:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Login :     form . Login , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Email :     form . Email , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Password :  form . Password , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Name :      form . Name , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 20:32:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										OrgID :     form . OrgId , 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-10 22:36:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( cmd . Login )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										cmd . Login  =  cmd . Email 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  len ( cmd . Login )  ==  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 400 ,  "Validation error, need specify either username or email" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-10 22:36:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( cmd . Password )  <  4  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 400 ,  "Password is missing or too short" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-10 22:36:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-20 20:50:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									usr ,  err  :=  hs . Login . CreateUser ( cmd ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-19 00:16:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-13 20:38:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  models . ErrOrgNotFound )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 400 ,  err . Error ( ) ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-13 20:38:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-20 20:50:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  user . ErrUserAlreadyExists )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( 412 ,  fmt . Sprintf ( "User with email '%s' or username '%s' already exists" ,  form . Email ,  form . Login ) ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-15 17:11:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "failed to create user" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-10 22:36:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-16 22:58:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									metrics . MApiAdminUserCreate . Inc ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-23 03:14:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-05-21 19:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  :=  models . UserIdDTO { 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-16 23:28:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Message :  "User created" , 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-20 20:50:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Id :       usr . ID , 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-16 23:28:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-16 22:55:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  result ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-10 22:36:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route PUT /admin/users/{user_id}/password admin_users adminUpdateUserPassword
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Set password for user.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// If you are running Grafana Enterprise and have Fine-grained access control enabled, you need to have a permission with action `users.password:update` and scope `global.users:*`.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2022-02-05 02:45:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  AdminUpdateUserPassword ( c  * models . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									form  :=  dtos . AdminUpdateUserPasswordForm { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & form ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									userID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":id" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "id is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-23 18:24:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( form . Password )  <  4  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 400 ,  "New password too short" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-23 18:24:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-02 22:58:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									userQuery  :=  user . GetUserByIDQuery { ID :  userID } 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-23 18:24:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-02 22:58:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									usr ,  err  :=  hs . userService . GetByID ( c . Req . Context ( ) ,  & userQuery ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Could not read user from database" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-23 18:24:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-02 22:58:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									passwordHashed ,  err  :=  util . EncodePassword ( form . Password ,  usr . Salt ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-23 16:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Could not encode password" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-23 16:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-23 18:24:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-04 21:05:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd  :=  user . ChangeUserPasswordCommand { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										UserID :       userID , 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-23 18:24:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										NewPassword :  passwordHashed , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-04 21:05:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  hs . userService . ChangePassword ( c . Req . Context ( ) ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to update user password" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-23 18:24:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . Success ( "User password updated" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-23 18:24:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route PUT /admin/users/{user_id}/permissions admin_users adminUpdateUserPermissions
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Set permissions for user.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Only works with Basic Authentication (username and password). See introduction for an explanation.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// If you are running Grafana Enterprise and have Fine-grained access control enabled, you need to have a permission with action `users.permissions:update` and scope `global.users:*`.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  AdminUpdateUserPermissions ( c  * models . ReqContext )  response . Response  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									form  :=  dtos . AdminUpdateUserPermissionsForm { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & form ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									userID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":id" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "id is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-26 22:43:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-03 16:20:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									err  =  hs . SQLStore . UpdateUserPermissions ( userID ,  form . IsGrafanaAdmin ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-03-19 16:14:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-20 20:50:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  user . ErrLastGrafanaAdmin )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  response . Error ( 400 ,  user . ErrLastGrafanaAdmin . Error ( ) ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-02 01:28:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to update user permissions" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-26 22:43:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . Success ( "User permissions updated" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-26 22:43:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route DELETE /admin/users/{user_id} admin_users adminDeleteUser
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Delete global User.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// If you are running Grafana Enterprise and have Fine-grained access control enabled, you need to have a permission with action `users:delete` and scope `global.users:*`.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2022-02-05 02:45:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  AdminDeleteUser ( c  * models . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									userID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":id" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "id is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-11 23:47:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-15 19:56:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd  :=  user . DeleteUserCommand { UserID :  userID } 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-11 23:47:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-15 19:56:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  hs . userService . Delete ( c . Req . Context ( ) ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-20 20:50:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  user . ErrUserNotFound )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  response . Error ( 404 ,  user . ErrUserNotFound . Error ( ) ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 18:43:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to delete user" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-11 23:47:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . Success ( "User deleted" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-11 23:47:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2019-03-08 22:15:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route POST /admin/users/{user_id}/disable admin_users adminDisableUser
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Disable user.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// If you are running Grafana Enterprise and have Fine-grained access control enabled, you need to have a permission with action `users:disable` and scope `global.users:1` (userIDScope).
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  AdminDisableUser ( c  * models . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									userID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":id" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "id is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-21 19:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// External users shouldn't be disabled from API
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									authInfoQuery  :=  & models . GetAuthInfoQuery { UserId :  userID } 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-20 20:50:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  hs . authInfoService . GetAuthInfo ( c . Req . Context ( ) ,  authInfoQuery ) ;  ! errors . Is ( err ,  user . ErrUserNotFound )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Could not disable external user" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-21 19:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:24:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									disableCmd  :=  user . DisableUserCommand { UserID :  userID ,  IsDisabled :  true } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  hs . userService . Disable ( c . Req . Context ( ) ,  & disableCmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-20 20:50:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  user . ErrUserNotFound )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  response . Error ( 404 ,  user . ErrUserNotFound . Error ( ) ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 18:43:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to disable user" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-23 20:54:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									err  =  hs . AuthTokenService . RevokeAllUserTokens ( c . Req . Context ( ) ,  userID ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-23 20:54:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to disable user" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-21 19:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . Success ( "User disabled" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-21 19:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route POST /admin/users/{user_id}/enable admin_users adminEnableUser
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Enable user.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// If you are running Grafana Enterprise and have Fine-grained access control enabled, you need to have a permission with action `users:enable` and scope `global.users:1` (userIDScope).
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2022-02-05 02:45:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  AdminEnableUser ( c  * models . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									userID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":id" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "id is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-21 19:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// External users shouldn't be disabled from API
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									authInfoQuery  :=  & models . GetAuthInfoQuery { UserId :  userID } 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-20 20:50:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  hs . authInfoService . GetAuthInfo ( c . Req . Context ( ) ,  authInfoQuery ) ;  ! errors . Is ( err ,  user . ErrUserNotFound )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Could not enable external user" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-21 19:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:24:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									disableCmd  :=  user . DisableUserCommand { UserID :  userID ,  IsDisabled :  false } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  hs . userService . Disable ( c . Req . Context ( ) ,  & disableCmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-20 20:50:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  user . ErrUserNotFound )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  response . Error ( 404 ,  user . ErrUserNotFound . Error ( ) ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 18:43:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 500 ,  "Failed to enable user" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-21 19:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . Success ( "User enabled" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-21 19:52:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route POST /admin/users/{user_id}/logout admin_users adminLogoutUser
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Logout user revokes all auth tokens (devices) for the user. User of issued auth tokens (devices) will no longer be logged in and will be required to authenticate again upon next activity.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// If you are running Grafana Enterprise and have Fine-grained access control enabled, you need to have a permission with action `users.logout` and scope `global.users:*`.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  AdminLogoutUser ( c  * models . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									userID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":id" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "id is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-08 22:15:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-11 19:28:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  c . UserID  ==  userID  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( 400 ,  "You cannot logout yourself" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-08 22:15:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-05 22:37:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  hs . logoutUserFromAllDevicesInternal ( c . Req . Context ( ) ,  userID ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-08 22:15:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route GET /admin/users/{user_id}/auth-tokens admin_users adminGetUserAuthTokens
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Return a list of all auth tokens (devices) that the user currently have logged in from.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// If you are running Grafana Enterprise and have Fine-grained access control enabled, you need to have a permission with action `users.authtoken:list` and scope `global.users:*`.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: adminGetUserAuthTokensResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  AdminGetUserAuthTokens ( c  * models . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									userID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":id" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "id is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-05 22:37:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  hs . getUserAuthTokensInternal ( c ,  userID ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-08 22:15:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route POST /admin/users/{user_id}/revoke-auth-token admin_users adminRevokeUserAuthToken
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Revoke auth token for user.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Revokes the given auth token (device) for the user. User of issued auth token (device) will no longer be logged in and will be required to authenticate again upon next activity.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// If you are running Grafana Enterprise and have Fine-grained access control enabled, you need to have a permission with action `users.authtoken:update` and scope `global.users:*`.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  AdminRevokeUserAuthToken ( c  * models . ReqContext )  response . Response  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cmd  :=  models . RevokeAuthTokenCmd { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									userID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":id" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "id is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-05 22:37:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  hs . revokeUserAuthTokenInternal ( c ,  userID ,  cmd ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-08 22:15:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters adminUpdateUserPassword
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  AdminUpdateUserPasswordParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  dtos . AdminUpdateUserPasswordForm  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									UserID  int64  ` json:"user_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters adminDeleteUser
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  AdminDeleteUserParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									UserID  int64  ` json:"user_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters adminEnableUser
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  AdminEnableUserParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									UserID  int64  ` json:"user_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters adminDisableUser
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  AdminDisableUserParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									UserID  int64  ` json:"user_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters adminGetUserAuthTokens
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  AdminGetUserAuthTokensParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									UserID  int64  ` json:"user_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters adminLogoutUser
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  AdminLogoutUserParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									UserID  int64  ` json:"user_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters adminRevokeUserAuthToken
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  AdminRevokeUserAuthTokenParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  models . RevokeAuthTokenCmd  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									UserID  int64  ` json:"user_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters adminCreateUser
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  AdminCreateUserParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  dtos . AdminCreateUserForm  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters adminUpdateUserPermissions
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  AdminUpdateUserPermissionsParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  dtos . AdminUpdateUserPermissionsForm  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									UserID  int64  ` json:"user_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response adminCreateUserResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  AdminCreateUserResponseResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  models . UserIdDTO  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response adminGetUserAuthTokensResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  AdminGetUserAuthTokensResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  [ ] * models . UserToken  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}