mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-02 23:41:05 +00:00 
			
		
		
		
	[GITEA] enable system users search via the API
Refs: https://codeberg.org/forgejo/forgejo/issues/1403 (cherry picked from commit87bd40411e) Conflicts: routers/api/v1/user/user.go https://codeberg.org/forgejo/forgejo/pulls/1469 (cherry picked from commit74f70ca873)
This commit is contained in:
		
					parent
					
						
							
								b65d777bc7
							
						
					
				
			
			
				commit
				
					
						673a75bb43
					
				
			
		
					 3 changed files with 51 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -54,19 +54,33 @@ func Search(ctx *context.APIContext) {
 | 
			
		|||
 | 
			
		||||
	listOptions := utils.GetListOptions(ctx)
 | 
			
		||||
 | 
			
		||||
	users, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
 | 
			
		||||
		Actor:       ctx.Doer,
 | 
			
		||||
		Keyword:     ctx.FormTrim("q"),
 | 
			
		||||
		UID:         ctx.FormInt64("uid"),
 | 
			
		||||
		Type:        user_model.UserTypeIndividual,
 | 
			
		||||
		ListOptions: listOptions,
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.JSON(http.StatusInternalServerError, map[string]any{
 | 
			
		||||
			"ok":    false,
 | 
			
		||||
			"error": err.Error(),
 | 
			
		||||
	uid := ctx.FormInt64("uid")
 | 
			
		||||
	var users []*user_model.User
 | 
			
		||||
	var maxResults int64
 | 
			
		||||
	var err error
 | 
			
		||||
 | 
			
		||||
	switch uid {
 | 
			
		||||
	case user_model.GhostUserID:
 | 
			
		||||
		maxResults = 1
 | 
			
		||||
		users = []*user_model.User{user_model.NewGhostUser()}
 | 
			
		||||
	case user_model.ActionsUserID:
 | 
			
		||||
		maxResults = 1
 | 
			
		||||
		users = []*user_model.User{user_model.NewActionsUser()}
 | 
			
		||||
	default:
 | 
			
		||||
		users, maxResults, err = user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
 | 
			
		||||
			Actor:       ctx.Doer,
 | 
			
		||||
			Keyword:     ctx.FormTrim("q"),
 | 
			
		||||
			UID:         uid,
 | 
			
		||||
			Type:        user_model.UserTypeIndividual,
 | 
			
		||||
			ListOptions: listOptions,
 | 
			
		||||
		})
 | 
			
		||||
		return
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.JSON(http.StatusInternalServerError, map[string]any{
 | 
			
		||||
				"ok":    false,
 | 
			
		||||
				"error": err.Error(),
 | 
			
		||||
			})
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue