Skip to content

Commit

Permalink
Merge pull request #1767 from jdalphon/jd_issue1695
Browse files Browse the repository at this point in the history
Case insensitivity for contribution keys
  • Loading branch information
Jeremy Poulin committed Sep 12, 2014
2 parents c7f94eb + 6feb959 commit 53e7f7a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def set_user
# The API call came with a contribution key and they are trying to access a project
elsif (params.key? :contribution_key) && (['jsonDataUpload', 'saveMedia'].include? params[:action])
project = Project.find_by_id(params[:id] || params[:pid])
if project && !project.contrib_keys.find_by_key(params[:contribution_key]).nil?
if project && !project.contrib_keys.find_by_key(params[:contribution_key].downcase).nil?
if params.key? :contributor_name
@cur_user = User.find_by_id(project.owner.id)
else
Expand All @@ -128,8 +128,8 @@ def set_user
params[:controller].include?('data_sets')
data_set = DataSet.find_by_id(params[:id])
if data_set &&
data_set.key == params[:contribution_key] &&
!data_set.project.contrib_keys.find_by_key(params[:contribution_key]).nil?
data_set.key == params[:contribution_key].downcase &&
!data_set.project.contrib_keys.find_by_key(params[:contribution_key].downcase).nil?
@cur_user = User.find_by_id(data_set.owner.id)
else
respond_to do |format|
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/contrib_keys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def destroy

def enter
@project = Project.find(params[:project_id])
keys = @project.contrib_keys.where(key: params[:key])
keys = @project.contrib_keys.where(key: params[:key].downcase)
contributor_name = params[:contributor_name]

if keys.count > 0 && !(contributor_name.nil?)
Expand Down
12 changes: 10 additions & 2 deletions app/models/contrib_key.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
class ContribKey < ActiveRecord::Base
belongs_to :project

def name=(val)
write_attribute(:name, val.downcase)
end

def key=(val)
write_attribute(:key, val.downcase)
end

validates :name, length: {
minimum: 1,
too_short: ' is too short (Minimum is one character)',
Expand All @@ -11,7 +19,7 @@ class ContribKey < ActiveRecord::Base
too_short: 'is too short (Minimum is one character)',
maximum: 40
}
validates_uniqueness_of :name, scope: :project
validates_uniqueness_of :key, scope: :project
validates_uniqueness_of :name, scope: :project, case_sensitive: false
validates_uniqueness_of :key, scope: :project, case_sensitive: false
validates :project_id, presence: true
end

0 comments on commit 53e7f7a

Please sign in to comment.