diff --git a/app/controllers/admins/user_actions_controller.rb b/app/controllers/admins/user_actions_controller.rb index cca6f6a14..d7d7b669f 100644 --- a/app/controllers/admins/user_actions_controller.rb +++ b/app/controllers/admins/user_actions_controller.rb @@ -2,8 +2,21 @@ class Admins::UserActionsController < Admins::BaseController before_action :require_admin def index - @user_actions = UserAction.order(created_at: :desc) + @user_actions = UserAction.where.not(action_type: ["CompetitionInfoCreate", "CompetitionInfoUpdate", "CompetitionInfoUp", "CompetitionInfoDown", 'MemoPassed']).order(created_at: :desc) + if params[:action_type].present? + @user_actions = @user_actions.where(action_type: params[:action_type]) + end + keyword = params[:keyword].to_s.strip.presence + if keyword + sql = 'login LIKE :keyword OR phone LIKE :keyword OR email LIKE :keyword' + @user_actions = @user_actions.where(sql, keyword: "%#{keyword}%") + end + @user_actions = paginate @user_actions + end + + def index_1 + @user_actions = UserAction.where(action_type: ["CompetitionInfoCreate", "CompetitionInfoUpdate", "CompetitionInfoUp", "CompetitionInfoDown", 'MemoPassed']).order(created_at: :desc) if params[:action_type].present? if params[:action_type].include?("CompetitionInfo") @user_actions = @user_actions.where(action_type: ["CompetitionInfoCreate", "CompetitionInfoUpdate", "CompetitionInfoUp", "CompetitionInfoDown"]) diff --git a/app/models/user_action.rb b/app/models/user_action.rb index 61262cce8..47ced4ed7 100644 --- a/app/models/user_action.rb +++ b/app/models/user_action.rb @@ -43,6 +43,7 @@ class UserAction < ApplicationRecord when "CompetitionInfoUp" then "上架竞赛" when "CompetitionInfoDown" then "下架竞赛" when "Attachment" then "上传附件" + when "MemoPassed" then "论坛审核" else self.action_type end end @@ -70,6 +71,7 @@ class UserAction < ApplicationRecord else return "上传附件地址:#{attachment.title}" end + when "MemoPassed" then "#{memo&.subject}" else "--" end end @@ -119,6 +121,14 @@ class UserAction < ApplicationRecord competition_info end + def memo + memo = if action_type == "MemoPassed" && data_bank.present? + Memo.find_by(id: self.action_id) + else + nil + end + end + def build_mode(model_name) model = model_name.constantize.new diff --git a/app/views/admins/user_actions/index.html.erb b/app/views/admins/user_actions/index.html.erb index 9a66e8ce1..e1271e023 100644 --- a/app/views/admins/user_actions/index.html.erb +++ b/app/views/admins/user_actions/index.html.erb @@ -5,7 +5,7 @@
<%= form_tag(admins_user_actions_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %> 操作类型: - <% action_type_options = [['上传附件', 'Attachment'], ['登录', 'Login'], ['退出登录', 'Logout'],['删除用户','DestroyUser'], ['删除项目', 'DestroyProject'], ['删除组织', 'DestroyOrganization'], ['竞赛', 'CompetitionInfo']] %> + <% action_type_options = [['上传附件', 'Attachment'], ['登录', 'Login'], ['退出登录', 'Logout'],['删除用户','DestroyUser'], ['删除项目', 'DestroyProject'], ['删除组织', 'DestroyOrganization']] %> <%= select_tag(:action_type, options_for_select(action_type_options, params[:action_type]), class: 'form-control') %> <%#= text_field_tag(:action_type, params[:action_type], class: 'form-control col-sm-2 ml-3',style: 'display: none;', placeholder: '自定义操作类型检索') %> <%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '操作人用户名/邮箱/手机号检索') %> diff --git a/app/views/admins/user_actions/index_1.html.erb b/app/views/admins/user_actions/index_1.html.erb new file mode 100644 index 000000000..8c4f8fa9d --- /dev/null +++ b/app/views/admins/user_actions/index_1.html.erb @@ -0,0 +1,33 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('操作记录', admins_user_actions_path) %> +<% end %> + +
+ <%= form_tag(admins_user_actions_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %> + 操作类型: + <% action_type_options = [['竞赛', 'CompetitionInfo'], ['论坛审核', 'MemoPassed']] %> + <%= select_tag(:action_type, options_for_select(action_type_options, params[:action_type]), class: 'form-control') %> + <%#= text_field_tag(:action_type, params[:action_type], class: 'form-control col-sm-2 ml-3',style: 'display: none;', placeholder: '自定义操作类型检索') %> + <%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '操作人用户名/邮箱/手机号检索') %> + <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> + <% end %> + +
+ +
+ <%= render partial: 'admins/user_actions/user_action_list', locals: { user_actions: @user_actions } %> +
+ + diff --git a/config/routes.rb b/config/routes.rb index e558c59b2..29aac62f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1120,7 +1120,9 @@ Rails.application.routes.draw do post :drag, on: :collection post :replace_image_url, on: :member end - resources :user_actions , only:[:index] + resources :user_actions , only:[:index] do + get :index_1, on: :collection + end resources :faqs resources :nps do post :switch_change, on: :collection