예제 #1
0
// Get a list of users that match the specified searchText
func (um *UserManager) SearchForUsersByName(pageNum int, numPerPage int,
	searchText string, ulr *UserListQueryResponse, curUser *CurrentUserInfo) error {
	if numPerPage == 0 {
		numPerPage = 25
	}
	if pageNum == 0 {
		pageNum = 1
	}
	if !util.IsAnyAdmin(curUser.User.Roles) {
		return NotAdminError()
	}
	numChan := make(chan int, 1)
	ulrChan := make(chan *UserListQueryResponse, 1)
	// Get the number of last and first name results that match our query
	go um.getUserSearchCount(searchText, "usersByName", numChan)
	// Determine number of last name results we need to grab
	skip := numPerPage * (pageNum - 1)
	go um.searchUsers(numPerPage, skip, searchText, "usersByName", ulrChan)
	nameCount := <-numChan
	readUlr := <-ulrChan
	if readUlr == nil {
		return &couchdb.Error{
			StatusCode: 500,
			Reason:     "Internal Error occurred.",
		}
	}
	//Copy the readUlr into the ulr
	for _, row := range readUlr.Rows {
		ulr.Rows = append(ulr.Rows, row)
	}
	// Total rows is the total number of last name results + the
	// total number of first name results.
	ulr.TotalRows = nameCount
	return nil
}
예제 #2
0
//Get list of users
func (um *UserManager) GetUserList(pageNum int, numPerPage int,
	ulr *UserListQueryResponse, curUser *CurrentUserInfo) error {
	//You have to be some sort of admin to do this
	if !util.IsAnyAdmin(curUser.User.Roles) {
		return NotAdminError()
	}
	params := url.Values{}
	if numPerPage != 0 {
		params.Add("limit", strconv.Itoa(numPerPage))
	}
	skip := numPerPage * (pageNum - 1)
	if skip > 0 {
		params.Add("skip", strconv.Itoa(skip))
	}
	userDb := Connection.SelectDB("_users", AdminAuth)
	err := userDb.GetView("user_queries", "listUsers", &ulr, &params)
	if err != nil {
		return err
	}
	return nil
}