diff --git a/app/controllers/admin/site_panel_controller.rb b/app/controllers/admin/site_panel_controller.rb index aef9d12..2e60946 100644 --- a/app/controllers/admin/site_panel_controller.rb +++ b/app/controllers/admin/site_panel_controller.rb @@ -1,4 +1,5 @@ class Admin::SitePanelController < OrbitAdminController + before_action :check_server_ability, only: [:index] def initialize super @app_title = "client_management" @@ -134,33 +135,38 @@ class Admin::SitePanelController < OrbitAdminController end end def create - site_construct = SiteConstruct.new(site_construct_params) - site_construct.user_id = current_user.id.to_s - site_construct.status = "creating" - site_construct.save - git_url = "http://ruling.digital/git"#"http://gitlab.tp.rulingcom.com/orbit_chiu1/orbit4-5.git" - git_template_url = "http://gitlab.tp.rulingcom.com/themes/default-theme.git" - git_extension_url = "http://gitlab.tp.rulingcom.com/core/default-modules.git" - site_server = SiteServer.where(:server_name=>site_construct.server_type).first - ip = site_server.ip - user = site_server.account - password = site_server.password - site_name = site_construct.site_name - domain_name = site_construct.domain_name - port = site_construct.get_port - db_name = site_construct.db_name - path = site_construct.path - site_construct_id = site_construct.id.to_s - if params[:site_construct][:copy_id].blank? - Thread.new do - system("bundle exec rake create_site:create_site['#{git_template_url}','#{git_extension_url}','#{git_url}','#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}']") + server_abiliy = ServerAbility.first + if server_ability.available + site_construct = SiteConstruct.new(site_construct_params) + site_construct.user_id = current_user.id.to_s + site_construct.status = "creating" + site_construct.save + git_url = "http://ruling.digital/git"#"http://gitlab.tp.rulingcom.com/orbit_chiu1/orbit4-5.git" + git_template_url = "http://gitlab.tp.rulingcom.com/themes/default-theme.git" + git_extension_url = "http://gitlab.tp.rulingcom.com/core/default-modules.git" + site_server = SiteServer.where(:server_name=>site_construct.server_type).first + ip = site_server.ip + user = site_server.account + password = site_server.password + site_name = site_construct.site_name + domain_name = site_construct.domain_name + port = site_construct.get_port + db_name = site_construct.db_name + path = site_construct.path + site_construct_id = site_construct.id.to_s + if params[:site_construct][:copy_id].blank? + Thread.new do + system("bundle exec rake create_site:create_site['#{git_template_url}','#{git_extension_url}','#{git_url}','#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}']") + end + else + Thread.new do + system("bundle exec rake create_site:copy_site['#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}','#{params[:site_construct][:copy_id]}',#{site_construct.only_copy_installed_module}]") + end end + redirect_to "#{admin_site_panel_sites_list_path}?id=#{site_construct_id}" else - Thread.new do - system("bundle exec rake create_site:copy_site['#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}','#{params[:site_construct][:copy_id]}',#{site_construct.only_copy_installed_module}]") - end + render :text => I18n.t('client_management.over_the_limit') end - redirect_to "#{admin_site_panel_sites_list_path}?id=#{site_construct_id}" end def create_site site_construct = SiteConstruct.find(params[:id]) @@ -275,4 +281,22 @@ class Admin::SitePanelController < OrbitAdminController def site_server_params params.require(:site_server).permit! rescue {} end + def check_server_ability + store_token = current_site.store_token + network = ONetwork.new(OrbitStore::URL,"post") + site_num = SiteConstruct.where(hidden: false,:status.ne => 'closed').count + response = network.request("/xhr/check_server_ability", + {"store_token" => store_token, + "site_num" => site_num, + "site_name" => current_site.title, + "site_url" => current_site.root_url}) + data = JSON.parse(response.body) rescue {} + puts data + @server_ability = ServerAbility.first + if data.keys.length>0 && !data['ability'].blank? + @server_ability.update_attributes(ability: data['ability'], site_num: site_num) + else + @server_ability.update_attributes(site_num: site_num) + end + end end \ No newline at end of file diff --git a/app/models/server_ability.rb b/app/models/server_ability.rb new file mode 100644 index 0000000..a5a7411 --- /dev/null +++ b/app/models/server_ability.rb @@ -0,0 +1,9 @@ +class ServerAbility + include Mongoid::Document + include Mongoid::Timestamps + field :ability, type: Integer, default: 0 + field :site_num, type: Integer, default: 0 + def available + self.ability==0 || self.site_num
Success! Site has been queued for construction. It can take upto 5 - 10 mins. You will be notified on <%= current_user.member_profile.email %> once the site is ready.
<% end %> +<% if @server_ability.available %> <%= form_for @site_construct, :url => {:action=>"create"}, :html => {:class => 'form-horizontal main-forms'} do |f| %> <%= render :partial => 'form', :locals => {:f => f} %> +<% end %> <% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 4ab5413..3acf44e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -7,6 +7,7 @@ en: upload_cert: Upload Cert cert_management: Cert Management client_management: + over_the_limit: Please Contact us (RulingCare) to add the limit of Site number. redirect_to_https: Redirect to https start_date: Start Date end_date: End Date diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index a741027..be82e1f 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -7,6 +7,7 @@ zh_tw: upload_cert: 上傳憑證 cert_management: 憑證管理 client_management: + over_the_limit: 請您聯絡客服以增加可以新增的網站數量上限。 redirect_to_https: 跳轉到https start_date: 開始日期 end_date: 結束日期 diff --git a/lib/client_management/engine.rb b/lib/client_management/engine.rb index 207a64c..12f453b 100644 --- a/lib/client_management/engine.rb +++ b/lib/client_management/engine.rb @@ -9,6 +9,10 @@ module ClientManagement taggable "SiteServer" # frontend_enabled # data_count 1..30 + require File.expand_path('../../../app/models/server_ability', __FILE__) + if ServerAbility.count==0 + ServerAbility.create() + end set_keyword_contstraints ["/cpanel/"] side_bar do head_label_i18n 'client_management.client_management', icon_class: "icons-users"