users_controller.rb 2.66 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
  before_filter :authorize_read_user, only: [:show]
5

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

      format.atom do
        load_events
        render layout: false
      end

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

22 23 24
  def groups
    load_groups

Alfredo Sumaran's avatar
Alfredo Sumaran committed
25
    respond_to do |format|
26
      format.html { render 'show' }
Alfredo Sumaran's avatar
Alfredo Sumaran committed
27 28 29 30 31 32
      format.json do
        render json: {
          html: view_to_html_string("shared/groups/_list", groups: @groups)
        }
      end
    end
33 34
  end

35
  def projects
36 37
    load_projects

Alfredo Sumaran's avatar
Alfredo Sumaran committed
38
    respond_to do |format|
39
      format.html { render 'show' }
Alfredo Sumaran's avatar
Alfredo Sumaran committed
40 41 42 43 44 45
      format.json do
        render json: {
          html: view_to_html_string("shared/projects/_list", projects: @projects, remote: true)
        }
      end
    end
46 47
  end

48
  def contributed
49 50
    load_contributed_projects

Alfredo Sumaran's avatar
Alfredo Sumaran committed
51
    respond_to do |format|
52
      format.html { render 'show' }
Alfredo Sumaran's avatar
Alfredo Sumaran committed
53 54 55 56 57 58
      format.json do
        render json: {
          html: view_to_html_string("shared/projects/_list", projects: @contributed_projects)
        }
      end
    end
59 60
  end

61
  def calendar
62
    calendar = contributions_calendar
63
    @timestamps = calendar.timestamps
64 65
    @starting_year = calendar.starting_year
    @starting_month = calendar.starting_month
66

67
    render 'calendar', layout: false
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
68
  end
69

70
  def calendar_activities
71 72
    @calendar_date = Date.parse(params[:date]) rescue Date.today
    @events = contributions_calendar.events_by_date(@calendar_date)
73 74 75 76

    render 'calendar_activities', layout: false
  end

77
  private
78 79 80
  def authorize_read_user
    render_404 unless @user.public?
  end
81

82
  def set_user
83 84
    @user = User.find_by_username!(params[:username])
  end
85

86
  def contributed_projects
87
    ContributedProjectsFinder.new(@user).execute(current_user)
88 89 90 91
  end

  def contributions_calendar
    @contributions_calendar ||= Gitlab::ContributionsCalendar.
92
      new(contributed_projects, @user)
93
  end
94

95 96 97
  def load_events
    # Get user activity feed for projects common for both users
    @events = @user.recent_events.
98 99 100 101 102
      merge(projects_for_current_user).
      references(:project).
      with_associations.
      limit_recent(20, params[:offset])
  end
103

104 105 106
  def load_projects
    @projects =
      PersonalProjectsFinder.new(@user).execute(current_user)
107
      .page(params[:page])
108 109 110 111 112 113 114
  end

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

  def load_groups
115
    @groups = JoinedGroupsFinder.new(@user).execute(current_user)
116 117
  end

118 119
  def projects_for_current_user
    ProjectsFinder.new.execute(current_user)
120
  end
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
121
end