users_controller.rb 2.22 KB
Newer Older
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
1
class UsersController < ApplicationController
2 3
  skip_before_action :authenticate_user!
  before_action :set_user
4

Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
5
  def show
6 7
    respond_to do |format|
      format.html
8 9 10 11 12 13

      format.atom do
        load_events
        render layout: false
      end

14 15 16 17
      format.json do
        load_events
        pager_json("events/_events", @events.count)
      end
18 19 20
    end
  end

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
  def groups
    load_groups

    render 'shared/groups/_list', locals: { groups: @groups }, layout: false
  end

  def user_projects
    load_projects

    render 'shared/projects/_list', locals: { projects: @projects, remote: true }, layout: false
  end

  def user_contributed_projects
    load_contributed_projects

    render 'shared/projects/_list', locals: { projects: @contributed_projects }, layout: false
  end

39
  def calendar
40
    calendar = contributions_calendar
41
    @timestamps = calendar.timestamps
42 43
    @starting_year = calendar.starting_year
    @starting_month = calendar.starting_month
44

45
    render 'calendar', layout: false
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
46
  end
47

48
  def calendar_activities
49 50
    @calendar_date = Date.parse(params[:date]) rescue nil
    @events = []
51

52 53
    if @calendar_date
      @events = contributions_calendar.events_by_date(@calendar_date)
54 55 56 57 58
    end

    render 'calendar_activities', layout: false
  end

59 60
  private

61
  def set_user
62 63
    @user = User.find_by_username!(params[:username])
  end
64

65
  def contributed_projects
66
    ContributedProjectsFinder.new(@user).execute(current_user)
67 68 69 70
  end

  def contributions_calendar
    @contributions_calendar ||= Gitlab::ContributionsCalendar.
71
      new(contributed_projects.reject(&:forked?), @user)
72
  end
73

74 75 76
  def load_events
    # Get user activity feed for projects common for both users
    @events = @user.recent_events.
77 78 79 80 81
      merge(projects_for_current_user).
      references(:project).
      with_associations.
      limit_recent(20, params[:offset])
  end
82

83 84 85 86 87 88 89 90 91 92 93 94 95 96
  def load_projects
    @projects =
      PersonalProjectsFinder.new(@user).execute(current_user)
      .page(params[:page]).per(PER_PAGE)
  end

  def load_contributed_projects
    @contributed_projects = contributed_projects.joined(@user)
  end

  def load_groups
    @groups = @user.groups.order_id_desc
  end

97 98
  def projects_for_current_user
    ProjectsFinder.new.execute(current_user)
99
  end
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
100
end