Add validation to prevent blank site_name/db_name/path in site creation/copy
This commit is contained in:
parent
53791d82c2
commit
422a9404e8
|
|
@ -281,6 +281,23 @@
|
|||
add_change_event_for_root_domain();
|
||||
})
|
||||
$("form.main-forms").submit(function(){
|
||||
// === 新增:送出前檢查必填欄位,避免 school_name/site_name/db_name 空白就送出 ===
|
||||
var required_fields = [
|
||||
{ selector: "#school_name", label: "School Name" },
|
||||
{ selector: "#site_name", label: "Site Name" },
|
||||
{ selector: "#db_name", label: "Database Name" }
|
||||
];
|
||||
var missing_labels = [];
|
||||
required_fields.forEach(function(field){
|
||||
if ($.trim($(field.selector).val()) === "") {
|
||||
missing_labels.push(field.label);
|
||||
}
|
||||
});
|
||||
if (missing_labels.length > 0) {
|
||||
alert("請填寫以下欄位後再送出:\n" + missing_labels.join("、"));
|
||||
return false;
|
||||
}
|
||||
// === 新增結束 ===
|
||||
$("#domain_name").removeAttr('disabled');
|
||||
$("#path").removeAttr("disabled");
|
||||
var type = $("#site_construct_site_type").val();
|
||||
|
|
@ -307,4 +324,4 @@
|
|||
$div.append("<span class=\"remove_btn\">X</span>").append(clone_input);
|
||||
$(this).siblings("#append_port_block").append($div)
|
||||
})
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,17 @@ namespace :create_site do
|
|||
desc "Copy Site from another site"
|
||||
task :copy_site,[:ip, :server_port,:user,:password,:site_name,:domain_name,:port,:db_name,:path,:site_construct_id,:template_site_construct_id,:only_copy_installed_module] => :environment do |task,args|
|
||||
@password = args.password
|
||||
# === 新增:關鍵欄位為空時直接中止,避免路徑塌陷後執行 chown/chmod -R 或 rsync --delete ===
|
||||
if args.site_name.blank? || args.path.blank? || args.db_name.blank?
|
||||
error_msg = "copy_site 中止:site_name(#{args.site_name.inspect}) / path(#{args.path.inspect}) / db_name(#{args.db_name.inspect}) 不可為空白"
|
||||
puts error_msg
|
||||
if args.site_construct_id.present?
|
||||
sc = SiteConstruct.find(args.site_construct_id) rescue nil
|
||||
sc.update(:status => "error", :infos => (sc.infos + [error_msg])) if sc
|
||||
end
|
||||
next
|
||||
end
|
||||
# === 新增結束 ===
|
||||
template_site = SiteConstruct.find(args.template_site_construct_id)
|
||||
if args.site_construct_id.blank?
|
||||
@site_construct = SiteConstruct.new
|
||||
|
|
@ -271,4 +282,4 @@ namespace :create_site do
|
|||
@site_construct.save!
|
||||
return @site_construct.infos
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,6 +5,17 @@ namespace :create_site do
|
|||
desc "Create Site Script"
|
||||
task :create_site,[:git_template_url,:git_extension_url,:git_url,:ip, :server_port,:user,:password,:site_name,:domain_name,:port,:db_name,:path,:site_construct_id] => :environment do |task,args|
|
||||
@password = args.password
|
||||
# === 新增:關鍵欄位為空時直接中止,避免路徑塌陷後對 "/" 執行 git clone / chown / chmod 777 -R ===
|
||||
if args.site_name.blank? || args.path.blank? || args.db_name.blank?
|
||||
error_msg = "create_site 中止:site_name(#{args.site_name.inspect}) / path(#{args.path.inspect}) / db_name(#{args.db_name.inspect}) 不可為空白"
|
||||
puts error_msg
|
||||
if args.site_construct_id.present?
|
||||
sc = SiteConstruct.find(args.site_construct_id) rescue nil
|
||||
sc.update(:status => "error", :infos => (sc.infos + [error_msg])) if sc
|
||||
end
|
||||
next
|
||||
end
|
||||
# === 新增結束 ===
|
||||
if args.site_construct_id.blank?
|
||||
@site_construct = SiteConstruct.new
|
||||
@site_construct.server_type = (SiteServer.where(:ip=>args.ip).first.server_name rescue args.ip)
|
||||
|
|
@ -220,4 +231,4 @@ namespace :create_site do
|
|||
@site_construct.save!
|
||||
return @site_construct.infos
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue