docbrown/app/controllers/dashboards_controller.rb
rhymes e588fa7ece Code cleanups (#659)
* Initial automatic cleanup with rubocop

* Fix syntax error introduced by rubocop

* Cleanup seeds file

* Cleanup lib folder

* Exclude bin folder because it contains auto generated files

* Make Rubocop a little bit more chatty

* Block length should not include comments in the count

* Cleanup config folder

* Cleanup specs

* Updated Rubocop version and generated a todo file

* Fix broken ArticlesApi spec

* Fix tests

* Restored rubocop pre-commit hook
2018-08-07 11:00:13 -04:00

25 lines
1,004 B
Ruby

class DashboardsController < ApplicationController
before_action :set_no_cache_header
before_action :authenticate_user!
after_action :verify_authorized
def show
@user = if params[:username] && current_user.is_admin?
User.find_by_username(params[:username])
else
current_user
end
authorize (@user || User), :dashboard_show?
if params[:which] == "following_users"
@follows = @user.follows_by_type("User").
order("created_at DESC").includes(:followable).limit(80)
elsif params[:which] == "user_followers"
@follows = Follow.where(followable_id: @user.id, followable_type: "User").
includes(:follower).order("created_at DESC").limit(80)
elsif @user&.organization && @user&.org_admin && params[:which] == "organization"
@articles = @user.organization.articles.order("created_at DESC").decorate
elsif @user
@articles = @user.articles.order("created_at DESC").decorate
end
end
end