users_controller.rb 1.97 KB
Newer Older
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
1
class UsersController < ApplicationController
2
  skip_before_filter :authenticate_user!, only: [:show, :activities]
3
  layout :determine_layout
4

Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
5
  def show
6
    @user = User.find_by_username!(params[:username])
7

Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
8
    unless current_user || @user.public_profile?
9 10
      return authenticate_user!
    end
11

12
    # Projects user can view
13 14
    visible_projects = ProjectsFinder.new.execute(current_user)
    authorized_projects_ids = visible_projects.pluck(:id)
15 16 17 18 19 20 21 22 23

    @projects = @user.personal_projects.
      where(id: authorized_projects_ids)

    # 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.
24
      where(project_id: authorized_projects_ids).limit(30)
25

26
    @title = @user.name
27

28 29 30
    user_repositories = visible_projects.map(&:repository)
    @timestamps = Gitlab::CommitsCalendar.create_timestamp(user_repositories,
                                                           @user, false)
31 32
    @starting_year = (Time.now - 1.year).strftime("%Y")
    @starting_month = Date.today.strftime("%m").to_i
33 34
    @last_commit_date = Gitlab::CommitsCalendar.last_commit_date(@timestamps)

35 36 37 38
    respond_to do |format|
      format.html
      format.atom { render layout: false }
    end
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
39
  end
40

41 42 43 44 45 46 47 48 49 50 51 52 53
  def activities
    user = User.find_by_username!(params[:username])
    # Projects user can view
    visible_projects = ProjectsFinder.new.execute(current_user)

    user_repositories = visible_projects.map(&:repository)
    user_activities = Gitlab::CommitsCalendar.create_timestamp(user_repositories,
                                                               user, true)
    user_activities = Gitlab::CommitsCalendar.commit_activity_match(
                                              user_activities, params[:date])
    render json: user_activities.to_json
  end

54 55 56 57 58 59 60
  def determine_layout
    if current_user
      'navless'
    else
      'public_users'
    end
  end
Dmytro Zaporozhets's avatar
Dmytro Zaporozhets committed
61
end