Skip to content
Snippets Groups Projects
Select Git revision
  • 5aa7f23ae8226f4925c7946f8ccde67733347ce8
  • master default protected
2 results

changelog

Blame
  • Forked from pipelines / tools / gitlab-deps
    Source project has a limited visibility.
    actions_user.go 13.85 KiB
    package accountserver
    
    import (
    	"errors"
    	"strings"
    
    	ct "git.autistici.org/ai3/go-common/ldap/compositetypes"
    	umdb "git.autistici.org/id/usermetadb"
    )
    
    // GetUserRequest retrieves a specific User.
    type GetUserRequest struct {
    	UserRequestBase
    
    	// Whether to return an inactive user.
    	IncludeInactive bool `json:"include_inactive"`
    }
    
    // Serve the request.
    func (r *GetUserRequest) Serve(rctx *RequestContext) (interface{}, error) {
    	if !r.IncludeInactive && rctx.User.Status != UserStatusActive {
    		return nil, ErrUserNotFound
    	}
    
    	// Return the public User object contained within the RawUser.
    	return &rctx.User.User, nil
    }
    
    // SearchUserRequest searches the database for users with names
    // matching a given pattern. The actual pattern semantics are
    // backend-specific (for LDAP, this is a prefix string search).
    type SearchUserRequest struct {
    	AdminRequestBase
    
    	Pattern string `json:"pattern"`
    	Limit   int    `json:"limit"`
    }
    
    // Validate the request.
    func (r *SearchUserRequest) Validate(rctx *RequestContext) error {
    	if r.Pattern == "" {
    		return newValidationError(nil, "pattern", "empty pattern")
    	}
    	return nil
    }
    
    // SearchUserResponse is the response type for SearchUserRequest.
    type SearchUserResponse struct {
    	Usernames []string `json:"usernames"`
    }
    
    // Serve the request.
    func (r *SearchUserRequest) Serve(rctx *RequestContext) (interface{}, error) {
    	usernames, err := rctx.TX.SearchUser(rctx.Context, r.Pattern, r.Limit)
    	if err != nil {
    		return nil, err
    	}
    	return &SearchUserResponse{Usernames: usernames}, nil
    }
    
    // ChangeUserPasswordRequest updates a user's password. It will also take
    // care of re-encrypting the user encryption key, if present.
    type ChangeUserPasswordRequest struct {
    	PrivilegedRequestBase
    	Password string `json:"password"`
    }
    
    // Sanitize the request.
    func (r *ChangeUserPasswordRequest) Sanitize() {
    	r.PrivilegedRequestBase.Sanitize()