Skip to content

Commit

Permalink
Removed validation constraint on account name.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveyken committed Mar 13, 2013
1 parent 54c9f81 commit effd774
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 10 deletions.
49 changes: 48 additions & 1 deletion .rvmrc
@@ -1 +1,48 @@
rvm use ruby-1.9.3-p362 #!/usr/bin/env bash

# This is an RVM Project .rvmrc file, used to automatically load the ruby
# development environment upon cd'ing into the directory

# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
# Only full ruby name is supported here, for short names use:
# echo "rvm use 1.9.3" > .rvmrc
environment_id="ruby-1.9.3-p362"

# Uncomment the following lines if you want to verify rvm version per project
# rvmrc_rvm_version="1.18.6 (stable)" # 1.10.1 seams as a safe start
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
# return 1
# }

# First we attempt to load the desired environment directly from the environment
# file. This is very fast and efficient compared to running through the entire
# CLI and selector. If you want feedback on which environment was used then
# insert the word 'use' after --create as this triggers verbose mode.
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
else
# If the environment file has not yet been created, use the RVM CLI to select.
rvm --create "$environment_id" || {
echo "Failed to create RVM environment '${environment_id}'."
return 1
}
fi

# If you use bundler, this might be useful to you:
# if [[ -s Gemfile ]] && {
# ! builtin command -v bundle >/dev/null ||
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
# }
# then
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
# gem install bundler
# fi
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
# then
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
# fi
31 changes: 22 additions & 9 deletions app/controllers/merge_controller.rb
Expand Up @@ -9,9 +9,9 @@ class MergeController < EntitiesController
before_filter :require_application, :only => :aliases before_filter :require_application, :only => :aliases


respond_to :html, :js respond_to :html, :js

helper_method :klass helper_method :klass

# GET /merge/contact/1/into/2 HTML # GET /merge/contact/1/into/2 HTML
# GET /merge/contact/1/into/2 JS # GET /merge/contact/1/into/2 JS
# PUT /merge/account/1/into/2 HTML # PUT /merge/account/1/into/2 HTML
Expand All @@ -24,9 +24,9 @@ def into
authorize! :manage, @duplicate authorize! :manage, @duplicate


# don't merge if either is invalid to start with # don't merge if either is invalid to start with
if !@master.valid? if !valid_object?(@master)
flash[:error] = I18n.t('assets_merge_invalid', :name => @master.name) flash[:error] = I18n.t('assets_merge_invalid', :name => @master.name)
elsif !@duplicate.valid? elsif !valid_object?(@duplicate)
flash[:error] = I18n.t('assets_merge_invalid', :name => @duplicate.name) flash[:error] = I18n.t('assets_merge_invalid', :name => @duplicate.name)
elsif request.put? elsif request.put?
do_merge(@master, @duplicate) do_merge(@master, @duplicate)
Expand All @@ -36,7 +36,7 @@ def into


respond_with(@duplicate) respond_with(@duplicate)
end end

# #
# List out the aliases for a given set of contact ids # List out the aliases for a given set of contact ids
# #
Expand All @@ -56,7 +56,7 @@ def respond_to_access_denied
flash[:warning] = t(:msg_asset_not_authorized, klass.to_s.humanize.downcase) flash[:warning] = t(:msg_asset_not_authorized, klass.to_s.humanize.downcase)
redirect_to :controller => klass.to_s.underscore.pluralize, :action => :index redirect_to :controller => klass.to_s.underscore.pluralize, :action => :index
end end

def respond_to_not_found def respond_to_not_found
flash[:warning] = t(:msg_asset_not_available, klass.to_s.humanize.downcase) flash[:warning] = t(:msg_asset_not_available, klass.to_s.humanize.downcase)
redirect_to :controller => klass.to_s.underscore.pluralize, :action => :index redirect_to :controller => klass.to_s.underscore.pluralize, :action => :index
Expand All @@ -67,7 +67,7 @@ def klass
name = params[:klass_name].classify name = params[:klass_name].classify
klass = (ENTITIES.include?(name) ? name.constantize : nil) klass = (ENTITIES.include?(name) ? name.constantize : nil)
end end

# Carefully sanitize params[:ids] by converting to integers and remove 0's since 'test'.to_i == 0 # Carefully sanitize params[:ids] by converting to integers and remove 0's since 'test'.to_i == 0
def santize_ids def santize_ids
(params[:ids] || []).split(',').flatten.map(&:to_i).reject{|x| x == 0}.compact (params[:ids] || []).split(',').flatten.map(&:to_i).reject{|x| x == 0}.compact
Expand All @@ -78,7 +78,7 @@ def do_merge(master, duplicate)
ignored = params["ignore"]["_self"].map{|k,v| k if v == "yes" }.compact ignored = params["ignore"]["_self"].map{|k,v| k if v == "yes" }.compact
duplicate.merge_with(master, ignored) duplicate.merge_with(master, ignored)
end end

# rudimentary API KEY authentication for the aliases action # rudimentary API KEY authentication for the aliases action
def require_application def require_application
error = "" error = ""
Expand All @@ -89,9 +89,22 @@ def require_application
else else
error = 'Please specify a valid api_key in the url.' error = 'Please specify a valid api_key in the url.'
end end

render :js => {:errors => error}.to_json render :js => {:errors => error}.to_json
false false
end end


# Return true if object is valid, except in case where object is account
# AND just account name is duplicate. That case is dealt with during the merge
def valid_object?(obj)

if obj.class.to_s == 'Account'
v = obj.valid?
obj.errors.keys.compact == [:name] || v
else
obj.valid?
end

end

end end

0 comments on commit effd774

Please sign in to comment.