application_controller.rb 1.52 KB
Newer Older
1
class Projects::ApplicationController < ApplicationController
2 3
  before_filter :project
  before_filter :repository
4 5 6 7 8 9 10 11 12
  layout :determine_layout

  def authenticate_user!
    # Restrict access to Projects area only
    # for non-signed users
    if !current_user
      id = params[:project_id] || params[:id]
      @project = Project.find_with_namespace(id)

13
      return if @project && @project.public?
14 15 16 17 18 19 20 21 22
    end

    super
  end

  def determine_layout
    if current_user
      'projects'
    else
23
      'public_projects'
24 25
    end
  end
26 27 28 29 30 31

  def require_branch_head
    unless @repository.branch_names.include?(@ref)
      redirect_to project_tree_path(@project, @ref), notice: "This action is not allowed unless you are on top of a branch"
    end
  end
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

  def set_filter_variables(collection)
    params[:sort] ||= 'newest'
    params[:scope] = 'all' if params[:scope].blank?
    params[:state] = 'opened' if params[:state].blank?

    @sort = params[:sort].humanize

    assignee_id = params[:assignee_id]
    author_id = params[:author_id]
    milestone_id = params[:milestone_id]

    if assignee_id.present? && !assignee_id.to_i.zero?
      @assignee = @project.team.find(assignee_id)
    end

    if author_id.present? && !author_id.to_i.zero?
      @author = @project.team.find(assignee_id)
    end

    if milestone_id.present? && !milestone_id.to_i.zero?
      @milestone = @project.milestones.find(milestone_id)
    end

    @assignees = User.where(id: collection.pluck(:assignee_id))
    @authors = User.where(id: collection.pluck(:author_id))
  end
59
end