before_action :check_database_writable, :only => [:new, :go_public]
before_action :require_cookies, :only => [:new]
- before_action :lookup_user_by_name, :only => [:set_status, :destroy]
allow_thirdparty_images :only => :show
allow_social_login :only => :new
def show
@user = User.find_by(:display_name => params[:display_name])
- if @user &&
- (@user.visible? || current_user&.administrator?)
+ if @user && (@user.visible? || current_user&.administrator?)
@title = @user.display_name
+
+ @heatmap_data = Rails.cache.fetch("heatmap_data_user_#{@user.id}", :expires_in => 1.day) do
+ one_year_ago = 1.year.ago.beginning_of_day
+ today = Time.zone.now.end_of_day
+
+ Changeset
+ .where(:user_id => @user.id)
+ .where(:created_at => one_year_ago..today)
+ .where(:num_changes => 1..)
+ .group("date_trunc('day', created_at)")
+ .select("date_trunc('day', created_at) AS date, SUM(num_changes) AS total_changes")
+ .order("date")
+ .map do |changeset|
+ {
+ :date => changeset.date.to_date.to_s,
+ :total_changes => changeset.total_changes.to_i
+ }
+ end
+ end
else
render_unknown_user params[:display_name]
end
end
end
- ##
- # destroy a user, marking them as deleted and removing personal data
- def destroy
- @user.soft_destroy!
- redirect_to user_path(:display_name => params[:display_name])
- end
-
def go_public
current_user.data_public = true
current_user.save
flash[:notice] = t ".flash success"
- redirect_to edit_account_path
- end
-
- ##
- # sets a user's status
- def set_status
- @user.activate! if params[:event] == "activate"
- @user.confirm! if params[:event] == "confirm"
- @user.unconfirm! if params[:event] == "unconfirm"
- @user.hide! if params[:event] == "hide"
- @user.unhide! if params[:event] == "unhide"
- @user.unsuspend! if params[:event] == "unsuspend"
- redirect_to user_path(:display_name => params[:display_name])
+ redirect_to account_path
end
##
session[:user_errors] = current_user.errors.as_json
- redirect_to edit_account_path
+ redirect_to account_path
else
user = User.find_by(:auth_provider => provider, :auth_uid => uid)
end
end
- ##
- # ensure that there is a "user" instance variable
- def lookup_user_by_name
- @user = User.find_by(:display_name => params[:display_name])
- rescue ActiveRecord::RecordNotFound
- redirect_to :action => "view", :display_name => params[:display_name] unless @user
- end
-
##
# return permitted user parameters
def user_params
params.require(:user).permit(:email, :display_name,
:auth_provider, :auth_uid,
- :pass_crypt, :pass_crypt_confirmation,
- :consider_pd)
+ :pass_crypt, :pass_crypt_confirmation)
end
##