Skip to content

Commit

Permalink
updated for Rails 4+ compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
hishammalik committed Sep 1, 2021
1 parent b233391 commit cfb050e
Show file tree
Hide file tree
Showing 70 changed files with 773 additions and 667 deletions.
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ redmine_version_major = version_file.match(/MAJOR =/).post_match.match(/\d/)[0].

gem "holidays", "~>1.0.3"
gem "icalendar"
gem "nokogiri", "~>1.6.8"
#gem "nokogiri", "~>1.6.8"
gem "open-uri-cached"
gem "prawn"
#gem "prawn"
gem 'json'

group :development do
Expand Down Expand Up @@ -40,3 +40,5 @@ end
# moved out of the dev group so backlogs can be tested by the user after install. Too many issues of weird setups with apache, nginx, etc.
# thin doesn't work for jruby
gem "thin", :platforms => [:ruby]
gem 'octokit', require: false
gem 'inifile', require: false
2 changes: 1 addition & 1 deletion app/controllers/rb_all_projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class RbAllProjectsController < ApplicationController
unloadable

before_filter :authorize_global
before_action :authorize_global

def statistics
backlogs_projects = RbCommonHelper.find_backlogs_enabled_active_projects
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/rb_application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class RbApplicationController < ApplicationController
unloadable

before_filter :load_project, :authorize, :check_if_plugin_is_configured
before_action :load_project, :authorize, :check_if_plugin_is_configured

#provide list of javascript_include_tags which must be rendered before common.js
def rb_jquery_plugins
Expand Down Expand Up @@ -38,10 +38,9 @@ def check_if_plugin_is_configured
# make a copy to workaround RuntimeError (can't modify frozen ActionController::Parameters):
s1 = @settings.dup
if s1[:story_trackers].blank? || s1[:task_tracker].blank?
puts("check_if_plugin_is_configured: something is blank, halting. #{s1}")
respond_to do |format|
format.html { render :template => "backlogs/not_configured", :handlers => [:erb], :formats => [:html] }
format.js { }
format.js {head :no_content }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/rb_calendars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RbCalendarsController < RbApplicationController

case Backlogs.platform
when :redmine
before_filter :require_admin_or_api_request, :only => :ical
before_action :require_admin_or_api_request, :only => :ical
accept_api_auth :ical
when :chiliproject
accept_key_auth :ical
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/rb_impediments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def create
begin
@impediment = RbTask.create_with_relationships(params, User.current.id, @project.id, true)
rescue => e
render :text => e.message.blank? ? e.to_s : e.message, :status => 400
render plain: e.message.blank? ? e.to_s : e.message, :status => 400
return
end

Expand All @@ -27,7 +27,7 @@ def update
begin
result = @impediment.update_with_relationships(params)
rescue => e
render :text => e.message.blank? ? e.to_s : e.message, :status => 400
render plain: e.message.blank? ? e.to_s : e.message, :status => 400
return
end
status = (result ? 200 : 400)
Expand Down
9 changes: 5 additions & 4 deletions app/controllers/rb_releases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ def edit
end

def update
except = ['id', 'project_id']
attribs = params.select{|k,v| (!except.include? k) and (RbRelease.column_names.include? k) }
attribs = Hash[*attribs.flatten]
except = ['id', 'project_id', 'authenticity_token', 'action', 'controller', '_method'] - RbRelease.column_names
# attribs = params.select{|k,v| (!except.include? k) and (RbRelease.column_names.include? k) }
# attribs = Hash[*attribs.flatten]
attribs = params.except(*except).permit!.to_h
begin
result = @release.update_attributes attribs
rescue => e
Rails.logger.debug e
Rails.logger.debug e.backtrace.join("\n")
render :text => e.message.blank? ? e.to_s : e.message, :status => 400
render plain: e.message.blank? ? e.to_s : e.message, :status => 400
return
end

Expand Down
8 changes: 3 additions & 5 deletions app/controllers/rb_server_variables_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ class RbServerVariablesController < RbApplicationController

# for index there's no @project
# (eliminates the need of RbAllProjectsController)
skip_before_filter :load_project, :authorize, :only => [:index]
skip_before_action :load_project, :authorize, :only => [:index]

def index
@context = params[:context]

respond_to do |format|
Rails.logger.warn("Format problem #{format}")
# Rails.logger.warn("Format problem #{format}")
format.html { render_404 }
format.js { render :template => 'rb_server_variables/show', :layout => false, :handlers => [:erb], :formats => [:js] }
#format.js { render js: "alert('Hello Rails');" }
format.js { render 'show', layout: false}
end
end

Expand Down
19 changes: 11 additions & 8 deletions app/controllers/rb_sprints_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class RbSprintsController < RbApplicationController
accept_api_auth :download

def create
attribs = params.select{|k,v| k != 'id' and RbSprint.column_names.include? k }
attribs = Hash[*attribs.flatten]
except = %w[id authenticity_token action controller _method] - RbSprint.column_names
# attribs = params.select{|k,v| k != 'id' and RbSprint.column_names.include? k }
# attribs = Hash[*attribs.flatten]
attribs = params.except(*except).permit!.to_h
@sprint = RbSprint.new(attribs)

#share the sprint according to the global setting
Expand All @@ -28,7 +30,7 @@ def create
rescue => e
Rails.logger.debug e
Rails.logger.debug e.backtrace.join("\n")
render :text => e.message.blank? ? e.to_s : e.message, :status => 400
render plain: e.message.blank? ? e.to_s : e.message, :status => 400
return
end

Expand All @@ -41,15 +43,16 @@ def create
end

def update
except = ['id', 'project_id']
attribs = params.select{|k,v| (!except.include? k) and (RbSprint.column_names.include? k) }
attribs = Hash[*attribs.flatten]
except = %w[id project_id authenticity_token action controller _method] - RbSprint.column_names
# attribs = params.select{|k,v| (!except.include? k) and (RbSprint.column_names.include? k) }
# attribs = Hash[*attribs.flatten]
attribs = params.except(*except).permit!.to_h
begin
result = @sprint.update_attributes attribs
rescue => e
Rails.logger.debug e
Rails.logger.debug e.backtrace.join("\n")
render :text => e.message.blank? ? e.to_s : e.message, :status => 400
render plain: e.message.blank? ? e.to_s : e.message, :status => 400
return
end

Expand Down Expand Up @@ -87,7 +90,7 @@ def download

def reset
unless @sprint.sprint_start_date
render :text => 'Sprint without start date cannot be reset', :status => 400
render plain: 'Sprint without start date cannot be reset', :status => 400
return
end

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/rb_stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class RbStoriesController < RbApplicationController

def index
if ! BacklogsPrintableCards::CardPageLayout.selected
render :text => "No label stock selected. How did you get here?", :status => 500
render plain: "No label stock selected. How did you get here?", :status => 500
return
end

begin
cards = BacklogsPrintableCards::PrintableCards.new(params[:sprint_id] ? @sprint.stories : RbStory.product_backlog(@project), params[:sprint_id], current_language)
rescue Prawn::Errors::CannotFit
render :text => "There was a problem rendering the cards. A possible error could be that the selected font exceeds a render box", :status => 500
render plain: "There was a problem rendering the cards. A possible error could be that the selected font exceeds a render box", :status => 500
return
end

Expand All @@ -32,7 +32,7 @@ def create
begin
story = RbStory.create_and_position(params)
rescue => e
render :text => e.message.blank? ? e.to_s : e.message, :status => 400
render plain: e.message.blank? ? e.to_s : e.message, :status => 400
return
end

Expand All @@ -48,7 +48,7 @@ def update
begin
result = story.update_and_position!(params)
rescue => e
render :text => e.message.blank? ? e.to_s : e.message, :status => 400
render plain: e.message.blank? ? e.to_s : e.message, :status => 400
return
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/rb_tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def create
begin
@task = RbTask.create_with_relationships(params, User.current.id, @project.id)
rescue => e
render :text => e.message.blank? ? e.to_s : e.message, :status => 400
render plain: e.message.blank? ? e.to_s : e.message, :status => 400
return
end

Expand Down
5 changes: 3 additions & 2 deletions app/helpers/rb_partials_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ class << self

def def_erb_method(method_name_and_args, filename)
erb_data = File.read(filename)
eruby = Erubis::FastEruby.new(erb_data)
eruby = ERB.new(erb_data)
eruby.def_method(self, method_name_and_args)
method_name = method_name_and_args[/^[^(]+/].strip.to_sym
define_method "#{method_name}_with_html_safe" do |*args, &block|
send("#{method_name}_without_html_safe", *args, &block).html_safe
end
alias_method_chain method_name, :html_safe
alias_method "#{method_name}_without_html_safe", method_name
alias_method method_name, "#{method_name}_with_html_safe"
method_name
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/rb_issue_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class RbIssueHistory < ActiveRecord::Base
self.table_name = 'rb_issue_history'
attr_protected :created_at # hack, all attributes will be mass asigment
# attr_protected :created_at # hack, all attributes will be mass asigment
belongs_to :issue

serialize :history, Array
Expand Down
2 changes: 1 addition & 1 deletion app/models/rb_journal.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class RbJournal < ActiveRecord::Base
unloadable
attr_protected :created_at # hack, all attributes will be mass asigment
# attr_protected :created_at # hack, all attributes will be mass asigment
end
4 changes: 2 additions & 2 deletions app/models/rb_project_settings.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class RbProjectSettings < ActiveRecord::Base
unloadable
attr_protected :created_at # hack, all attributes will be mass asigment
# attr_protected :created_at # hack, all attributes will be mass asigment
belongs_to :project
attr_accessible :project_id
# attr_accessible :project_id
end

4 changes: 2 additions & 2 deletions app/models/rb_release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ class RbRelease < ActiveRecord::Base
has_many :issues, :class_name => 'RbStory', :foreign_key => 'release_id', :dependent => :nullify
has_many :rb_release_burnchart_day_cache, :dependent => :delete_all, :foreign_key => 'release_id'

attr_accessible :project_id, :name, :release_start_date, :release_end_date, :status
attr_accessible :project, :description, :planned_velocity, :sharing
# attr_accessible :project_id, :name, :release_start_date, :release_end_date, :status
# attr_accessible :project, :description, :planned_velocity, :sharing

validates_presence_of :project_id, :name, :release_start_date, :release_end_date
validates_inclusion_of :status, :in => RELEASE_STATUSES
Expand Down
2 changes: 1 addition & 1 deletion app/models/rb_release_burnchart_day_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Table layout optimized for quickly summing up release burncharts.
class RbReleaseBurnchartDayCache < ActiveRecord::Base
unloadable
attr_protected :created_at # hack, all attributes will be mass asigment
# attr_protected :created_at # hack, all attributes will be mass asigment
belongs_to :issue
belongs_to :release

Expand Down
4 changes: 2 additions & 2 deletions app/models/rb_release_multiview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ class RbReleaseMultiview < ActiveRecord::Base
self.table_name = 'rb_releases_multiview'

unloadable
attr_protected :created_at # hack, all attributes will be mass asigment
# attr_protected :created_at # hack, all attributes will be mass asigment

belongs_to :project

attr_accessible :name, :project_id, :release_ids, :project, :description
# attr_accessible :name, :project_id, :release_ids, :project, :description
serialize :release_ids

validates_presence_of :project_id, :name
Expand Down
2 changes: 1 addition & 1 deletion app/models/rb_sprint_burndown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RbSprintBurndown < ActiveRecord::Base
self.table_name = 'rb_sprint_burndown'
belongs_to :version

attr_accessible :directon, :version_id, :stories, :burndown
# attr_accessible :directon, :version_id, :stories, :burndown

serialize :stories, Array
serialize :burndown, Hash
Expand Down
4 changes: 2 additions & 2 deletions app/models/rb_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

class RbStats < ActiveRecord::Base
attr_protected :created_at # hack, all attributes will be mass asigment
# attr_protected :created_at # hack, all attributes will be mass asigment
REDMINE_PROPERTIES = ['estimated_hours', 'fixed_version_id', 'status_id', 'story_points', 'remaining_hours']
JOURNALED_PROPERTIES = {
'estimated_hours' => :float,
Expand Down Expand Up @@ -84,7 +84,7 @@ def self.journal_property_value(property, j)
end

def self.rebuild(issue)
RbJournal.delete_all(:issue_id => issue.id)
RbJournal.where(:issue_id => issue.id).delete_all

changes = {}
RbJournal::REDMINE_PROPERTIES.each{|prop| changes[prop] = [] }
Expand Down
18 changes: 10 additions & 8 deletions app/models/rb_story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ def self.create_and_position(params)
params['prev'] = nil if (['next', 'prev'] - params.keys).size == 2

# lft and rgt fields are handled by acts_as_nested_set
attribs = params.select{|k,v| !['prev', 'next', 'id', 'lft', 'rgt'].include?(k) && RbStory.column_names.include?(k) }

except = %w[prev next id lft rigt authenticity_token action controller _method] - RbStory.column_names
# attribs = params.select{|k,v| !['prev', 'next', 'id', 'lft', 'rgt'].include?(k) && RbStory.column_names.include?(k) }
# attribs = Hash[*attribs.flatten]
attribs = params.except(*except).permit!.to_h
attribs[:status] = RbStory.class_default_status
attribs = Hash[*attribs.flatten]
s = RbStory.new(attribs)
s.save!
s.position!(params)
Expand Down Expand Up @@ -261,10 +262,11 @@ def update_and_position!(params)
params['next'] = params.delete('next_id') if params.include?('next_id')
self.position!(params)

except = %w[prev next id project_id lft rigt authenticity_token action controller _method] - RbStory.column_names
# lft and rgt fields are handled by acts_as_nested_set
attribs = params.select{|k,v| !['prev', 'id', 'project_id', 'lft', 'rgt'].include?(k) && RbStory.column_names.include?(k) }
attribs = Hash[*attribs.flatten]

# attribs = params.select{|k,v| !['prev', 'id', 'project_id', 'lft', 'rgt'].include?(k) && RbStory.column_names.include?(k) }
# attribs = Hash[*attribs.flatten]
attribs = params.except(*except).permit!.to_h
return self.journalized_update_attributes attribs
end

Expand All @@ -291,11 +293,11 @@ def update_release_burnchart_data(days,release_burndown_id)
end

def save_release_burnchart_data(series,release_burndown_id)
RbReleaseBurnchartDayCache.delete_all(
RbReleaseBurnchartDayCache.where(
["issue_id = ? AND release_id = ? AND day IN (?)",
self.id,
release_burndown_id,
series.series(:day)])
series.series(:day)]).delete_all

series.each{|s|
RbReleaseBurnchartDayCache.create(:issue_id => self.id,
Expand Down
7 changes: 4 additions & 3 deletions app/models/rb_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ def self.rb_safe_attributes(params)
:project_id=>params[:project_id] # required to verify "safeness"
).safe_attribute_names
end
attribs = params.select {|k,v| safe_attributes_names.include?(k) }
# attribs = params.select {|k,v| safe_attributes_names.include?(k) }
# lft and rgt fields are handled by acts_as_nested_set
attribs = attribs.select{|k,v| k != 'lft' and k != 'rgt' }
attribs = Hash[*attribs.flatten] if attribs.is_a?(Array)
# attribs = attribs.select{|k,v| k != 'lft' and k != 'rgt' }
# attribs = Hash[*attribs.flatten] if attribs.is_a?(Array)
attribs = params.permit(safe_attributes_names - %w[lft rgt]).permit!.to_h
return attribs
end

Expand Down
6 changes: 3 additions & 3 deletions app/workers/backlogs_after_save.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class BacklogsAfterSave
include Sidekiq::Worker
# include ::Sidekiq::Worker

sidekiq_options queue: :backlogs,
backtrace: true
# sidekiq_options queue: :backlogs,
# backtrace: true

def perform(issue_id)
Issue.find(issue_id).backlogs_after_save_async
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateStoriesTasksSprintsAndBurndown < ActiveRecord::Migration
class CreateStoriesTasksSprintsAndBurndown < ActiveRecord::Migration[4.2]
def self.up
add_column :issues, :position, :integer
add_column :issues, :story_points, :integer
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/012_migrate_legacy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class MigrateLegacy < ActiveRecord::Migration
class MigrateLegacy < ActiveRecord::Migration[4.2]
def self.normalize_value(v, t)
v = v[1] if v.is_a?(Array)

Expand Down
Loading

0 comments on commit cfb050e

Please sign in to comment.