Skip to content

Commit

Permalink
Merge pull request #3 from jrupesh/master
Browse files Browse the repository at this point in the history
Skip inclusion filter and avoid modification of the core redmine.
  • Loading branch information
alexwais committed Oct 9, 2014
2 parents 8229f33 + 49863dc commit 18da21d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ The plugin was developed and tested with Redmine version 2.5.2.

- Put the plugin folder into your Redmine's /plugin directory.

- Edit the file /app/models/workflow_permission.rb inside your Redmine installation:

Change line 19 from
`validates_inclusion_of :rule, :in => %w(readonly required)`
to
`validates_inclusion_of :rule, :in => %w(readonly required hidden)`
and save that file.

- Restart your Redmine.


Expand Down
20 changes: 6 additions & 14 deletions lib/redmine_workflow_hidden_fields/workflow_permission_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@ module RedmineWorkflowHiddenFields
module WorkflowPermissionPatch
def self.included(base)
base.send(:include, InstanceMethods)
#base.extend(ClassMethods)
base.class_eval do

# HACK: Remove the existing validates_uniqueness_of block
#
# The filters are part of validators are raw, they can be skipped with the following way.
rule_inclusion_validation = base._validators[:rule].find{ |validator| validator.is_a? ActiveModel::Validations::InclusionValidator }
base._validators[:rule].delete(rule_inclusion_validation)
filter = base._validate_callbacks.find{ |c| c.raw_filter == rule_inclusion_validation }.filter
skip_callback :validate, filter

# Add new validates_uniqueness_of with correct scope
#validates_uniqueness_of :name, :case_sensitive => false, :scope => :site_id



#validates_inclusion_of :rule, :in => %w(readonly required hidden)
_validators.reject!{ |key, _| key == :rule }

#_validate_callbacks.reject! do |callback|
# callback.raw_filter.attributes == [:rule]
#end
validates_inclusion_of :rule, :in => %w(readonly required hidden)
end
end

Expand Down

0 comments on commit 18da21d

Please sign in to comment.