• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

benwbrum / fromthepage / 13528664866

25 Feb 2025 06:48PM UTC coverage: 59.626% (-2.2%) from 61.822%
13528664866

Pull #4471

github

web-flow
Merge 279229e31 into 3b7156fe3
Pull Request #4471: Search test

1548 of 3188 branches covered (48.56%)

Branch coverage included in aggregate %.

84 of 457 new or added lines in 18 files covered. (18.38%)

1 existing line in 1 file now uncovered.

7065 of 11257 relevant lines covered (62.76%)

78.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.96
/app/controllers/user_controller.rb
1
class UserController < ApplicationController
1✔
2
  include ElasticSearchable
1✔
3
  before_action :remove_col_id, :only => [:profile, :update_profile]
1✔
4
  before_action :authorized?, :only => [:update_profile, :update]
1✔
5

6
  PAGES_PER_SCREEN = 50
1✔
7

8
  def demo
1✔
9
    session[:demo_mode] = true;
×
10
    redirect_to dashboard_path
×
11
  end
12

13
  def feature_toggle
1✔
14
    feature = params[:feature]
3✔
15
    value = params[:value]
3✔
16
    session[:features] ||= {}
3✔
17
    if value=='enable'
3✔
18
      session[:features][feature]=true
3!
19
    elsif value=='disable'
×
20
      session[:features][feature]=nil
×
21
    else
×
22
      if session[:features][feature]
×
23
        render :plain => "#{feature} is enabled"
×
24
      else
×
25
        render :plain => "#{feature} is disabled"
×
26
      end
27
      return
×
28
    end
29
    redirect_back :fallback_location => dashboard_role_path
3✔
30
  end
31

32
  def choose_locale
1✔
33
    new_locale = params[:chosen_locale].to_sym
×
34
    if !I18n.available_locales.include?(new_locale)
×
35
      # use the default if the above optiosn didn't work
×
36
      new_locale = I18n.default_locale
×
37
    end
38

39
    if user_signed_in?
×
40
      current_user.preferred_locale = new_locale
×
41
      current_user.save
×
42
    else
×
43
      session[:current_locale] = new_locale
×
44
    end
45
    redirect_back :fallback_location => dashboard_role_path
×
46
  end
47

48

49
  NOTOWNER = "NOTOWNER"
1✔
50
  def update
1✔
51

52
    # spam check
53
    if !@user.owner && (params[:user][:about] != NOTOWNER || params[:user][:about] != NOTOWNER)
5!
54
      logger.error("Possible spam: deleting user #{@user.email}")
×
55
      @user.destroy!
×
56
      redirect_to dashboard_path
×
57
    else
5✔
58
      params_hash = user_params.except(:notifications)
5✔
59
      notifications_hash = user_params[:notifications]
5✔
60
      params_hash.delete_if { |k,v| v == NOTOWNER }
46✔
61
      params_hash[:dictation_language] = params[:dialect]
5✔
62

63
      if params_hash[:slug] == ""
5✔
64
        @user.update(params_hash.except(:slug))
1✔
65
        login = @user.login.parameterize
1✔
66
        @user.update(slug: login)
1✔
67
      else
4✔
68
        @user.update(params_hash)
4✔
69
      end
70
        @user.notification.update(notifications_hash)
5✔
71

72
      if @user.save!
5✔
73
        flash[:notice] = t('.user_updated')
5✔
74
        ajax_redirect_to({ :action => 'profile', :user_id => @user.slug, :anchor => '' })
5✔
75
      else
×
76
        render :action => 'update_profile'
×
77
      end
78
    end
79
  end
80

81
  def update_profile
1✔
82
    unless @user
6!
83
      @user = User.friendly.find(params[:user_slug])
×
84
    end
85

86
    if @user.real_name.blank?
6!
87
      @user.real_name = @user.display_name || @user.login
×
88
    end
89

90
    # Set dictation language to default (en-US) if it doesn't exist
91
    lang = !@user.dictation_language.blank? ? @user.dictation_language : "en-US"
6✔
92
    # Find the language portion of the language/dialect or set to nil
93
    part = lang.split('-').first
6✔
94
    # Find the index of the language in the array (transform to integer)
95
    @lang_index = Collection::LANGUAGE_ARRAY.size.times
6✔
96
      .select {|i| Collection::LANGUAGE_ARRAY[i].include?(part)}[0]
360✔
97
    # Then find the index of the nested dialect within the language array
98
    int = Collection::LANGUAGE_ARRAY[@lang_index].size.times
6✔
99
      .select {|i| Collection::LANGUAGE_ARRAY[@lang_index][i].include?(lang)}[0]
84✔
100
    # Transform to integer and subtract 2 because of how the array is nested
101
    @dialect_index = !int.nil? ? int-2 : nil
6!
102
  end
103

104

105
  def api_key
1✔
106
    @user = current_user
×
107
  end
108

109
  def generate_api_key
1✔
110
    @user = current_user
×
111
    @user.api_key = User.generate_api_key
×
112
    @user.save!
×
113

114
#    ajax_redirect_to(user_api_key_path(@user))
115
    render :action => :api_key, :layout => false
×
116
  end
117

118
  def disable_api_key
1✔
119
    @user = current_user
×
120
    @user.api_key = nil
×
121
    @user.save!
×
122
    # ajax_redirect_to(user_api_key_path(@user))
123
    render :action => :api_key, :layout => false
×
124
  end
125

126
  def profile
1✔
127
    # Find the user if it isn't already set
128
    @user ||= User.friendly.find(params[:id])
47✔
129

130
    if !@user.deleted || current_user.admin
47✔
131
      @collections_and_document_sets = @user.visible_collections_and_document_sets(current_user)
47✔
132
      @collection_ids = @collections_and_document_sets.map(&:id)
47✔
133
      @deeds = @user.deeds.includes(:note, :page, :user, :work, :collection)
47✔
134
                    .order('created_at DESC').paginate(page: params[:page], per_page: PAGES_PER_SCREEN)
135
    else
×
136
      flash[:notice] = t('.user_deleted')
×
137
      redirect_to dashboard_path
×
138
    end
139

140
    return unless @user.owner?
47✔
141

142
    if params[:ai_text]
30!
143
      @tag = Tag.where(ai_text: params[:ai_text]).first
×
144
      if @tag
×
145
        tag_collections = @tag.collections.where(owner_user_id: @user.id)
×
146
        tag_document_sets = tag_collections.map(&:document_sets).flatten
×
147
        @tag_collections = tag_collections+tag_document_sets
×
148
      end
149
    end
150
    collections = @user.all_owner_collections.carousel
30✔
151
    sets = @user.document_sets.carousel
30✔
152
    @carousel_collections = (collections + sets).sample(8)
30✔
153
  end
154

155
  def search # ElasticSearch version
1✔
NEW
156
    @user = User.friendly.find(params[:user_slug])
×
NEW
157
    search_page = (search_params[:page] || 1).to_i
×
NEW
158
    @term = search_params[:term]
×
NEW
159
    @breadcrumb_scope={owner: true}
×
160

NEW
161
    page_size = 10
×
162
    
163
    query_config = {
NEW
164
      type: 'org',
×
165
      org_id: @user.id
166
    }
NEW
167
    @org_filter = @user
×
168
  
NEW
169
    search_data = elastic_search_results(
×
170
      @term,
171
      search_page,
172
      page_size,
173
      search_params[:filter],
174
      query_config
175
    )
176

NEW
177
    if search_data
×
NEW
178
      inflated_results = search_data[:inflated]
×
NEW
179
      @full_count = search_data[:full_count] # Used by All tab
×
NEW
180
      @type_counts = search_data[:type_counts]
×
181

182
      # Used for pagination, currently capped at 10k
183
      #
184
      # TODO: ES requires a scroll/search_after query for result sets larger
185
      #       than 10k.
186
      #
187
      #       To setup support we just need to add a composite tiebreaker field
188
      #       to the schemas
NEW
189
      @filtered_count = [ 10000, search_data[:filtered_count] ].min
×
190

191
      # Inspired by display controller search
NEW
192
      @search_string = "\"#{@term || ""}\""
×
NEW
193
      @search_results = WillPaginate::Collection.create(
×
194
        search_page,
195
        page_size,
196
        @filtered_count) do |pager|
NEW
197
          pager.replace(inflated_results)
×
198
        end
199
    end
200
  end
201

202
  private
1✔
203

204
  def authorized?
1✔
205
    unless @user
11✔
206
      @user = User.friendly.find(params[:user_slug])
4✔
207
    end
208

209
    unless current_user && (@user == current_user || current_user.admin?)
11!
210
      redirect_to dashboard_path
×
211
    end
212
  end
213

214
  def search_params
1✔
NEW
215
    params.permit(:term, :page, :filter, :user_id)
×
216
  end
217

218

219
  def user_params
1✔
220
    params.require(:user).permit(:picture, :real_name, :orcid, :slug, :website, :location, :about, :preferred_locale, :help, :footer_block, notifications: [:user_activity, :owner_stats, :add_as_collaborator, :add_as_owner, :note_added, :add_as_reviewer])
10✔
221
  end
222

223
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc