Read about our upcoming Code of Conduct on this issue

application_controller.rb 852 Bytes
Newer Older
Valery Sizov's avatar
Valery Sizov committed
1
class Groups::ApplicationController < ApplicationController
2
  layout 'group'
Douwe Maan's avatar
Douwe Maan committed
3
4

  skip_before_action :authenticate_user!
5
  before_action :group
Valery Sizov's avatar
Valery Sizov committed
6
7

  private
8
9

  def group
Douwe Maan's avatar
Douwe Maan committed
10
11
    unless @group
      id = params[:group_id] || params[:id]
12
      @group = Group.find_by_full_path(id)
Douwe Maan's avatar
Douwe Maan committed
13
14
15

      unless @group && can?(current_user, :read_group, @group)
        @group = nil
16

Douwe Maan's avatar
Douwe Maan committed
17
18
19
20
21
        if current_user.nil?
          authenticate_user!
        else
          render_404
        end
22
23
      end
    end
Douwe Maan's avatar
Douwe Maan committed
24
25
26
27
28
29

    @group
  end

  def group_projects
    @projects ||= GroupProjectsFinder.new(group).execute(current_user)
30
  end
31

Valery Sizov's avatar
Valery Sizov committed
32
  def authorize_admin_group!
33
    unless can?(current_user, :admin_group, group)
Valery Sizov's avatar
Valery Sizov committed
34
35
36
      return render_404
    end
  end
37

Douwe Maan's avatar
Douwe Maan committed
38
39
40
41
42
  def authorize_admin_group_member!
    unless can?(current_user, :admin_group_member, group)
      return render_403
    end
  end
Valery Sizov's avatar
Valery Sizov committed
43
end