add limit client manager feature

This commit is contained in:
BOYA,CHIU 2021-07-19 19:52:42 +08:00
parent df79763000
commit 23a7aadb6d
10 changed files with 231 additions and 8 deletions

View File

@ -1,11 +1,11 @@
class Admin::OfficialModuleController < OrbitAdminController class Admin::OfficialModuleController < OrbitAdminController
layout "structure"
def set_master_key def set_master_key
@master_password = MasterPassword.first rescue nil @master_password = MasterPassword.first rescue nil
if @master_password.nil? if @master_password.nil?
@master_password = MasterPassword.new @master_password = MasterPassword.new
end end
render :layout => "structure"
end end
def update_master_password def update_master_password
@ -26,7 +26,43 @@ class Admin::OfficialModuleController < OrbitAdminController
redirect_to admin_site_set_master_key_path(current_site) redirect_to admin_site_set_master_key_path(current_site)
end end
def index
@managers = ServerAbilityManager.all.order_by(sort)
.with_categories(filters("category"))
.with_tags(filters("tag")).desc(:created_at)
@table_fields = ["site_name_layout", "max_site_ability", "site_num","site_ip"]
@tags = @module_app.tags
@categories = @module_app.categories.enabled
@filter_fields = filter_fields_without_status(@categories, @tags)
@managers = search_data(@managers,[:title,:site_domain]).page(params[:page]).per(10)
if request.xhr?
render :partial => "index"
end
end
def set_server_ability
store_token = params[:official_module_id]
@manager = ServerAbilityManager.where(store_token: store_token).first || ServerAbilityManager.new(id: nil)
end
def update_server_ability
manager_params = params.require(:server_ability_manager).permit!
store_token = manager_params[:store_token]
manager = ServerAbilityManager.where(store_token: store_token).first
if manager.nil?
r_site = RegisteredSite.where(uid: store_token).first
manager = ServerAbilityManager.create(store_token: store_token, site_name: r_site.title,site_url: r_site.site_domain,site_ip: r_site.real_ip || r_site.ip[0])
end
manager.update_attributes(manager_params)
redirect_to :action => "index"
end
def delete
store_token = params[:official_module_id]
ServerAbilityManager.where(store_token: store_token).first.destroy
redirect_to :action => "index"
end
private private
def password_params def password_params

View File

@ -100,4 +100,26 @@ class ClientSitesController < ApplicationController
end end
end end
def check_server_ability
site_num = params[:site_num]
store_token = params[:store_token]
site_name = params[:site_name]
site_url = params[:site_url]
manager = ServerAbilityManager.where(store_token: store_token).first
ability = manager.max_site_ability rescue 0
site_ip = request.remote_ip
update_params = {
site_ip: site_ip,
site_num: site_num,
site_url: site_url
}
if manager.nil?
update_params = update_params.merge({store_token: store_token,
site_name: site_name})
ServerAbilityManager.create(update_params)
else
manager.update_attributes(update_params)
end
render :json => {ability: ability}
end
end end

View File

@ -0,0 +1,35 @@
class ServerAbilityManager
include Mongoid::Document
include Mongoid::Timestamps
include OrbitCategory::Categorizable
include OrbitTag::Taggable
field :store_token
field :site_name
field :site_url
field :site_ip
field :site_num, type: Integer, default: 0
field :max_site_ability, type: Integer, default: 0
def site_name_layout(url=nil,site_name=nil)
url = self.site_url if url.nil?
site_name = self.site_name if site_name.nil?
"<a href=\"#{url}\">#{site_name}</a>
<div class=\"quick-edit\">
<ul class=\"nav nav-pills\">
<li>
<a href=\"/#{I18n.locale}/admin/official_module/#{self.store_token}/set_server_ability\">
#{I18n.t('edit')}
</a>
</li>
<li>
<a href=\"/#{I18n.locale}/admin/official_module/#{self.store_token}/delete\">
#{I18n.t('delete_')}
</a>
</li>
</ul>
<div>"
end
def site_name
tmp = super
tmp = tmp.blank? ? self.site_url : tmp
end
end

View File

@ -0,0 +1,26 @@
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead("official_module.#{f}") %>
<% end %>
</tr>
</thead>
<tbody>
<% @managers.each do |manager| %>
<tr>
<% @table_fields.each do |f| %>
<td>
<%= manager.send(f).to_s.html_safe %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<%= content_tag :div, paginate(@managers), class: "pagination pagination-centered" %>
<a class="btn btn-primary pull-right" href="official_module/set_server_ability" title="Create new">
<%= t('new_') %>
</a>
</div>

View File

@ -0,0 +1,4 @@
<%= render_filter @filter_fields, "index_table" %>
<div id="index_table">
<%= render :partial => "index" %>
</div>

View File

@ -0,0 +1,40 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/wrap-nav"%>
<%= stylesheet_link_tag "lib/main-forms"%>
<%= stylesheet_link_tag "lib/fileupload"%>
<%= stylesheet_link_tag "lib/togglebox"%>
<% end %>
<%= form_for @manager, :url => {:action => "update_server_ability"}, :method => "patch", :html => {:class => "form-horizontal main-forms"} do |f| %>
<fieldset>
<!-- Input Area -->
<div class="input-area">
<div class="control-group">
<label class="control-label muted"><%= t('official_module.site_name') %></label>
<div class="controls">
<% if @manager.new_record? %>
<%= f.select :store_token, RegisteredSite.all.collect{|v| [v.show_name,v.site_token]} %>
<% else %>
<%= f.hidden_field :store_token %>
<label class="control-label" style="text-align: left;">
<%= @manager.site_name %>
</label>
<% end %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('official_module.max_site_ability') %></label>
<div class="controls">
<%= f.number_field :max_site_ability, :class=>"input-large", :autocomplete=>"off" %>
</div>
</div>
</div>
<!-- Form Actions -->
<div class="form-actions" style="background: none;">
<% if @manager.new_record? %>
<%= f.submit t('new_'), :class => "btn btn-primary" %>
<% else %>
<%= f.submit t('edit'), :class => "btn btn-primary" %>
<% end %>
</div>
</fieldset>
<% end %>

View File

@ -1,2 +1,11 @@
en: en:
master_key: Master Key master_key: Master Key
official_module:
all: All
official_module: Official Module
site_name_layout: Site Name
max_site_ability: Max Site Ability
site_num: Site Number
site_ip: Site IP
module_name:
official_module: Official Module

View File

@ -1,2 +1,11 @@
zh_tw: zh_tw:
master_key: 網站密碼 master_key: 網站密碼
official_module:
all: 全部
official_module: 官網模組
site_name_layout: 網站名稱
max_site_ability: 最大容許網站數量
site_num: 網站數量
site_ip: 網站IP
module_name:
official_module: 官網模組

View File

@ -6,13 +6,23 @@ Rails.application.routes.draw do
get "/desktop/widget_download_url" => "client_sites#widget_download_url" get "/desktop/widget_download_url" => "client_sites#widget_download_url"
get "/store/form_token" => 'client_sites#get_csrf_token' get "/store/form_token" => 'client_sites#get_csrf_token'
post "/xhr/check_server_ability" => 'client_sites#check_server_ability'
locales = Site.first.in_use_locales rescue I18n.available_locales locales = Site.first.in_use_locales rescue I18n.available_locales
scope "(:locale)", locale: Regexp.new(locales.join("|")) do scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do namespace :admin do
scope "sites/:id", :controller => 'official_module' do scope "sites/:id", :controller => 'official_module',as: :site do
get "set_master_key" => 'official_module#set_master_key', as: :site_set_master_key get "set_master_key"
patch "update_master_password" => 'official_module#update_master_password' patch "update_master_password"
end
resources :official_module, :controller => 'official_module',:only=>[:index] do
get "set_server_ability"
get "delete"
patch "update_server_ability"
end
scope :official_module, :controller => 'official_module',:only=>[],as: :official_module_new do
get "set_server_ability"
get "delete"
patch "update_server_ability"
end end
end end
end end

View File

@ -3,14 +3,46 @@ module OfficialModule
initializer "official_module" do initializer "official_module" do
OrbitApp.registration "OfficialModule", :type => "ModuleApp" do OrbitApp.registration "OfficialModule", :type => "ModuleApp" do
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
taggable "ServerAbilityManager"
categorizable
authorizable
module_label "official_module.official_module"
set_keyword_contstraints ['/store/check_module_permissions', set_keyword_contstraints ['/store/check_module_permissions',
'/store/register_old_sites_modules', '/store/register_old_sites_modules',
'/store/check_for_rulingcom', '/store/check_for_rulingcom',
'/store/desktop/widgets', '/store/desktop/widgets',
'/desktop/widget_download_url', '/desktop/widget_download_url',
'/store/form_token'] '/store/form_token']
side_bar do
head_label_i18n 'official_module.official_module', icon_class: "fa fa-puzzle-piece"
available_for "managers"
active_for_controllers (['admin/official_module'])
head_link_path "admin_official_module_index_path"
context_link 'official_module.all',
:link_path=>"admin_official_module_index_path" ,
:priority=>1,
:active_for_action=>{'admin/official_module'=>"index"},
:available_for => 'users'
context_link 'categories',
:link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'official_module').id}",
:priority=>2,
:active_for_action=>{'admin/official_module'=>'categories'},
:active_for_category => 'OfficialModule',
:available_for => 'managers'
context_link 'tags',
:link_path=>"admin_module_app_tags_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'official_module').id}",
:priority=>3,
:active_for_action=>{'admin/official_module'=>'tags'},
:active_for_tag => 'OfficialModule',
:available_for => 'managers'
end end
end end
end end
end
end end