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

Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
6
  def show
7 8
    @contributed_projects = Project.
      where(id: authorized_projects_ids & @user.contributed_projects_ids).
9 10 11
      in_group_namespace.
      includes(:namespace).
      reject(&:forked?)
12

13
    @projects = @user.personal_projects.
14
      where(id: authorized_projects_ids).includes(:namespace)
15 16 17 18 19 20

    # 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.
21
      where(project_id: authorized_projects_ids).
22
      with_associations.limit(30)
23

24
    @title = @user.name
25
    @title_url = user_path(@user)
26

27 28 29 30 31 32 33
    respond_to do |format|
      format.html
      format.atom { render layout: false }
    end
  end

  def calendar
34 35
    projects = Project.where(id: authorized_projects_ids & @user.contributed_projects_ids)
    calendar = Gitlab::CommitsCalendar.new(projects, @user)
36
    @timestamps = calendar.timestamps
37 38
    @starting_year = calendar.starting_year
    @starting_month = calendar.starting_month
39

40
    render 'calendar', layout: false
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
41
  end
42 43 44 45 46 47 48 49

  def determine_layout
    if current_user
      'navless'
    else
      'public_users'
    end
  end
50 51 52

  private

53
  def set_user
54 55 56 57 58 59
    @user = User.find_by_username!(params[:username])

    unless current_user || @user.public_profile?
      return authenticate_user!
    end
  end
60 61 62 63 64 65

  def authorized_projects_ids
    # Projects user can view
    @authorized_projects_ids ||=
      ProjectsFinder.new.execute(current_user).pluck(:id)
  end
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
66
end