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

benwbrum / fromthepage / 17387282326

01 Sep 2025 09:13PM UTC coverage: 64.405%. Remained the same
17387282326

push

github

web-flow
4857 - Require rubocop step in CI (#4858)

* 4857 - Require rubocop step in CI

* 4865 - Organize gemfiles

1790 of 3303 branches covered (54.19%)

Branch coverage included in aggregate %.

839 of 1497 new or added lines in 133 files covered. (56.05%)

43 existing lines in 29 files now uncovered.

7928 of 11786 relevant lines covered (67.27%)

103.82 hits per line

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

62.84
/app/controllers/user_controller.rb
1
class UserController < ApplicationController
1✔
2
  before_action :remove_col_id, only: [ :profile, :update_profile ]
1✔
3
  before_action :authorized?, only: [ :update_profile, :update ]
1✔
4

5
  PAGES_PER_SCREEN = 50
1✔
6

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

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

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

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

47

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

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

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

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

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

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

102

103
  def api_key
1✔
104
    @user = current_user
×
105
  end
106

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

112
    #    ajax_redirect_to(user_api_key_path(@user))
NEW
113
    render action: :api_key, layout: false
×
114
  end
115

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

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

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

138
    return unless @user.owner?
48✔
139

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

153
  def search
1✔
154
    @user = User.friendly.find(params[:user_slug])
1✔
155
    @search_string = search_params[:term]
1✔
156

157
    @es_query = Elasticsearch::MultiQuery.new(
1✔
158
      query: @search_string,
159
      query_params: {
160
        org: params[:user_slug]
161
      },
162
      page: params[:page] || 1,
163
      scope: search_params[:filter],
164
      user: current_user
165
    ).call
166

167
    @breadcrumb_scope = { owner: true }
1✔
168
    @org_filter = @es_query.org_filter
1✔
169

170
    @search_results = @es_query.results
1✔
171
    @full_count = @es_query.total_count
1✔
172
    @type_counts = @es_query.type_counts
1✔
173
  end
174

175
  private
1✔
176

177
  def authorized?
1✔
178
    unless @user
11✔
179
      @user = User.friendly.find(params[:user_slug])
4✔
180
    end
181

182
    unless current_user && (@user == current_user || current_user.admin?)
11!
183
      redirect_to dashboard_path
×
184
    end
185
  end
186

187
  def search_params
1✔
188
    params.permit(:term, :page, :filter, :user_id)
2✔
189
  end
190

191

192
  def user_params
1✔
193
    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✔
194
  end
195
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