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
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

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" %>
<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 %>
<% 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 %>

View File

@ -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

View File

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

View File

@ -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"