BigW Consortium Gitlab

users_controller.rb 3.08 KB
Newer Older
1
class UsersController < ApplicationController
2 3
  include RoutableActions

4
  skip_before_action :authenticate_user!
5
  before_action :user, except: [:exists]
6

7
  def show
8 9
    respond_to do |format|
      format.html
10 11 12 13 14 15

      format.atom do
        load_events
        render layout: false
      end

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

23 24 25
  def groups
    load_groups

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

36
  def projects
37 38
    load_projects

39
    respond_to do |format|
40
      format.html { render 'show' }
41 42
      format.json do
        render json: {
43
          html: view_to_html_string("shared/projects/_list", projects: @projects)
44 45 46
        }
      end
    end
47 48
  end

49
  def contributed
50 51
    load_contributed_projects

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

62 63 64 65 66 67 68
  def snippets
    load_snippets

    respond_to do |format|
      format.html { render 'show' }
      format.json do
        render json: {
69
          html: view_to_html_string("snippets/_snippets", collection: @snippets)
70 71 72 73 74
        }
      end
    end
  end

75
  def calendar
76
    calendar = contributions_calendar
77
    @activity_dates = calendar.activity_dates
78

79
    render 'calendar', layout: false
80
  end
81

82
  def calendar_activities
83 84
    @calendar_date = Date.parse(params[:date]) rescue Date.today
    @events = contributions_calendar.events_by_date(@calendar_date)
85 86 87 88

    render 'calendar_activities', layout: false
  end

89
  def exists
90
    render json: { exists: !!Namespace.find_by_path_or_name(params[:username]) }
91 92
  end

93
  private
Felipe Artur committed
94

Felipe Artur committed
95
  def user
96
    @user ||= find_routable!(User, params[:username])
97
  end
98

99
  def contributed_projects
Felipe Artur committed
100
    ContributedProjectsFinder.new(user).execute(current_user)
101 102 103
  end

  def contributions_calendar
104
    @contributions_calendar ||= Gitlab::ContributionsCalendar.new(user, current_user)
105
  end
106

107 108
  def load_events
    # Get user activity feed for projects common for both users
Felipe Artur committed
109
    @events = user.recent_events.
110 111 112 113 114
      merge(projects_for_current_user).
      references(:project).
      with_associations.
      limit_recent(20, params[:offset])
  end
115

116 117
  def load_projects
    @projects =
Felipe Artur committed
118
      PersonalProjectsFinder.new(user).execute(current_user)
119
      .page(params[:page])
120 121 122
  end

  def load_contributed_projects
Felipe Artur committed
123
    @contributed_projects = contributed_projects.joined(user)
124 125 126
  end

  def load_groups
Felipe Artur committed
127
    @groups = JoinedGroupsFinder.new(user).execute(current_user)
128 129
  end

130
  def load_snippets
131
    @snippets = SnippetsFinder.new(
132
      current_user,
133
      author: user,
134
      scope: params[:scope]
135
    ).execute.page(params[:page])
136 137
  end

138
  def projects_for_current_user
139
    ProjectsFinder.new(current_user: current_user).execute
140
  end
141 142 143 144

  def build_canonical_path(user)
    url_for(params.merge(username: user.to_param))
  end
145
end