ensl.org/app/controllers/directories_controller.rb

63 lines
1.5 KiB
Ruby
Raw Normal View History

class DirectoriesController < ApplicationController
before_action :get_directory, except: [:new, :create]
def show
if @directory.hidden
@files = @directory.files
2014-03-31 21:33:16 +00:00
render partial: 'data_files/list', layout: true
else
2020-03-24 21:55:11 +00:00
@directories = Directory.ordered.filtered.where(parent_id: Directory::ROOT)
end
end
def new
@directory = Directory.new
@directory.parent = Directory.find params[:id]
raise AccessError unless @directory.can_create? cuser
end
def edit
raise AccessError unless @directory.can_update? cuser
end
2020-03-31 17:26:55 +00:00
def recreate
raise AccessError unless @cuser&.admin?
@result = @directory.recreate_transaction
@nobody = true
end
def create
@directory = Directory.new(Directory.params(params, cuser))
raise AccessError unless @directory.can_create? cuser
if @directory.save
flash[:notice] = t(:directories_create)
redirect_to(@directory)
else
2014-03-31 21:33:16 +00:00
render :new
end
end
def update
raise AccessError unless @directory.can_update? cuser
if @directory.update_attributes(Directory.params(params, cuser))
flash[:notice] = t(:directories_update)
redirect_to @directory
else
2014-03-31 21:33:16 +00:00
render :edit
end
end
def destroy
raise AccessError unless @directory.can_destroy? cuser
@directory.destroy
redirect_to directory_path(Directory.find(Directory::ROOT))
end
private
def get_directory
@directory = Directory.find params[:id]
end
end