2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								package  api  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
									
										
										
										
											2021-05-12 20:10:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"context" 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"encoding/json" 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"fmt" 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"io" 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"net/http" 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"strings" 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"testing" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-11 00:37:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/authn" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/authn/authntest" 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/stretchr/testify/assert" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/stretchr/testify/require" 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-29 18:51:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/api/dtos" 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-13 12:11:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/apimachinery/identity" 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-19 21:02:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/infra/db" 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-18 23:01:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/infra/db/dbtest" 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-30 19:15:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/infra/tracing" 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-15 17:58:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/login/social" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/login/social/socialtest" 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-17 15:19:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/accesscontrol" 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/accesscontrol/actest" 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-27 01:44:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/featuremgmt" 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/login" 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-21 21:47:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/login/authinfotest" 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 17:56:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/org" 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-26 16:27:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/org/orgimpl" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/org/orgtest" 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-08 00:03:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/quota/quotaimpl" 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-24 16:38:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/sqlstore" 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-07 00:50:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest" 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 20:32:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/user" 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 22:08:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/user/userimpl" 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/user/usertest" 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-11 21:37:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/setting" 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/web/webtest" 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-04 21:04:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  setUpGetOrgUsersDB ( t  * testing . T ,  sqlStore  db . DB ,  cfg  * setting . Cfg )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . AutoAssignOrg  =  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . AutoAssignOrgId  =  int ( testOrgID ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-12 20:10:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-26 07:21:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									quotaService  :=  quotaimpl . ProvideService ( sqlStore ,  cfg ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-04 21:04:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									orgService ,  err  :=  orgimpl . ProvideService ( sqlStore ,  cfg ,  quotaService ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-12 20:10:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-30 19:15:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									usrSvc ,  err  :=  userimpl . ProvideService ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										sqlStore ,  orgService ,  cfg ,  nil ,  nil ,  tracing . InitializeTracerForTest ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										quotaService ,  supportbundlestest . NewFakeBundleService ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-12 20:10:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-08 00:03:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-25 01:08:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									id ,  err  :=  orgService . GetOrCreate ( context . Background ( ) ,  "testOrg" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									require . Equal ( t ,  testOrgID ,  id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-08 00:03:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									_ ,  err  =  usrSvc . Create ( context . Background ( ) ,  & user . CreateUserCommand { Email :  "testUser@grafana.com" ,  Login :  testUserLogin } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									_ ,  err  =  usrSvc . Create ( context . Background ( ) ,  & user . CreateUserCommand { Email :  "user1@grafana.com" ,  Login :  "user1" } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									_ ,  err  =  usrSvc . Create ( context . Background ( ) ,  & user . CreateUserCommand { Email :  "user2@grafana.com" ,  Login :  "user2" } ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-12 20:10:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								func  TestOrgUsersAPIEndpoint_userLoggedIn ( t  * testing . T )  {  
						 
					
						
							
								
									
										
										
										
											2022-01-27 01:44:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									hs  :=  setupSimpleHTTPServer ( featuremgmt . WithFeatures ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									settings  :=  hs . Cfg 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-24 16:38:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									sqlStore  :=  db . InitTestDB ( t ,  sqlstore . InitTestDBOpt { Cfg :  settings } ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-27 22:43:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									hs . SQLStore  =  sqlStore 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-26 16:27:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									orgService  :=  orgtest . NewOrgServiceFake ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-27 00:53:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									orgService . ExpectedSearchOrgUsersResult  =  & org . SearchOrgUsersQueryResult { } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-26 16:27:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									hs . orgService  =  orgService 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-04 21:04:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									setUpGetOrgUsersDB ( t ,  sqlStore ,  settings ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-18 23:01:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									mock  :=  dbtest . NewFakeDB ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 16:54:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									loggedInUserScenario ( t ,  "When calling GET on" ,  "api/org/users" ,  "api/org/users" ,  func ( sc  * scenarioContext )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 16:54:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										orgService . ExpectedSearchOrgUsersResult  =  & org . SearchOrgUsersQueryResult { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											OrgUsers :  [ ] * org . OrgUserDTO { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Login :  testUserLogin ,  Email :  "testUser@grafana.com" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Login :  "user1" ,  Email :  "user1@grafana.com" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Login :  "user2" ,  Email :  "user2@grafana.com" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-26 16:27:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										sc . handlerFunc  =  hs . GetOrgUsersForCurrentOrg 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										sc . fakeReqWithParams ( "GET" ,  sc . url ,  map [ string ] string { } ) . exec ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										require . Equal ( t ,  http . StatusOK ,  sc . resp . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 21:39:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  resp  [ ] org . OrgUserDTO 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										err  :=  json . Unmarshal ( sc . resp . Body . Bytes ( ) ,  & resp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										assert . Len ( t ,  resp ,  3 ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-03 16:20:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ,  mock ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									loggedInUserScenario ( t ,  "When calling GET on" ,  "api/org/users/search" ,  "api/org/users/search" ,  func ( sc  * scenarioContext )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-27 00:53:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										orgService . ExpectedSearchOrgUsersResult  =  & org . SearchOrgUsersQueryResult { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											OrgUsers :  [ ] * org . OrgUserDTO { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Login :  "user1" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Login :  "user2" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Login :  "user3" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											TotalCount :  3 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											PerPage :     1000 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Page :        1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										sc . handlerFunc  =  hs . SearchOrgUsersWithPaging 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-12 20:10:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										sc . fakeReqWithParams ( "GET" ,  sc . url ,  map [ string ] string { } ) . exec ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										require . Equal ( t ,  http . StatusOK ,  sc . resp . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-27 00:53:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  resp  org . SearchOrgUsersQueryResult 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-12 20:10:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										err  :=  json . Unmarshal ( sc . resp . Body . Bytes ( ) ,  & resp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										assert . Len ( t ,  resp . OrgUsers ,  3 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										assert . Equal ( t ,  int64 ( 3 ) ,  resp . TotalCount ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										assert . Equal ( t ,  1000 ,  resp . PerPage ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										assert . Equal ( t ,  1 ,  resp . Page ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-03 16:20:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ,  mock ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-12 20:10:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									loggedInUserScenario ( t ,  "When calling GET with page and limit query parameters on" ,  "api/org/users/search" ,  "api/org/users/search" ,  func ( sc  * scenarioContext )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-27 00:53:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										orgService . ExpectedSearchOrgUsersResult  =  & org . SearchOrgUsersQueryResult { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											OrgUsers :  [ ] * org . OrgUserDTO { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Login :  "user1" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											TotalCount :  3 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											PerPage :     2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Page :        2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										sc . handlerFunc  =  hs . SearchOrgUsersWithPaging 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-12 20:10:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										sc . fakeReqWithParams ( "GET" ,  sc . url ,  map [ string ] string { "perpage" :  "2" ,  "page" :  "2" } ) . exec ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										require . Equal ( t ,  http . StatusOK ,  sc . resp . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-27 00:53:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  resp  org . SearchOrgUsersQueryResult 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-12 20:10:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										err  :=  json . Unmarshal ( sc . resp . Body . Bytes ( ) ,  & resp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										assert . Len ( t ,  resp . OrgUsers ,  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										assert . Equal ( t ,  int64 ( 3 ) ,  resp . TotalCount ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										assert . Equal ( t ,  2 ,  resp . PerPage ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										assert . Equal ( t ,  2 ,  resp . Page ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-03 16:20:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ,  mock ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-12 20:10:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-17 15:19:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									t . Run ( "Given there are two hidden users" ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										settings . HiddenUsers  =  map [ string ] struct { } { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"user1" :        { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											testUserLogin :  { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Cleanup ( func ( )  {  settings . HiddenUsers  =  make ( map [ string ] struct { } )  } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										loggedInUserScenario ( t ,  "When calling GET on" ,  "api/org/users" ,  "api/org/users" ,  func ( sc  * scenarioContext )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 16:54:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											orgService . ExpectedSearchOrgUsersResult  =  & org . SearchOrgUsersQueryResult { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												OrgUsers :  [ ] * org . OrgUserDTO { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													{ Login :  testUserLogin ,  Email :  "testUser@grafana.com" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													{ Login :  "user1" ,  Email :  "user1@grafana.com" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													{ Login :  "user2" ,  Email :  "user2@grafana.com" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											sc . handlerFunc  =  hs . GetOrgUsersForCurrentOrg 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											sc . fakeReqWithParams ( "GET" ,  sc . url ,  map [ string ] string { } ) . exec ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . Equal ( t ,  http . StatusOK ,  sc . resp . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 21:39:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											var  resp  [ ] org . OrgUserDTO 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											err  :=  json . Unmarshal ( sc . resp . Body . Bytes ( ) ,  & resp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . Len ( t ,  resp ,  2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . Equal ( t ,  testUserLogin ,  resp [ 0 ] . Login ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . Equal ( t ,  "user2" ,  resp [ 1 ] . Login ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-03 16:20:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ,  mock ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										loggedInUserScenarioWithRole ( t ,  "When calling GET as an admin on" ,  "GET" ,  "api/org/users/lookup" , 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 17:56:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											"api/org/users/lookup" ,  org . RoleAdmin ,  func ( sc  * scenarioContext )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												sc . handlerFunc  =  hs . GetOrgUsersForCurrentOrgLookup 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												sc . fakeReqWithParams ( "GET" ,  sc . url ,  map [ string ] string { } ) . exec ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												require . Equal ( t ,  http . StatusOK ,  sc . resp . Code ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												var  resp  [ ] dtos . UserLookupDTO 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												err  :=  json . Unmarshal ( sc . resp . Body . Bytes ( ) ,  & resp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Len ( t ,  resp ,  2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  testUserLogin ,  resp [ 0 ] . Login ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  "user2" ,  resp [ 1 ] . Login ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-03 16:20:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ,  mock ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-24 19:10:32 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-09-17 15:19:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  TestOrgUsersAPIEndpoint_updateOrgRole ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									type  testCase  struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-13 21:10:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										desc             string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										SkipOrgRoleSync  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										AuthEnabled      bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										AuthModule       string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedCode     int 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									permissions  :=  [ ] accesscontrol . Permission { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ Action :  accesscontrol . ActionOrgUsersRead ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ Action :  accesscontrol . ActionOrgUsersWrite ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ Action :  accesscontrol . ActionOrgUsersAdd ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ Action :  accesscontrol . ActionOrgUsersRemove ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									tests  :=  [ ] testCase { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-13 21:10:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											desc :             "should be able to change basicRole when skip_org_role_sync true" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											SkipOrgRoleSync :  true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											AuthEnabled :      true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											AuthModule :       login . LDAPAuthModule , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :     http . StatusOK , 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											desc :             "should not be able to change basicRole when skip_org_role_sync false" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											SkipOrgRoleSync :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											AuthEnabled :      true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											AuthModule :       login . LDAPAuthModule , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :     http . StatusForbidden , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-15 17:58:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											desc :             "should not be able to change basicRole for a user synced through an OAuth provider" , 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-13 17:56:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											SkipOrgRoleSync :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											AuthEnabled :      true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											AuthModule :       login . GrafanaComAuthModule , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :     http . StatusForbidden , 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-25 20:27:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-13 21:10:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											desc :             "should be able to change basicRole with a basic Auth" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											SkipOrgRoleSync :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											AuthEnabled :      false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											AuthModule :       "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :     http . StatusOK , 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-13 21:10:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											desc :             "should be able to change basicRole with a basic Auth" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											SkipOrgRoleSync :  true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											AuthEnabled :      true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											AuthModule :       "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :     http . StatusOK , 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									userWithPermissions  :=  userWithPermissions ( 1 ,  permissions ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									userRequesting  :=  & user . User { ID :  2 ,  OrgID :  1 } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									reqBody  :=  ` { "userId": "1", "role": "Admin", "orgId": "1"} ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  tt  :=  range  tests  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( tt . desc ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											server  :=  SetupAPITestServer ( t ,  func ( hs  * HTTPServer )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . Cfg  =  setting . NewCfg ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . Cfg . LDAPAuthEnabled  =  tt . AuthEnabled 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-11 00:37:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												switch  tt . AuthModule  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												case  login . LDAPAuthModule : 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													hs . Cfg . LDAPAuthEnabled  =  tt . AuthEnabled 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													hs . Cfg . LDAPSkipOrgRoleSync  =  tt . SkipOrgRoleSync 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-11 00:37:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												case  login . GrafanaComAuthModule : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													hs . authnService  =  & authntest . FakeService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														EnabledClients :  [ ] string { authn . ClientWithPrefix ( "grafana_com" ) } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														ExpectedClientConfig :  & authntest . FakeSSOClientConfig { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															ExpectedIsSkipOrgRoleSyncEnabled :  tt . SkipOrgRoleSync , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-15 17:58:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												// AuthModule empty means basic auth
 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-21 21:47:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . authInfoService  =  & authinfotest . FakeService { 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													ExpectedUserAuth :  & login . UserAuth { AuthModule :  tt . AuthModule } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . userService  =  & usertest . FakeUserService { ExpectedSignedInUser :  userWithPermissions } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . orgService  =  & orgtest . FakeOrgService { } 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-15 17:58:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . SocialService  =  & socialtest . FakeSocialService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedAuthInfoProvider :  & social . OAuthInfo { Enabled :  tt . AuthEnabled ,  SkipOrgRoleSync :  tt . SkipOrgRoleSync } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . accesscontrolService  =  & actest . FakeService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedPermissions :  permissions , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											req  :=  server . NewRequest ( http . MethodPatch ,  fmt . Sprintf ( "/api/orgs/%d/users/%d" ,  userRequesting . OrgID ,  userRequesting . ID ) ,  strings . NewReader ( reqBody ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											req . Header . Set ( "Content-Type" ,  "application/json" ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-13 12:11:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											userWithPermissions . OrgRole  =  identity . RoleAdmin 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											res ,  err  :=  server . Send ( webtest . RequestWithSignedInUser ( req ,  userWithPermissions ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . Equal ( t ,  tt . expectedCode ,  res . StatusCode ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  res . Body . Close ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  TestOrgUsersAPIEndpoint ( t  * testing . T )  {  
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									type  testCase  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										desc          string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										permissions   [ ] accesscontrol . Permission 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedCode  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									tests  :=  [ ] testCase { 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-17 15:19:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											desc :          "UsersLookupGet should return 200 for user with correct permissions" , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 16:17:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionOrgUsersRead ,  Scope :  accesscontrol . ScopeUsersAll } } , 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-17 15:19:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusForbidden , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											desc :          "UsersLookupGet should return 403 for user without required permissions" , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 16:17:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  "wrong" } } , 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-17 15:19:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  tt  :=  range  tests  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( tt . desc ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											server  :=  SetupAPITestServer ( t ,  func ( hs  * HTTPServer )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . Cfg  =  setting . NewCfg ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . orgService  =  & orgtest . FakeOrgService { ExpectedSearchOrgUsersResult :  & org . SearchOrgUsersQueryResult { } } 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-21 21:47:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . authInfoService  =  & authinfotest . FakeService { } 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											res ,  err  :=  server . Send ( webtest . RequestWithSignedInUser ( server . NewGetRequest ( "/api/org/users/lookup" ) ,  userWithPermissions ( 1 ,  tt . permissions ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . Equal ( t ,  tt . expectedCode ,  res . StatusCode ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  res . Body . Close ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-23 01:46:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  TestGetOrgUsersAPIEndpoint_AccessControlMetadata ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									type  testCase  struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										desc              string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										permissions       [ ] accesscontrol . Permission 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										includeMetadata   bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedCode      int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedMetadata  map [ string ] bool 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-23 01:46:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									tests  :=  [ ] testCase { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											desc :             "should not get access control metadata" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											includeMetadata :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											permissions :  [ ] accesscontrol . Permission { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Action :  accesscontrol . ActionOrgUsersRead ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Action :  accesscontrol . ActionOrgUsersWrite ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Action :  accesscontrol . ActionOrgUsersAdd ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Action :  accesscontrol . ActionOrgUsersRemove ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :      http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedMetadata :  nil , 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-23 01:46:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											desc :             "should get access control metadata" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											includeMetadata :  true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											permissions :  [ ] accesscontrol . Permission { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Action :  accesscontrol . ActionOrgUsersRead ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Action :  accesscontrol . ActionOrgUsersWrite ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Action :  accesscontrol . ActionOrgUsersAdd ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Action :  accesscontrol . ActionOrgUsersRemove ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusOK , 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-23 01:46:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedMetadata :  map [ string ] bool { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												"org.users:write" :   true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"org.users:add" :     true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"org.users:read" :    true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												"org.users:remove" :  true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-23 01:46:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  tt  :=  range  tests  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( tt . desc ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											server  :=  SetupAPITestServer ( t ,  func ( hs  * HTTPServer )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . Cfg  =  setting . NewCfg ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . orgService  =  & orgtest . FakeOrgService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedSearchOrgUsersResult :  & org . SearchOrgUsersQueryResult { OrgUsers :  [ ] * org . OrgUserDTO { { UserID :  1 } } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-21 21:47:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . authInfoService  =  & authinfotest . FakeService { } 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . userService  =  & usertest . FakeUserService { ExpectedSignedInUser :  userWithPermissions ( 1 ,  tt . permissions ) } 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-04 20:29:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . accesscontrolService  =  actest . FakeService { ExpectedPermissions :  tt . permissions } 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 22:08:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-23 01:46:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											url  :=  "/api/orgs/1/users" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  tt . includeMetadata  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												url  +=  "?accesscontrol=true" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											res ,  err  :=  server . Send ( webtest . RequestWithSignedInUser ( server . NewGetRequest ( url ) ,  userWithPermissions ( 1 ,  tt . permissions ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . Equal ( t ,  tt . expectedCode ,  res . StatusCode ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-23 01:46:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 21:39:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											var  userList  [ ] * org . OrgUserDTO 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											err  =  json . NewDecoder ( res . Body ) . Decode ( & userList ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-23 01:46:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  tt . expectedMetadata  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Equal ( t ,  tt . expectedMetadata ,  userList [ 0 ] . AccessControl ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-23 01:46:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Nil ( t ,  userList [ 0 ] . AccessControl ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  res . Body . Close ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-23 01:46:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  TestGetOrgUsersAPIEndpoint_AccessControl ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									type  testCase  struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										name          string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										permissions   [ ] accesscontrol . Permission 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedCode  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										targetOrg     int64 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									tests  :=  [ ] testCase { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											name :  "user with permissions can get users in org" , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :  [ ] accesscontrol . Permission { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Action :  accesscontrol . ActionOrgUsersRead ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											targetOrg :     1 , 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											name :          "user without permissions cannot get users in org" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusForbidden , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											targetOrg :     1 , 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  tc  :=  range  tests  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( tc . name ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											server  :=  SetupAPITestServer ( t ,  func ( hs  * HTTPServer )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . Cfg  =  setting . NewCfg ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . orgService  =  & orgtest . FakeOrgService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedSearchOrgUsersResult :  & org . SearchOrgUsersQueryResult { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-21 21:47:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . authInfoService  =  & authinfotest . FakeService { } 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . userService  =  & usertest . FakeUserService { ExpectedSignedInUser :  userWithPermissions ( 1 ,  tc . permissions ) } 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 21:20:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . accesscontrolService  =  & actest . FakeService { } 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 22:08:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											u  :=  userWithPermissions ( 1 ,  tc . permissions ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											res ,  err  :=  server . Send ( webtest . RequestWithSignedInUser ( server . NewGetRequest ( fmt . Sprintf ( "/api/orgs/%d/users/" ,  tc . targetOrg ) ) ,  u ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . Equal ( t ,  tc . expectedCode ,  res . StatusCode ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  res . Body . Close ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  TestPostOrgUsersAPIEndpoint_AccessControl ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									type  testCase  struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										desc          string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										permissions   [ ] accesscontrol . Permission 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										input         string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedCode  int 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									tests  :=  [ ] testCase { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											desc :  "user with permissions can add users to org" , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :  [ ] accesscontrol . Permission { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Action :  accesscontrol . ActionOrgUsersAdd ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											input :         ` { "loginOrEmail": "user", "role": "Viewer"} ` , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusOK , 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											desc :          "user without permissions cannot add users to org" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusForbidden , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											input :         ` { "loginOrEmail": "user", "role": "Viewer"} ` , 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  tt  :=  range  tests  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( tt . desc ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											server  :=  SetupAPITestServer ( t ,  func ( hs  * HTTPServer )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . Cfg  =  setting . NewCfg ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . orgService  =  & orgtest . FakeOrgService { } 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-21 21:47:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . authInfoService  =  & authinfotest . FakeService { } 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . userService  =  & usertest . FakeUserService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedUser :          & user . User { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedSignedInUser :  userWithPermissions ( 1 ,  tt . permissions ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 21:20:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . accesscontrolService  =  & actest . FakeService { } 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 22:08:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-27 19:58:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											u  :=  userWithPermissions ( 1 ,  tt . permissions ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											res ,  err  :=  server . SendJSON ( webtest . RequestWithSignedInUser ( server . NewPostRequest ( "/api/orgs/1/users" ,  strings . NewReader ( tt . input ) ) ,  u ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . Equal ( t ,  tt . expectedCode ,  res . StatusCode ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  res . Body . Close ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-09-17 15:19:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  TestOrgUsersAPIEndpointWithSetPerms_AccessControl ( t  * testing . T )  {  
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									type  testCase  struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										expectedCode  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										desc          string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										url           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										method        string 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										role          org . RoleType 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										permissions   [ ] accesscontrol . Permission 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										input         string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									tests  :=  [ ] testCase { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											desc :          "org viewer with the correct permissions can add a user as a viewer to his org" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											url :           "/api/org/users" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											method :        http . MethodPost , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											role :          org . RoleViewer , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionOrgUsersAdd ,  Scope :  accesscontrol . ScopeUsersAll } } , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											input :         ` { "loginOrEmail": "user", "role": "Viewer"} ` , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusForbidden , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											desc :          "org viewer with the correct permissions cannot add a user as an editor to his org" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											url :           "/api/org/users" , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											role :          org . RoleViewer , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											method :        http . MethodPost , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionOrgUsersAdd ,  Scope :  accesscontrol . ScopeUsersAll } } , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											input :         ` { "loginOrEmail": "user", "role": "Editor"} ` , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											desc :          "org viewer with the correct permissions can add a user as a viewer to his org" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											url :           "/api/orgs/1/users" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											method :        http . MethodPost , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											role :          org . RoleViewer , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionOrgUsersAdd ,  Scope :  accesscontrol . ScopeUsersAll } } , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											input :         ` { "loginOrEmail": "user", "role": "Viewer"} ` , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusForbidden , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											desc :          "org viewer with the correct permissions cannot add a user as an editor to his org" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											url :           "/api/orgs/1/users" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											method :        http . MethodPost , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											role :          org . RoleViewer , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionOrgUsersAdd ,  Scope :  accesscontrol . ScopeUsersAll } } , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											input :         ` { "loginOrEmail": "user", "role": "Editor"} ` , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											desc :          "org viewer with the correct permissions can update a user's role to a viewer in his org" , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											url :           fmt . Sprintf ( "/api/org/users/%d" ,  1 ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											method :        http . MethodPatch , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											role :          org . RoleViewer , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionOrgUsersWrite ,  Scope :  accesscontrol . ScopeUsersAll } } , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											input :         ` { "role": "Viewer"} ` , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusForbidden , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											desc :          "org viewer with the correct permissions cannot update a user's role to a Editorin his org" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											url :           fmt . Sprintf ( "/api/org/users/%d" ,  1 ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											method :        http . MethodPatch , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionOrgUsersWrite ,  Scope :  accesscontrol . ScopeUsersAll } } , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											input :         ` { "role": "Editor"} ` , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											desc :          "org viewer with the correct permissions can update a user's role to a viewer in his org" , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											url :           fmt . Sprintf ( "/api/orgs/1/users/%d" ,  1 ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											method :        http . MethodPatch , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											role :          org . RoleViewer , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionOrgUsersWrite ,  Scope :  accesscontrol . ScopeUsersAll } } , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											input :         ` { "role": "Viewer"} ` , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusForbidden , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											desc :          "org viewer with the correct permissions cannot update a user's role to a editor in his org" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											url :           fmt . Sprintf ( "/api/orgs/1/users/%d" ,  1 ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											method :        http . MethodPatch , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											role :          org . RoleViewer , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionOrgUsersWrite ,  Scope :  accesscontrol . ScopeUsersAll } } , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											input :         ` { "role": "Editor"} ` , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusOK , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											desc :          "org viewer with the correct permissions can invite a user as a viewer in his org" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											url :           "/api/org/invites" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											method :        http . MethodPost , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											role :          org . RoleViewer , 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-28 00:37:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionOrgUsersAdd ,  Scope :  accesscontrol . ScopeUsersAll } } , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											input :         ` { "loginOrEmail": "newUserEmail@test.com", "sendEmail": false, "role": "Viewer"} ` , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusForbidden , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											desc :          "org viewer with the correct permissions cannot invite a user as an editor in his org" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											url :           "/api/org/invites" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											method :        http . MethodPost , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											role :          org . RoleEditor , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionUsersCreate } } , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											input :         ` { "loginOrEmail": "newUserEmail@test.com", "sendEmail": false, "role": "Editor"} ` , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  tt  :=  range  tests  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( tt . desc ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											server  :=  SetupAPITestServer ( t ,  func ( hs  * HTTPServer )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . Cfg  =  setting . NewCfg ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . orgService  =  & orgtest . FakeOrgService { } 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-21 21:47:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . authInfoService  =  & authinfotest . FakeService { 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													ExpectedUserAuth :  & login . UserAuth { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														AuthModule :  "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . userService  =  & usertest . FakeUserService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedUser :          & user . User { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedSignedInUser :  userWithPermissions ( 1 ,  tt . permissions ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 21:37:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . accesscontrolService  =  & actest . FakeService { } 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 22:08:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											u  :=  userWithPermissions ( 1 ,  tt . permissions ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  reader  io . Reader 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  tt . input  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												reader  =  strings . NewReader ( tt . input ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											res ,  err  :=  server . SendJSON ( webtest . RequestWithSignedInUser ( server . NewRequest ( tt . method ,  tt . url ,  reader ) ,  u ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . Equal ( t ,  tt . expectedCode ,  res . StatusCode ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  res . Body . Close ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-28 00:40:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  TestPatchOrgUsersAPIEndpoint_AccessControl ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									type  testCase  struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										name          string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										role          org . RoleType 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										permissions   [ ] accesscontrol . Permission 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										input         string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedCode  int 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-17 15:19:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									tests  :=  [ ] testCase { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-13 21:10:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											name :          "user with permissions can update org role" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionOrgUsersWrite ,  Scope :  "users:*" } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											role :          org . RoleAdmin , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											input :         ` { "role": "Viewer"} ` , 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedCode :  http . StatusOK , 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											name :          "user without permissions cannot update org role" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											input :         ` { "role": "Editor"} ` , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusForbidden , 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											name :          "user with permissions cannot update org role with more privileges" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											permissions :   [ ] accesscontrol . Permission { { Action :  accesscontrol . ActionOrgUsersWrite ,  Scope :  "users:*" } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											role :          org . RoleViewer , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											input :         ` { "role": "Admin"} ` , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusForbidden , 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  tt  :=  range  tests  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( tt . name ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											server  :=  SetupAPITestServer ( t ,  func ( hs  * HTTPServer )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . Cfg  =  setting . NewCfg ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . orgService  =  & orgtest . FakeOrgService { } 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-21 21:47:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . authInfoService  =  & authinfotest . FakeService { 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-23 01:41:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													ExpectedUserAuth :  & login . UserAuth { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														AuthModule :  "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-03 21:37:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . accesscontrolService  =  & actest . FakeService { } 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . userService  =  & usertest . FakeUserService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedUser :          & user . User { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedSignedInUser :  userWithPermissions ( 1 ,  tt . permissions ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 22:08:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-17 15:19:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											u  :=  userWithPermissions ( 1 ,  tt . permissions ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											res ,  err  :=  server . SendJSON ( webtest . RequestWithSignedInUser ( server . NewRequest ( http . MethodPatch ,  "/api/orgs/1/users/1" ,  strings . NewReader ( tt . input ) ) ,  u ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . Equal ( t ,  tt . expectedCode ,  res . StatusCode ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  res . Body . Close ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  TestDeleteOrgUsersAPIEndpoint_AccessControl ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									type  testCase  struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										name            string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										permissions     [ ] accesscontrol . Permission 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										isGrafanaAdmin  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedCode    int 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									tests  :=  [ ] testCase { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											name :  "user with permissions can remove user from org" , 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											permissions :  [ ] accesscontrol . Permission { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ Action :  accesscontrol . ActionOrgUsersRemove ,  Scope :  "users:*" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusOK , 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 22:29:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											name :          "user without permissions cannot remove user from org" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedCode :  http . StatusForbidden , 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  tt  :=  range  tests  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( tt . name ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											server  :=  SetupAPITestServer ( t ,  func ( hs  * HTTPServer )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . Cfg  =  setting . NewCfg ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . accesscontrolService  =  actest . FakeService { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												hs . orgService  =  & orgtest . FakeOrgService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedOrgListResponse :  orgtest . OrgListResponse { struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														OrgID     int64 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Response  error 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} { OrgID :  1 ,  Response :  nil } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-21 21:47:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . authInfoService  =  & authinfotest . FakeService { } 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												hs . userService  =  & usertest . FakeUserService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedUser :          & user . User { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ExpectedSignedInUser :  userWithPermissions ( 1 ,  tt . permissions ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 22:08:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-17 17:12:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 22:33:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											u  :=  userWithPermissions ( 1 ,  tt . permissions ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											u . IsGrafanaAdmin  =  tt . isGrafanaAdmin 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											res ,  err  :=  server . SendJSON ( webtest . RequestWithSignedInUser ( server . NewRequest ( http . MethodDelete ,  "/api/orgs/1/users/1" ,  nil ) ,  u ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . Equal ( t ,  tt . expectedCode ,  res . StatusCode ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											require . NoError ( t ,  res . Body . Close ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-17 15:19:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}