From d6940f0890819086b3d08c089bdd30e68453a826 Mon Sep 17 00:00:00 2001 From: Vishesh Ruparelia Date: Thu, 21 Mar 2019 11:51:03 +0530 Subject: [PATCH] Add checks for update_name in shares --- app/controllers/share_controller.rb | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/app/controllers/share_controller.rb b/app/controllers/share_controller.rb index baa4c6f7..53192ac3 100644 --- a/app/controllers/share_controller.rb +++ b/app/controllers/share_controller.rb @@ -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, @@ -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 @@ -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 @@ -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