users_controller.rb 1.4 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1
class UsersController < ApplicationController
2 3
  skip_before_filter :authenticate_user!
  before_filter :set_user
4
  layout :determine_layout
5

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
6
  def show
7
    # Projects user can view
8 9
    visible_projects = ProjectsFinder.new.execute(current_user)
    authorized_projects_ids = visible_projects.pluck(:id)
10 11 12 13 14 15 16 17 18

    @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.
19
      where(project_id: authorized_projects_ids).limit(30)
20

21
    @title = @user.name
22
    @title_url = user_path(@user)
23

24 25 26 27 28 29 30 31
    respond_to do |format|
      format.html
      format.atom { render layout: false }
    end
  end

  def calendar
    visible_projects = ProjectsFinder.new.execute(current_user)
32
    calendar = Gitlab::CommitsCalendar.new(visible_projects, @user)
33
    @timestamps = calendar.timestamps
34 35
    @starting_year = calendar.starting_year
    @starting_month = calendar.starting_month
36

37
    render 'calendar', layout: false
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
38
  end
39 40 41 42 43 44 45 46

  def determine_layout
    if current_user
      'navless'
    else
      'public_users'
    end
  end
47 48 49

  private

50
  def set_user
51 52 53 54 55 56
    @user = User.find_by_username!(params[:username])

    unless current_user || @user.public_profile?
      return authenticate_user!
    end
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
57
end