diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 859f19f19..d7cf29387 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -800,11 +800,13 @@ class UsersController < ApplicationController @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('created_at desc').limit(10).offset(@page * 10) when "project_message" @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('created_at desc').limit(10).offset(@page * 10) + when "current_user" + @user_activities = UserActivity.where("user_id = #{User.current.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))").order('created_at desc').limit(10).offset(@page * 10) else - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids}) and act_type in #{course_types}").order('created_at desc').limit(10).offset(@page * 10) + @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('created_at desc').limit(10).offset(@page * 10) end else - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids}) and act_type in #{course_types}").order('created_at desc').limit(10).offset(@page * 10) + @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('created_at desc').limit(10).offset(@page * 10) end # @user_activities = paginateHelper @user_activities,500 @type = params[:type] diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb index 284687870..103796a72 100644 --- a/app/models/course_activity.rb +++ b/app/models/course_activity.rb @@ -19,6 +19,7 @@ class CourseActivity < ActiveRecord::Base user_activity.act_type = self.course_act_type user_activity.container_type = "Course" user_activity.container_id = self.course_id + user_activity.user_id = self.user_id user_activity.save end end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 92f3f4a1a..13f2518e1 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -29,6 +29,7 @@
  • diff --git a/db/migrate/20150907064144_add_user_id_to_user_activities.rb b/db/migrate/20150907064144_add_user_id_to_user_activities.rb new file mode 100644 index 000000000..a038f4dab --- /dev/null +++ b/db/migrate/20150907064144_add_user_id_to_user_activities.rb @@ -0,0 +1,5 @@ +class AddUserIdToUserActivities < ActiveRecord::Migration + def change + add_column :user_activities, :user_id, :int + end +end diff --git a/db/migrate/20150907064547_update_user_activities.rb b/db/migrate/20150907064547_update_user_activities.rb new file mode 100644 index 000000000..b4c56c009 --- /dev/null +++ b/db/migrate/20150907064547_update_user_activities.rb @@ -0,0 +1,40 @@ +class UpdateUserActivities < ActiveRecord::Migration + def up + count = UserActivity.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + UserActivity.page(i).per(30).each do |activity| + if activity.container_type.to_s == 'Project' + forge_activity = ForgeActivity.where("forge_act_type = '#{activity.act_type.to_s}' and forge_act_id = #{activity.act_id}").first + if forge_activity + activity.user_id = forge_activity.user_id + else + activity.user_id = 0 + end + + elsif activity.container_type.to_s == 'Course' + course_activity = CourseActivity.where("course_act_type = '#{activity.act_type.to_s}' and course_act_id = #{activity.act_id}").first + if course_activity + activity.user_id = course_activity.user_id + else + activity.user_id = 0 + end + end + activity.save + end + end + end + end + + def down + count = UserActivity.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + UserActivity.page(i).per(30).each do |activity| + activity.user_id = nil + activity.save + end + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3b5b88ee7..db0b57ae8 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 => 20150906091045) do +ActiveRecord::Schema.define(:version => 20150907064547) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false