diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index e974f26b4..155e75976 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -104,6 +104,8 @@ class AttachmentsController < ApplicationController end else direct_download_history + # 记录用户行为 + record_user_actions end end else @@ -113,6 +115,10 @@ class AttachmentsController < ApplicationController redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html" end + def record_user_actions + UserActions.create(:action_id => id, :action_type => "AttachmentHistory", :user_id => User.current.id) + end + def download # modify by nwb # 下载添加权限设置 diff --git a/app/models/user_actions.rb b/app/models/user_actions.rb new file mode 100644 index 000000000..de2388911 --- /dev/null +++ b/app/models/user_actions.rb @@ -0,0 +1,4 @@ +class UserActions < ActiveRecord::Base + attr_accessible :action_id, :action_type, :user_id + has_many :users +end diff --git a/db/migrate/20160317090350_create_user_actions.rb b/db/migrate/20160317090350_create_user_actions.rb new file mode 100644 index 000000000..d7893fcad --- /dev/null +++ b/db/migrate/20160317090350_create_user_actions.rb @@ -0,0 +1,11 @@ +class CreateUserActions < ActiveRecord::Migration + def change + create_table :user_actions do |t| + t.integer :user_id + t.string :action_type + t.integer :action_id + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 33bf42b5b..2c55aad61 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160316055201) do +ActiveRecord::Schema.define(:version => 20160317090350) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1782,6 +1782,14 @@ ActiveRecord::Schema.define(:version => 20160316055201) do t.integer "fields_bits", :default => 0 end + create_table "user_actions", :force => true do |t| + t.integer "user_id" + t.string "action_type" + t.integer "action_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "user_activities", :force => true do |t| t.string "act_type" t.integer "act_id" diff --git a/spec/factories/user_actions.rb b/spec/factories/user_actions.rb new file mode 100644 index 000000000..38dbed67e --- /dev/null +++ b/spec/factories/user_actions.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :user_action, :class => 'UserActions' do + user_id 1 +action_type "MyString" +action_id 1 + end + +end diff --git a/spec/models/user_actions_spec.rb b/spec/models/user_actions_spec.rb new file mode 100644 index 000000000..afe799fb9 --- /dev/null +++ b/spec/models/user_actions_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe UserActions, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end