This repository has been archived on 2024-12-01. You can view files and clone it, but cannot push or open issues or pull requests.
redmine_rodax_crm/lib/redmine_contacts/patches/compatibility_patch.rb
2012-01-03 16:18:32 +00:00

76 lines
2.2 KiB
Ruby

require_dependency 'application_controller'
if (Redmine::VERSION.to_a.first(3).join('.') < '1.3.0')
def labelled_fields_for(*args, &proc)
args << {} unless args.last.is_a?(Hash)
options = args.last
options.merge!({:builder => TabularFormBuilder})
fields_for(*args, &proc)
end
def labelled_remote_form_for(*args, &proc)
args << {} unless args.last.is_a?(Hash)
options = args.last
options.merge!({:builder => TabularFormBuilder})
remote_form_for(*args, &proc)
end
def labelled_form_for(*args, &proc)
args << {} unless args.last.is_a?(Hash)
options = args.last
options.merge!({:builder => TabularFormBuilder})
form_for(*args, &proc)
end
end
module RedmineContacts
module Patches
module ApplicationControllerCompatibilityPatch
module InstanceMethods
# Find project of id params[:id]
def find_project
@project = Project.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
# Find project of id params[:project_id]
def find_project_by_project_id
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
render_404
end
# Find a project based on params[:project_id]
# TODO: some subclasses override this, see about merging their logic
def find_optional_project
@project = Project.find(params[:project_id]) unless params[:project_id].blank?
allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
allowed ? true : deny_access
rescue ActiveRecord::RecordNotFound
render_404
end
end
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
end
end
end
end
Dispatcher.to_prepare do
if !ApplicationController.included_modules.include?(RedmineContacts::Patches::ApplicationControllerCompatibilityPatch) && (Redmine::VERSION.to_a.first(3).join('.') < '1.1.0')
ApplicationController.send(:include, RedmineContacts::Patches::ApplicationControllerCompatibilityPatch)
end
end