users_controller.rb 1.49 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
    @contributed_projects = Project.where(id: authorized_projects_ids).
      in_group_namespace

14 15 16 17 18 19 20 21
    @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.
22
      where(project_id: authorized_projects_ids).limit(30)
23

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

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

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

40
    render 'calendar', layout: false
Dmitriy Zaporozhets's avatar
Dmitriy 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
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
60
end