users_controller.rb 2.09 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
    calendar = contributions_calendar
35
    @timestamps = calendar.timestamps
36 37
    @starting_year = calendar.starting_year
    @starting_month = calendar.starting_month
38

39
    render 'calendar', layout: false
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
40
  end
41

42
  def calendar_activities
43 44
    @calendar_date = Date.parse(params[:date]) rescue nil
    @events = []
45

46 47
    if @calendar_date
      @events = contributions_calendar.events_by_date(@calendar_date)
48 49 50 51 52
    end

    render 'calendar_activities', layout: false
  end

53 54 55 56 57 58 59
  def determine_layout
    if current_user
      'navless'
    else
      'public_users'
    end
  end
60 61 62

  private

63
  def set_user
64 65 66 67 68 69
    @user = User.find_by_username!(params[:username])

    unless current_user || @user.public_profile?
      return authenticate_user!
    end
  end
70 71 72 73 74 75

  def authorized_projects_ids
    # Projects user can view
    @authorized_projects_ids ||=
      ProjectsFinder.new.execute(current_user).pluck(:id)
  end
76 77 78 79 80 81 82 83 84 85

  def contributed_projects
    @contributed_projects = Project.
      where(id: authorized_projects_ids & @user.contributed_projects_ids).reject(&:forked?)
  end

  def contributions_calendar
    @contributions_calendar ||= Gitlab::ContributionsCalendar.
      new(contributed_projects, @user)
  end
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
86
end