users_controller.rb 1.56 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
    # Projects user can view
8 9
    visible_projects = ProjectsFinder.new.execute(current_user)
    authorized_projects_ids = visible_projects.pluck(:id)
10

11
    @contributed_projects = Project.where(id: authorized_projects_ids).
12
      in_group_namespace.includes(:namespace)
13

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

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

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

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

  def calendar
    visible_projects = ProjectsFinder.new.execute(current_user)
36
    calendar = Gitlab::CommitsCalendar.new(visible_projects, @user)
37
    @timestamps = calendar.timestamps
38 39
    @starting_year = calendar.starting_year
    @starting_month = calendar.starting_month
40

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

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

  private

54
  def set_user
55 56 57 58 59 60
    @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
61
end