Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks for update_name in shares #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions app/controllers/share_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

class ShareController < ApplicationController
before_action :admin_required
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found

VALID_NAME = Regexp.new "\A\\w[\\w ]+\z"
# Disk Pool minimum free: default og 10GB, but for root,
Expand All @@ -26,11 +27,20 @@ class ShareController < ApplicationController
DP_MIN_FREE_ROOT = 20

def update_name
# FIXME - lots of checks missing!
s = Share.find(params[:id])
s.name = params[:value]
s.save
s.reload
name=params[:value]
unless valid_name?(name)
render :plain => s.name
return
end

share=Share.where(:name => name).first
if share.nil?
#store if name is unique
s.name = name
s.save
s.reload
end
render :text => s.name
end

Expand Down Expand Up @@ -325,7 +335,9 @@ def is_valid_domain_name(domain)
end

def valid_name?(nm)
return false unless (nm =~ VALID_NAME)
unless nm =~ VALID_NAME and nm.length <= 32
return false
end
true
end

Expand All @@ -337,4 +349,9 @@ def location2file(loc)
Share.full_path(rest)
end

def record_not_found
flash[:notice] = "Share doesn't exist"
redirect_to root_path
end

end