func listUsers(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	userEmail := r.URL.Query().Get("userEmail")
	roleName := r.URL.Query().Get("role")
	contextValue := r.URL.Query().Get("context")
	users, err := auth.ListUsers()
	if err != nil {
		return err
	}
	apiUsers := make([]apiUser, 0, len(users))
	roleMap := make(map[string]*permission.Role)
	includeAll := permission.Check(t, permission.PermUserUpdate)
	perms, err := t.Permissions()
	if err != nil {
		return err
	}
	for _, user := range users {
		usrData, err := createAPIUser(perms, &user, roleMap, includeAll)
		if err != nil {
			return err
		}
		if usrData == nil {
			continue
		}
		if userEmail == "" && roleName == "" {
			apiUsers = append(apiUsers, *usrData)
		}
		if userEmail != "" && usrData.Email == userEmail {
			apiUsers = append(apiUsers, *usrData)
		}
		if roleName != "" {
			for _, role := range usrData.Roles {
				if role.Name == roleName {
					if contextValue != "" && role.ContextValue == contextValue {
						apiUsers = append(apiUsers, *usrData)
						break
					}
					if contextValue == "" {
						apiUsers = append(apiUsers, *usrData)
						break
					}
				}
			}
		}
	}
	if len(apiUsers) == 0 {
		if contextValue != "" {
			return &errors.HTTP{Code: http.StatusNotFound, Message: "Wrong context being passed."}
		}
		user, err := auth.ConvertNewUser(t.User())
		if err != nil {
			return err
		}
		perm, err := user.Permissions()
		if err != nil {
			return err
		}
		userData, err := createAPIUser(perm, user, nil, true)
		if err != nil {
			return err
		}
		apiUsers = append(apiUsers, *userData)
	}
	w.Header().Add("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(apiUsers)
}
func listUsers(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	userEmail := r.URL.Query().Get("userEmail")
	roleName := r.URL.Query().Get("role")
	contextValue := r.URL.Query().Get("context")
	users, err := auth.ListUsers()
	if err != nil {
		return err
	}
	apiUsers := make([]apiUser, 0, len(users))
	roleMap := make(map[string]*permission.Role)
	includeAll := permission.Check(t, permission.PermUserUpdate)
	perms, err := t.Permissions()
	if err != nil {
		return err
	}
	for _, user := range users {
		usrData, err := createAPIUser(perms, &user, roleMap, includeAll)
		if err != nil {
			return err
		}
		if usrData == nil {
			continue
		}
		if userEmail == "" && roleName == "" {
			apiUsers = append(apiUsers, *usrData)
		}
		if userEmail != "" && usrData.Email == userEmail {
			apiUsers = append(apiUsers, *usrData)
		}
		if roleName != "" {
			for _, role := range usrData.Roles {
				if role.Name == roleName {
					if contextValue != "" && role.ContextValue == contextValue {
						apiUsers = append(apiUsers, *usrData)
						break
					}
					if contextValue == "" {
						apiUsers = append(apiUsers, *usrData)
						break
					}
				}
			}
		}
	}
	if len(apiUsers) == 0 {
		if contextValue != "" {
			return &errors.HTTP{Code: http.StatusNotFound, Message: "Wrong context being passed."}
		}
		user, err := auth.ConvertNewUser(t.User())
		if err != nil {
			return err
		}
		perm, err := user.Permissions()
		if err != nil {
			return err
		}
		userData, err := createAPIUser(perm, user, nil, true)
		if err != nil {
			return err
		}
		apiUsers = append(apiUsers, *userData)
	}
	w.Header().Add("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(apiUsers)
}
func listUsers ( w http . ResponseWriter , r * http . Request , t auth . Token ) error { userEmail := r . URL . Query ( ) . Get ( " " ) roleName := r . URL . Query ( ) . Get ( " " ) contextValue := r . URL . Query ( ) . Get ( " " ) users , err := auth . ListUsers ( ) if err != nil { return err } apiUsers := make ( [ ] apiUser , 0 , len ( users ) ) roleMap := make ( map [ string ] * permission . Role ) includeAll := permission . Check ( t , permission . PermUserUpdate ) perms , err := t . Permissions ( ) if err != nil { return err } for _ , user := range users { usrData , err := createAPIUser ( perms , & user , roleMap , includeAll ) if err != nil { return err } if usrData == nil { continue } if userEmail == " " && roleName == " " { apiUsers = append ( apiUsers , * usrData ) } if userEmail != " " && usrData . Email == userEmail { apiUsers = append ( apiUsers , * usrData ) } if roleName != " " { for _ , role := range usrData . Roles { if role . Name == roleName { if contextValue != " " && role . ContextValue == contextValue { apiUsers = append ( apiUsers , * usrData ) break } if contextValue == " " { apiUsers = append ( apiUsers , * usrData ) break } } } } } if len ( apiUsers ) == 0 { if contextValue != " " { return & errors . HTTP { Code : http . StatusNotFound , Message : " " } } user , err := auth . ConvertNewUser ( t . User ( ) ) if err != nil { return err } perm , err := user . Permissions ( ) if err != nil { return err } userData , err := createAPIUser ( perm , user , nil , true ) if err != nil { return err } apiUsers = append ( apiUsers , * userData ) } w . Header ( ) . Add ( " " , " " ) return json . NewEncoder ( w ) . Encode ( apiUsers ) }
// title: user list
// path: /users
// method: GET
// produce: application/json
// responses:
//   200: OK
//   401: Unauthorized
title : user list path : / users method : GET produce : application / json responses : 200 : OK 401 : Unauthorized