users_controller.rb 895 字节
Newer Older
D
Dmitriy Zaporozhets 已提交
1
class UsersController < ApplicationController
2 3
  skip_before_filter :authenticate_user!, only: [:show]
  layout :determine_layout
4

D
Dmitriy Zaporozhets 已提交
5
  def show
6
    @user = User.find_by_username!(params[:username])
7

D
Dmitriy Zaporozhets 已提交
8
    unless current_user || @user.public_profile?
9 10
      return authenticate_user!
    end
11

12 13 14 15 16 17 18 19 20 21 22 23 24
    # Projects user can view
    authorized_projects_ids = ProjectsFinder.new.execute(current_user).pluck(:id)

    @projects = @user.personal_projects.
      where(id: authorized_projects_ids)

    # Collect only groups common for both users
    @groups = @user.groups & GroupsFinder.new.execute(current_user)

    # Get user activity feed for projects common for both users
    @events = @user.recent_events.
      where(project_id: authorized_projects_ids).limit(20)

25
    @title = @user.name
D
Dmitriy Zaporozhets 已提交
26
  end
27 28 29 30 31 32 33 34

  def determine_layout
    if current_user
      'navless'
    else
      'public_users'
    end
  end
D
Dmitriy Zaporozhets 已提交
35
end