From 37aa950028b59c2e3456f4d209349a11d957d30e Mon Sep 17 00:00:00 2001 From: "Matt K. Fu" Date: Thu, 23 May 2013 11:55:57 +0800 Subject: [PATCH] user action --- app/controllers/admin/user_actions_controller.rb | 6 ++++++ app/controllers/application_controller.rb | 1 + app/jobs/user_action_recoder.rb | 8 ++++++++ app/models/user/user.rb | 2 ++ app/models/user/user_action.rb | 10 ++++++++++ app/views/admin/user_actions/index.html.erb | 16 ++++++++++++++++ config/routes.rb | 3 +++ 7 files changed, 46 insertions(+) create mode 100644 app/controllers/admin/user_actions_controller.rb create mode 100644 app/jobs/user_action_recoder.rb create mode 100644 app/models/user/user_action.rb create mode 100644 app/views/admin/user_actions/index.html.erb diff --git a/app/controllers/admin/user_actions_controller.rb b/app/controllers/admin/user_actions_controller.rb new file mode 100644 index 00000000..dff3a432 --- /dev/null +++ b/app/controllers/admin/user_actions_controller.rb @@ -0,0 +1,6 @@ +class Admin::UserActionsController < OrbitBackendController + + def index + @user_actions = UserAction.all + end +end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c1de055e..8f0c6870 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -29,6 +29,7 @@ class ApplicationController < ActionController::Base def set_current_user User.current = current_or_guest_user + UserActionRecoder.perform(current_or_guest_user,params) end def front_end_available(module_app_title='') diff --git a/app/jobs/user_action_recoder.rb b/app/jobs/user_action_recoder.rb new file mode 100644 index 00000000..d5cd9281 --- /dev/null +++ b/app/jobs/user_action_recoder.rb @@ -0,0 +1,8 @@ +class UserActionRecoder + @queue = :low + def self.perform(user,params) + UserAction.create!(:user=>user,:params=>params,:page=>"#{params['controller']}##{params['action']}") + true + end + +end \ No newline at end of file diff --git a/app/models/user/user.rb b/app/models/user/user.rb index 4b3a9e6e..4a01a71c 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -31,6 +31,8 @@ class User # has_many :papers, :autosave => true, :dependent => :destroy has_and_belongs_to_many :sub_role_tags + has_many :user_actions, :dependent => :destroy + # has_and_belongs_to_many :statuses has_and_belongs_to_many :roles has_and_belongs_to_many :sub_roles diff --git a/app/models/user/user_action.rb b/app/models/user/user_action.rb new file mode 100644 index 00000000..b49af689 --- /dev/null +++ b/app/models/user/user_action.rb @@ -0,0 +1,10 @@ +class UserAction + include Mongoid::Document + include Mongoid::Timestamps + + belongs_to :user + field :params,:type => Hash + + field :page + +end \ No newline at end of file diff --git a/app/views/admin/user_actions/index.html.erb b/app/views/admin/user_actions/index.html.erb new file mode 100644 index 00000000..74e4ea5f --- /dev/null +++ b/app/views/admin/user_actions/index.html.erb @@ -0,0 +1,16 @@ + + + + + + + + <% @user_actions.each do |user_action| %> + + + + + + <% end %> +
時間使用帳號頁面
<%= user_action.created_at %><%= user_action.user.name %><%= user_action.page %>
+ diff --git a/config/routes.rb b/config/routes.rb index 7182ece6..2f084967 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ Orbit::Application.routes.draw do # get "robots.txt" => 'robots#index' + + devise_for :users do match "/users_passwd" => "desktop/registrations#update", :as => :users_passwd, :via => :put end @@ -18,6 +20,7 @@ Orbit::Application.routes.draw do # routes for admin namespace :admin do + match 'user_actions' => 'user_actions#index' match 'system_preference' => "sites#show_system_preference",:as=>"system_preference" mount Resque::Server.new, :at => "/resque" resources :assets do