summaryrefslogtreecommitdiff
path: root/app/controllers/generic_files_controller.rb
blob: b7dc453e4edb2543e9f666aa7efcd52a131d1db2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
59
60
61
62
63
64
class GenericFilesController < ApplicationController

  load_resource :sip_account
  load_resource :conference
  load_resource :hunt_group
  load_resource :automatic_call_distributor
  load_resource :user
  load_resource :tenant
  load_resource :generic_file

  load_and_authorize_resource :generic_file, :through => [:sip_account, :conference, :hunt_group, :automatic_call_distributor, :user, :tenant]

  before_filter :set_and_authorize_parent

  def index
    @generic_files = @parent.generic_files
  end

  def show
    
  end

  def new
    @generic_file = @parent.generic_files.build()
  end

  def create
    @generic_file = @parent.generic_files.new(params[:generic_file])
    if @generic_file.save
      m = method( :"#{@parent.class.name.underscore}_generic_files_url" )
      redirect_to m.( @parent ), :notice => t('generic_files.controller.successfuly_created')
    else
      render :new
    end
  end

  def edit
    @generic_file = GenericFile.find(params[:id])
  end

  def update
    @generic_file = GenericFile.find(params[:id])
    if @generic_file.update_attributes(params[:generic_file])
      m = method( :"#{@parent.class.name.underscore}_generic_files_url" )
      redirect_to m.( @parent ), :notice  => t('generic_files.controller.successfuly_updated')
    else
      render :edit
    end
  end

  def destroy
    @generic_file = GenericFile.find(params[:id])
    @generic_file.destroy
    m = method( :"#{@parent.class.name.underscore}_generic_files_url" )
    redirect_to m.( @parent ), :notice => t('generic_files.controller.successfuly_destroyed')
  end

  private
  def set_and_authorize_parent
    @parent = @sip_account || @conference || @hunt_group || @automatic_call_distributor || @user || @tenant

    authorize! :read, @parent
  end
end