users_controller.rb 1.76 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
    @contributed_projects = contributed_projects.joined(@user).reject(&:forked?)
Josh Frye's avatar
Josh Frye committed
7
    
8
    @projects = PersonalProjectsFinder.new(@user).execute(current_user)
Josh Frye's avatar
Josh Frye committed
9
    @projects = @projects.page(params[:page]).per(PER_PAGE)
10

11
    @groups = @user.groups.order_id_desc
12

13 14
    respond_to do |format|
      format.html
15 16 17 18 19 20

      format.atom do
        load_events
        render layout: false
      end

21 22 23 24
      format.json do
        load_events
        pager_json("events/_events", @events.count)
      end
25 26 27 28
    end
  end

  def calendar
29
    calendar = contributions_calendar
30
    @timestamps = calendar.timestamps
31 32
    @starting_year = calendar.starting_year
    @starting_month = calendar.starting_month
33

34
    render 'calendar', layout: false
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
35
  end
36

37
  def calendar_activities
38 39
    @calendar_date = Date.parse(params[:date]) rescue nil
    @events = []
40

41 42
    if @calendar_date
      @events = contributions_calendar.events_by_date(@calendar_date)
43 44 45 46 47
    end

    render 'calendar_activities', layout: false
  end

48 49
  private

50
  def set_user
51 52
    @user = User.find_by_username!(params[:username])
  end
53

54
  def contributed_projects
55
    ContributedProjectsFinder.new(@user).execute(current_user)
56 57 58 59
  end

  def contributions_calendar
    @contributions_calendar ||= Gitlab::ContributionsCalendar.
60
      new(contributed_projects.reject(&:forked?), @user)
61
  end
62

63 64 65
  def load_events
    # Get user activity feed for projects common for both users
    @events = @user.recent_events.
66 67 68 69 70
      merge(projects_for_current_user).
      references(:project).
      with_associations.
      limit_recent(20, params[:offset])
  end
71

72 73
  def projects_for_current_user
    ProjectsFinder.new.execute(current_user)
74
  end
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
75
end