add limit feature

This commit is contained in:
BOYA,CHIU 2021-07-19 19:51:29 +08:00
parent 05a359e0fa
commit 999d08434c
6 changed files with 65 additions and 24 deletions

View File

@ -1,4 +1,5 @@
class Admin::SitePanelController < OrbitAdminController class Admin::SitePanelController < OrbitAdminController
before_action :check_server_ability, only: [:index]
def initialize def initialize
super super
@app_title = "client_management" @app_title = "client_management"
@ -134,33 +135,38 @@ class Admin::SitePanelController < OrbitAdminController
end end
end end
def create def create
site_construct = SiteConstruct.new(site_construct_params) server_abiliy = ServerAbility.first
site_construct.user_id = current_user.id.to_s if server_ability.available
site_construct.status = "creating" site_construct = SiteConstruct.new(site_construct_params)
site_construct.save site_construct.user_id = current_user.id.to_s
git_url = "http://ruling.digital/git"#"http://gitlab.tp.rulingcom.com/orbit_chiu1/orbit4-5.git" site_construct.status = "creating"
git_template_url = "http://gitlab.tp.rulingcom.com/themes/default-theme.git" site_construct.save
git_extension_url = "http://gitlab.tp.rulingcom.com/core/default-modules.git" git_url = "http://ruling.digital/git"#"http://gitlab.tp.rulingcom.com/orbit_chiu1/orbit4-5.git"
site_server = SiteServer.where(:server_name=>site_construct.server_type).first git_template_url = "http://gitlab.tp.rulingcom.com/themes/default-theme.git"
ip = site_server.ip git_extension_url = "http://gitlab.tp.rulingcom.com/core/default-modules.git"
user = site_server.account site_server = SiteServer.where(:server_name=>site_construct.server_type).first
password = site_server.password ip = site_server.ip
site_name = site_construct.site_name user = site_server.account
domain_name = site_construct.domain_name password = site_server.password
port = site_construct.get_port site_name = site_construct.site_name
db_name = site_construct.db_name domain_name = site_construct.domain_name
path = site_construct.path port = site_construct.get_port
site_construct_id = site_construct.id.to_s db_name = site_construct.db_name
if params[:site_construct][:copy_id].blank? path = site_construct.path
Thread.new do site_construct_id = site_construct.id.to_s
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}']") 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 end
redirect_to "#{admin_site_panel_sites_list_path}?id=#{site_construct_id}"
else else
Thread.new do render :text => I18n.t('client_management.over_the_limit')
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 end
redirect_to "#{admin_site_panel_sites_list_path}?id=#{site_construct_id}"
end end
def create_site def create_site
site_construct = SiteConstruct.find(params[:id]) site_construct = SiteConstruct.find(params[:id])
@ -275,4 +281,22 @@ class Admin::SitePanelController < OrbitAdminController
def site_server_params def site_server_params
params.require(:site_server).permit! rescue {} params.require(:site_server).permit! rescue {}
end 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 end

View File

@ -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<self.ability
end
end

View File

@ -1,6 +1,8 @@
<% if params[:msg] == "success" %> <% if params[:msg] == "success" %>
<div class="alert alert-success" style="width: 60%; font-size: 18px; margin: auto;"><strong>Success!</strong> Site has been queued for construction. It can take upto 5 - 10 mins. You will be notified on <strong><%= current_user.member_profile.email %></strong> once the site is ready.</div> <div class="alert alert-success" style="width: 60%; font-size: 18px; margin: auto;"><strong>Success!</strong> Site has been queued for construction. It can take upto 5 - 10 mins. You will be notified on <strong><%= current_user.member_profile.email %></strong> once the site is ready.</div>
<% end %> <% end %>
<% if @server_ability.available %>
<%= form_for @site_construct, :url => {:action=>"create"}, :html => {:class => 'form-horizontal main-forms'} do |f| %> <%= form_for @site_construct, :url => {:action=>"create"}, :html => {:class => 'form-horizontal main-forms'} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %> <%= render :partial => 'form', :locals => {:f => f} %>
<% end %>
<% end %> <% end %>

View File

@ -7,6 +7,7 @@ en:
upload_cert: Upload Cert upload_cert: Upload Cert
cert_management: Cert Management cert_management: Cert Management
client_management: client_management:
over_the_limit: Please Contact us (RulingCare) to add the limit of Site number.
redirect_to_https: Redirect to https redirect_to_https: Redirect to https
start_date: Start Date start_date: Start Date
end_date: End Date end_date: End Date

View File

@ -7,6 +7,7 @@ zh_tw:
upload_cert: 上傳憑證 upload_cert: 上傳憑證
cert_management: 憑證管理 cert_management: 憑證管理
client_management: client_management:
over_the_limit: 請您聯絡客服以增加可以新增的網站數量上限。
redirect_to_https: 跳轉到https redirect_to_https: 跳轉到https
start_date: 開始日期 start_date: 開始日期
end_date: 結束日期 end_date: 結束日期

View File

@ -9,6 +9,10 @@ module ClientManagement
taggable "SiteServer" taggable "SiteServer"
# frontend_enabled # frontend_enabled
# data_count 1..30 # data_count 1..30
require File.expand_path('../../../app/models/server_ability', __FILE__)
if ServerAbility.count==0
ServerAbility.create()
end
set_keyword_contstraints ["/cpanel/"] set_keyword_contstraints ["/cpanel/"]
side_bar do side_bar do
head_label_i18n 'client_management.client_management', icon_class: "icons-users" head_label_i18n 'client_management.client_management', icon_class: "icons-users"