forked from Gitlink/forgeplus
Merge branch 'standalone_develop' into pre_trustie_server
This commit is contained in:
commit
b966000969
|
@ -292,6 +292,7 @@ class AccountsController < ApplicationController
|
|||
UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id), :ip => request.remote_ip)
|
||||
user.update_column(:last_login_on, Time.now)
|
||||
session[:"#{default_yun_session}"] = user.id
|
||||
UserOnline.login(user.id)
|
||||
Rails.logger.info("#########_____session_default_yun_session__________###############{default_yun_session}")
|
||||
# 注册完成后有一天的试用申请(先去掉)
|
||||
# UserDayCertification.create(user_id: user.id, status: 1)
|
||||
|
|
|
@ -67,9 +67,9 @@ class Admins::DashboardsController < Admins::BaseController
|
|||
CommitLog.count
|
||||
end
|
||||
|
||||
@subject_name = ["用户数", "项目数", "组织数", "Issue数", "Issue评论数", "PR数", "Commit数"]
|
||||
@subject_icon = ["fa-user","fa-git", "fa-sitemap", "fa-warning", "fa-comments", "fa-share-alt", "fa-upload"]
|
||||
@subject_data = [@user_count, @project_count, @organization_count, @issue_count, @comment_count, @pr_count, @commit_count]
|
||||
@subject_name = ["用户数", "项目数", "组织数", "Issue数", "Issue评论数", "PR数", "Commit数", "在线用户数"]
|
||||
@subject_icon = ["fa-user","fa-git", "fa-sitemap", "fa-warning", "fa-comments", "fa-share-alt", "fa-upload", "fa-user"]
|
||||
@subject_data = [@user_count, @project_count, @organization_count, @issue_count, @comment_count, @pr_count, @commit_count, UserOnline.count]
|
||||
|
||||
if EduSetting.get("open_baidu_tongji").to_s == "true"
|
||||
tongji_service = Baidu::TongjiService.new
|
||||
|
|
|
@ -330,20 +330,6 @@ class ApplicationController < ActionController::Base
|
|||
User.current = find_current_user
|
||||
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous"))
|
||||
|
||||
# # 开放课程通过链接访问的用户
|
||||
# if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank?
|
||||
# content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}"
|
||||
#
|
||||
# if Digest::MD5.hexdigest(content) == params[:chinaoocKey]
|
||||
# user = open_class_user
|
||||
# if user
|
||||
# start_user_session(user)
|
||||
# set_autologin_cookie(user)
|
||||
# end
|
||||
# User.current = user
|
||||
# end
|
||||
# end
|
||||
|
||||
if !User.current.logged? && Rails.env.development?
|
||||
user = User.find 1
|
||||
User.current = user
|
||||
|
@ -366,6 +352,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
UserOnline.login(User.current.id)
|
||||
# User.current = User.find 81403
|
||||
end
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ class AttachmentsController < ApplicationController
|
|||
Rails.logger.info("request.host===#{request.host},request.referer===#{request.referer}")
|
||||
tip_exception(403, "你没有权限访问") if request.host.present? && !request.referer.to_s.include?(request.host.to_s.gsub("www.",""))
|
||||
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
||||
tip_exception('不可访问') if params[:download_url].to_s.include?("chinese_dictionary.txt")
|
||||
url = base_url.starts_with?("https:") ? params[:download_url].to_s.gsub("http:", "https:") : params[:download_url].to_s
|
||||
md5_file = Digest::MD5.hexdigest(params[:download_url])
|
||||
FileUtils.mkdir_p("#{Rails.root}#{EduSetting.get("attachment_folder")}gitea/") unless Dir.exists?("#{Rails.root}#{EduSetting.get("attachment_folder")}gitea/")
|
||||
|
|
|
@ -63,6 +63,7 @@ module LoginHelper
|
|||
|
||||
user.delete_autologin_token(autologin)
|
||||
user.delete_session_token(session[:tk])
|
||||
UserOnline.logout(User.current.id)
|
||||
self.logged_user = nil
|
||||
end
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ class RepositoriesController < ApplicationController
|
|||
|
||||
def sub_entries
|
||||
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
||||
|
||||
tip_exception('不可访问') if params[:filepath].to_s.include?("chinese_dictionary.txt")
|
||||
if @project.educoder?
|
||||
if params[:type] === 'file'
|
||||
@sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri)
|
||||
|
@ -307,6 +307,7 @@ class RepositoriesController < ApplicationController
|
|||
def raw
|
||||
domain = GiteaService.gitea_config[:domain]
|
||||
api_url = GiteaService.gitea_config[:base_url]
|
||||
tip_exception('不可访问') if params[:filepath].to_s.include?("chinese_dictionary.txt")
|
||||
|
||||
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{CGI.escape(params[:filepath])}?ref=#{CGI.escape(params[:ref])}"
|
||||
file_path = [domain, api_url, url].join
|
||||
|
|
|
@ -9,7 +9,7 @@ class Users::OrganizationsController < Users::BaseController
|
|||
@organizations = observed_user.organizations.with_visibility("common")
|
||||
end
|
||||
|
||||
@organizations = @organizations.ransack(login_cont: params[:search]).result if params[:search].present?
|
||||
@organizations = @organizations.ransack(login_or_nickname_cont: params[:search]).result if params[:search].present?
|
||||
|
||||
@home_top_ids = @organizations.joins(:home_top_settings).where(home_top_settings: {user_id: observed_user.id}).order("home_top_settings.created_at asc").pluck(:id)
|
||||
|
||||
|
|
|
@ -244,7 +244,9 @@ module RepositoriesHelper
|
|||
Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}")
|
||||
content = entry['content'].present? ? entry['content'] : Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
|
||||
# readme_render_decode64_content(content, owner, repo, ref)
|
||||
new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name'])
|
||||
text = new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name'])
|
||||
text = "该内容不合规,请修改。" if text.present? && !HarmoniousDictionary.clean?(text)
|
||||
text
|
||||
end
|
||||
|
||||
def decode64_content(entry, owner, repo, ref, path=nil)
|
||||
|
@ -253,9 +255,13 @@ module RepositoriesHelper
|
|||
content = entry['content'].present? ? entry['content'] : Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
|
||||
# Rails.logger.info("content===#{content}")
|
||||
return Base64.decode64(content).force_encoding("GBK").encode("UTF-8") unless Base64.decode64(content).force_encoding('UTF-8').valid_encoding?
|
||||
return Base64.decode64(content).force_encoding('UTF-8')
|
||||
text = Base64.decode64(content).force_encoding('UTF-8')
|
||||
text = "该内容不合规,请修改。" if text.present? && !HarmoniousDictionary.clean?(text)
|
||||
text
|
||||
elsif entry['is_text_file'] == true
|
||||
return render_decode64_content(entry['content'])
|
||||
text = render_decode64_content(entry['content'])
|
||||
text = "该内容不合规,请修改。" if text.present? && !HarmoniousDictionary.clean?(text)
|
||||
text
|
||||
else
|
||||
file_type = File.extname(entry['name'].to_s)[1..-1]
|
||||
if image_type?(file_type)
|
||||
|
@ -264,7 +270,9 @@ module RepositoriesHelper
|
|||
if download_type(file_type)
|
||||
return entry['content']
|
||||
end
|
||||
render_decode64_content(entry['content'])
|
||||
text = render_decode64_content(entry['content'])
|
||||
text = "该内容不合规,请修改。" if text.present? && !HarmoniousDictionary.clean?(text)
|
||||
text
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
module UserOnline
|
||||
class << self
|
||||
redis_config = YAML.load_file(Rails.root.join('config', 'redis.yml'))
|
||||
if redis_config.present?
|
||||
redis_url = redis_config[Rails.env]['url']
|
||||
$redis = Redis.new({:url=>redis_url})
|
||||
else
|
||||
$redis = Rails.cache.data
|
||||
end
|
||||
def login(user_id)
|
||||
set_bit(user_id, 1)
|
||||
end
|
||||
|
||||
def logout(user_id)
|
||||
if Rails.cache.is_a?(ActiveSupport::Cache::RedisStore)
|
||||
now = Time.now()
|
||||
keys = []
|
||||
(1..5).each do |i|
|
||||
key = (now - i.minutes).strftime("%H-%M")
|
||||
keys << "cache:online_user_#{key}"
|
||||
set_bit_and_expire(cache_key, user_id, 0) unless $redis.ttl(cache_key) == -2
|
||||
end
|
||||
end
|
||||
set_bit(user_id, 0)
|
||||
end
|
||||
|
||||
def set_bit(user_id, flag)
|
||||
if $redis.ttl(cache_key) == -2
|
||||
# 如果key不存在
|
||||
set_bit_and_expire(cache_key, user_id, flag)
|
||||
else
|
||||
if $redis.ttl(cache_key) ==-1
|
||||
# 可以存在,但过期时间没关联
|
||||
# 这种情况大概率是并发原因导致对相应key设置过期时跳过了。所以删除并重新设置过期时间
|
||||
$redis.del(cache_key)
|
||||
set_bit_and_expire(cache_key, user_id, flag)
|
||||
end
|
||||
|
||||
# 统计当前时间下,前5分钟的活跃人数
|
||||
$redis.setbit(cache_key, user_id, flag)
|
||||
end
|
||||
end
|
||||
|
||||
def set_bit_and_expire(cache_key, user_id, flag)
|
||||
$redis.setbit(cache_key, user_id, flag)
|
||||
# $redis.setbit(last_cache_key, user_id, flag)
|
||||
# 现在统计5分钟在线人数,这里设置6分钟过期,目的是统计当前时刻的前5分钟
|
||||
$redis.expire(cache_key, 6 * 60)
|
||||
end
|
||||
|
||||
def count
|
||||
if Rails.cache.is_a?(ActiveSupport::Cache::RedisStore)
|
||||
now = Time.now()
|
||||
keys = []
|
||||
(0..4).each do |i|
|
||||
key = (now - i.minutes).strftime("%H-%M")
|
||||
keys << "cache:online_user_#{key}"
|
||||
end
|
||||
# 防止每个分钟数据有重复,所以去重去除
|
||||
$redis.bitop("OR", "daiao", keys)
|
||||
$redis.bitcount("daiao")
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
def cache_key
|
||||
if Rails.cache.is_a?(ActiveSupport::Cache::RedisStore)
|
||||
"cache:online_user_#{Time.now().strftime("%H-%M")}"
|
||||
else
|
||||
raise '请配置config.cache_store = redis_store'
|
||||
end
|
||||
end
|
||||
|
||||
def last_cache_key
|
||||
if Rails.cache.is_a?(ActiveSupport::Cache::RedisStore)
|
||||
# 如设置5分钟内即300秒有请求的用户视为在线, 则最大会统计到10分钟内有活动用户
|
||||
# TODO 更精确时长
|
||||
begin_hour = Time.now.beginning_of_hour
|
||||
minutes_piece = (Time.now - begin_hour) / (60 * 5)
|
||||
time = begin_hour.since((minutes_piece.to_i - 1) * (60 * 5)).strftime("%H-%M")
|
||||
"cache:online_user_#{time}"
|
||||
else
|
||||
raise '请配置config.cache_store = redis_store'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@
|
|||
<% add_admin_breadcrumb('概览', admins_path) %>
|
||||
<% end %>
|
||||
|
||||
<% cache "/admin/dashboards/#{Time.now.strftime('%Y-%m-%d')}", :expires_in => 1.days do %>
|
||||
<%# cache_if EduSetting.get("open_baidu_tongji").to_s == "true", "/admin/dashboards/#{Time.now.strftime('%Y-%m-%d')}", :expires_in => 1.days do %>
|
||||
<div class="header bg-gradient-primary pb-8 pt-md-8">
|
||||
<div class="container-fluid">
|
||||
<div class="header-body">
|
||||
|
@ -32,7 +32,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%end %>
|
||||
<%#end %>
|
||||
|
||||
<div class="box admin-list-container project-language-list-container">
|
||||
<table class="table table-hover text-center subject-list-table">
|
||||
|
|
Loading…
Reference in New Issue