# Filters added to this controller will be run for all controllers in the # application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base class < action_list end def user_actions(*action_list) verify :session => :rbac_user_id, :redirect_to => {:controller => '/'}, :only => action_list, :add_flash => { :notice => 'You must log in to do that' } end end def current_user session[:rbac_user_id].nil? ? nil : User.find(session[:rbac_user_id]) end def logged_in? current_user.kind_of?(User) end def can_upload_patches?; logged_in?; end def can_edit_patch?(patch); logged_in? and (patch.created_by == current_user.id or current_user.has_role?('Admin')); end def can_update_patch?(patch); can_edit_patch?(patch); end protected def check_for_admin_role if current_user.nil? or not current_user.has_role?('Admin') flash[:error] = "You do not have Admin permissions or are not logged in" redirect_to :action => 'list' return false else return true end end def copy_patches(patch_list, dir) patch_list.each do |p| patch, patch_version = case p when Patch [p, p.latest_version] else [p.patch, p] end FileUtils.cp(patch_version.path, File.join(dir, "#{patch.id}_#{patch.filename}")) end end def patches_to_tgz(patch_list) if HAVE_FEATURE_TAR tar_gz_contents = nil Tempfile.open('patch_tar', TMP_DIR) do |tmpfile| patch_dir = "#{tmpfile.path}.d" FileUtils.mkdir(patch_dir) copy_patches(patch_list, patch_dir) begin sio = StringIO.new class < 'patches.tar.gz'}.merge(user_options) send_data patches_to_tgz(patch_list), :filename => options[:filename] end end