groups_controller.rb 1.85 KB
Newer Older
randx's avatar
randx committed
1 2 3 4 5 6 7
class GroupsController < ApplicationController
  respond_to :html
  layout 'group'

  before_filter :group
  before_filter :projects

8 9 10
  # Authorize
  before_filter :authorize_read_group!

randx's avatar
randx committed
11
  def show
12
    @events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0)
randx's avatar
randx committed
13 14 15 16 17 18 19 20 21 22 23
    @last_push = current_user.recent_push

    respond_to do |format|
      format.html
      format.js
      format.atom { render layout: false }
    end
  end

  # Get authored or assigned open merge requests
  def merge_requests
24
    @merge_requests = current_user.cared_merge_requests
25
    @merge_requests = @merge_requests.of_group(@group).recent.page(params[:page]).per(20)
randx's avatar
randx committed
26 27 28 29 30
  end

  # Get only assigned issues
  def issues
    @user   = current_user
31
    @issues = current_user.assigned_issues.opened
32
    @issues = @issues.of_group(@group).recent.page(params[:page]).per(20)
randx's avatar
randx committed
33 34 35 36 37 38 39 40 41
    @issues = @issues.includes(:author, :project)

    respond_to do |format|
      format.html
      format.atom { render layout: false }
    end
  end

  def search
42
    result = SearchContext.new(project_ids, params).execute
randx's avatar
randx committed
43

44 45 46
    @projects       = result[:projects]
    @merge_requests = result[:merge_requests]
    @issues         = result[:issues]
randx's avatar
randx committed
47 48 49
  end

  def people
50 51
    @project = group.projects.find(params[:project_id]) if params[:project_id]
    @users = @project ? @project.users : group.users
52
    @users.sort_by!(&:name)
53 54 55 56

    if @project
      @team_member = @project.users_projects.new
    end
randx's avatar
randx committed
57 58 59 60 61
  end

  protected

  def group
62
    @group ||= Group.find_by_path(params[:id])
randx's avatar
randx committed
63 64 65
  end

  def projects
66
    @projects ||= group.projects.authorized_for(current_user).sorted_by_activity
randx's avatar
randx committed
67 68 69 70 71
  end

  def project_ids
    projects.map(&:id)
  end
72 73 74 75 76 77 78

  # Dont allow unauthorized access to group
  def authorize_read_group!
    unless projects.present? or can?(current_user, :manage_group, @group)
      return render_404
    end
  end
randx's avatar
randx committed
79
end