Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# German strings go here for Rails i18n | ||
de: | ||
activerecord: | ||
errors: | ||
messages: | ||
prefix_invalid: "muss den Präfix \"%{prefix}\" haben" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# English strings go here for Rails i18n | ||
en: | ||
activerecord: | ||
errors: | ||
messages: | ||
prefix_invalid: "must start with \"%{prefix}\"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
lib/chiliproject_ensure_project_hierarchy/projects_controller_patch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
::Project::IDENTIFIER_SEPARATOR = "-" | ||
|
||
module Plugin | ||
module EnsureProjectHierarchy | ||
module ProjectsController | ||
module ClassMethods | ||
|
||
end | ||
|
||
module InstanceMethods | ||
private | ||
|
||
def new_with_default_identifier_for_new_subprojects | ||
new_without_default_identifier_for_new_subprojects | ||
if params[:parent_id] | ||
parent_project = Project.find params[:parent_id] | ||
puts "Do I get here? And who is the parent_project? " + parent_project.inspect | ||
@project.identifier = "#{parent_project.identifier}#{::Project::IDENTIFIER_SEPARATOR}" | ||
puts "wheeeee! " + @project.inspect | ||
end | ||
end | ||
|
||
def validate_parent_id_with_identifier_hierarchy | ||
return true if User.current.admin? | ||
return false unless validate_parent_id_without_identifier_hierarchy | ||
parent_id = params[:project] && params[:project][:parent_id] | ||
if parent_id || @project.new_record? | ||
parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i) | ||
if parent && !@project.identifier.match("#{Regexp.escape(parent.identifier + ::Project::IDENTIFIER_SEPARATOR)}.+") | ||
@project.errors.add :identifier, :prefix_invalid, :prefix => "#{parent.identifier}-" | ||
return false | ||
end | ||
end | ||
true | ||
end | ||
end | ||
|
||
def self.included(receiver) | ||
receiver.extend ClassMethods | ||
receiver.send :include, InstanceMethods | ||
receiver.class_eval do | ||
unloadable | ||
|
||
alias_method_chain :new, :default_identifier_for_new_subprojects | ||
alias_method_chain :validate_parent_id, :identifier_hierarchy | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
ProjectsController.send(:include, Plugin::EnsureProjectHierarchy::ProjectsController) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters