users_controller.rb 1.45 KB
Newer Older
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
1
class UsersController < ApplicationController
2
  layout :determine_layout
3

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

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

19
    @title = @user.name
20

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

  def calendar
    visible_projects = ProjectsFinder.new.execute(current_user)

30
    # Get user repositories and collect timestamps for commits
31
    user_repositories = visible_projects.map(&:repository)
32 33
    calendar = Gitlab::CommitsCalendar.new(user_repositories, @user)
    @timestamps = calendar.timestamps
34 35
    @starting_year = (Time.now - 1.year).strftime("%Y")
    @starting_month = Date.today.strftime("%m").to_i
36

37
    render 'calendar', layout: false
Dmytro Zaporozhets's avatar
Dmytro 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 50 51 52 53 54 55 56

  private

  def authenticate_user!
    @user = User.find_by_username!(params[:username])

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